Adding the Extension of PRG in the Tab Settings list
-
@lycan-thrope said in Adding the Extension of PRG in the Tab Settings list:
I was bit again by that indentation bug, even in PythonScript, obviously it does it, too.
I’m a bit disturbed by this.
There is no indentation bug, just indentation rules to follow.
And PythonScript is just a plugin version of an embedded Python interpreter, so any files created for use with it must also follow Python’s indentation rules.
I wish I could help further, but I really don’t know how to. -
There is no indentation problem with what @Alan-Kilborn originall posted. I just created a fresh Notepad++ with PythonScript, copy/pasted exactly what he had into
TabSettingsOverrideByExtension.py
, and ran that. When I opened aexample.prg
file, it properly used 3 spaces when I typed a tab in theexample.prg
file.My PythonScript console looks like:
Python 2.7.18 (v2.7.18:8d21aa21f2, Apr 20 2020, 13:25:05) [MSC v.1500 64 bit (AMD64)] Initialisation took 15ms Ready. setting up for files with extension prg
if I switch to a different tab, then back to
example.prg
, I see anothersetting up for files with extension prg
in the console.Similarly, if I exit out and come back in, then open up
example.prg
without running the script first, it properly uses the default TAB character with a width of 4 characters.If I create a user
startup.py
with the exact contents:# -*- coding: utf-8 -*- from Npp import * import os import TabSettingsOverrideByExtension tsobe = TabSettingsOverrideByExtension.TSOBE()
when I restart Notepad++, I get no errors in the PythonScript console, and if I open
example.prg
, it does 3-space when I hit the TAB key.So Alan’s example script works exactly as described. You do not need to edit anything after you paste in the exact contents from the black box and save. It just works right, with correct indentation.
-
@peterjones said in Adding the Extension of PRG in the Tab Settings list:
if I switch to a different tab, then back to example.prg, I see another setting up for files with extension prg in the console.
Oops, I guess I didn’t mean to leave the print statement in there… But perhaps it was helpful here.
So the reason it “sets it up” everytime you switch tabs is that upon the tab change, Notepad++ itself will reset the tab settings…so the script code has to override that and set it up the way it wants it. (Just some background info).
BTW, the script isn’t “perfect”. If you rename a file that has a non .prg extension so that it has that extension, it will probably take a tab switch away and a return to get it to take effect. Also, once tab characters are “in” a file, this script won’t remove them, even if the configuration is set to use-spaces. These limitations could be worked around, with more code.
-
Yes, I get it, it’s not an indentation bug, I must have done something wrong. :-)
So I’ll have to mess with it to see what I did wrong. I will try creating a user startup.py and put it where ever it goes (reading the instructions on file locations I have here somewhere), and remove it from the machine startup.py. This is kind of the thing, I know I’ve screwed it up somehow and I don’t understand the indentation rules for Python…I’m am only learning and dabbling at the moment, and indentation was never a critical part of any programming I’ve ever done, so it’s new to me. I’ll get it. Thanks for the pointers and the tests.
-
-