Loading preferences by file extension.
-
I need some help. I have 3 different types of files that I routinely edit with NPP. Each of those extensions have different column spacing. I have 3 preferences set (one for each file) and currently manually load them prior to editing each file. I would like to know if there is a way to preload the appropriate settings based on the file extension to make this job a lot easier.
Best,
J -
I don’t 100% follow your description. But I don’t think it’s natively possible.
clarifications
First question: what do you mean by “column spacing”? In Notepad++, each column is one character wide. Do you mean the tab size (Settings > Preferences > Language: Tab Settings)?
Second question: when you manually load the preference, how are you doing that?
Third question: at one point, you say “types of files” and another “extensions”. So I assume you have three different extensions, like
.one
,.two
,.three
, and each one of those types has a different tab setting?scripting language solution
If you have multiple extensions, and you are willing to install the PythonScript plugin, there might be a way to change the tab size based on the extension of the active window. If you want to go down that route, we can help you (@Ekopalypse has posted many PythonScript examples that change some setting based on file extension, but I cannot find any right now. If you choose to go down this route, he can probably find them easier than I can.)
batch workaround
From an outside-of-notepad++ solution, you could create a
.bat
file for each extension (one.bat two.bat three.bat
), and have that batch file either copy over the right configuration set, or use the-settingsDir
(new to Notepad++ v7.9.2) command line argument in order to load the right config file. Maybe:one.bat
"c:\program files\notepad++\notepad++.exe" -settingsDir="c:\temp\notepad++\settings.one" $*
two.bat
"c:\program files\notepad++\notepad++.exe" -settingsDir="c:\temp\notepad++\settings.two" $*
three.bat
"c:\program files\notepad++\notepad++.exe" -settingsDir="c:\temp\notepad++\settings.three" $*
Then associate
.one
to open withone.bat
and so on.Similarly, even with earlier versions of Notepad++, each batch file could copy over the settings file to the single central location, something like
copy "c:\temp\notepad++\settings.one.filename.xml" "%AppData%\Notepad++\filename.xml"
for appropriate config file names, and then run notepad++ on the selected file. -
Hello, thank you for the reply. The vertical edge settings are what I am trying to adjust by file. You got everything else correct. So I have:
.def with spacing “A”,
.ini with spacing “B”… etc
Our team has hired some technician level associates in order to help us, so I have been trying to create visual boundaries in each “column” Realistically that is the only preference parameter that I need to come in with the file.
I am manually loading them by replacing the appdata with a saved set from another instance.
Best,
Jim -
@James-Swallow said in Loading preferences by file extension.:
The vertical edge settings are what I am trying to adjust by file
Ah, okay, yes. Those settings should work with either the PythonScript or the batch workaround.
if you want to go the PythonScript route, let us know. Otherwise, hopefully you have enough for the batch. (or you can wait to see if someone else has other suggestions).
-
see here for an example based on the language used.
-
OK, So I got that script to run. A couple of questions:
On Startup, is there a way to automate this so it will apply to open instances without changing the language and then changing back?
Second question, What is the best way to run this with shortcuts if that is not an option? -
@James-Swallow said in Loading preferences by file extension.:
On Startup, is there a way to automate this so it will apply to open instances without changing the language and then changing back?
Interesting. I would have thought that BUFFERACTIVATED notification would trigger at Notepad++'s initial startup, too. But if the callback isn’t triggering, it’s probably not notified. There is a notification for “notepad++ has finished loading everything”: NPPN_READY, which in PythonScript is NOTIFICATION.READY. So if you add that to the list of notifications, it should work for you.
Second question, What is the best way to run this with shortcuts if that is not an option?
Hmmm. I think if you added a call to
on_set_edge_config()
(or whatever you called your version of the callback function) at the end of the script, then if you run the script manually, it will trigger the callback, even if the script was already run from startup.py. (I’m not 100% sure). If so, then use the PythonScript > Configuration… to add your script to the Menu Items. Then, after Notepad++ restart, you can assign as keyboard shortcut to that script using Settings > Shortcut Mapper > Plugin Commands and filtering for PythonScript to easily find your script’s name. -
Just a note that if you started your script via startup.py and call it again, you will get two callbacks registered doing the same thing, that would be unnecessary. And if you want to call it intially with
on_set_edge_config()
, do not forget to add aNone
parameter, because the function expects anargs
dictionary. -
@PeterJones said in Loading preferences by file extension.:
I would have thought that BUFFERACTIVATED notification would trigger at Notepad++'s initial startup
Yea, the fact that this doesn’t happen is a sometimes-annoying quirk. :-(
-
So your best advice, as the script’s author, is to add a call to
on_set_edge_config(None)
instartup.py
? -
Yes, that’s what I usually do too, but I have to admit, npp_ready is also a nice solution too, since it’s only called once. As usual, there are more ways to Rome.
-
Thanks for all the input thus far. Much obliged!