• Login
Community
  • Login

Loading preferences by file extension.

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
12 Posts 4 Posters 902 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J
    James Swallow
    last edited by Feb 9, 2021, 9:22 PM

    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

    P 1 Reply Last reply Feb 9, 2021, 9:51 PM Reply Quote 0
    • P
      PeterJones @James Swallow
      last edited by Feb 9, 2021, 9:51 PM

      @James-Swallow ,

      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 with one.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.

      1 Reply Last reply Reply Quote 3
      • J
        James Swallow
        last edited by James Swallow Feb 9, 2021, 10:05 PM Feb 9, 2021, 10:03 PM

        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

        P E 2 Replies Last reply Feb 9, 2021, 10:07 PM Reply Quote 0
        • P
          PeterJones @James Swallow
          last edited by Feb 9, 2021, 10:07 PM

          @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).

          1 Reply Last reply Reply Quote 1
          • E
            Ekopalypse @James Swallow
            last edited by Feb 9, 2021, 10:26 PM

            @James-Swallow

            see here for an example based on the language used.

            1 Reply Last reply Reply Quote 2
            • J
              James Swallow
              last edited by Feb 11, 2021, 9:50 PM

              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?

              P 1 Reply Last reply Feb 11, 2021, 10:07 PM Reply Quote 0
              • P
                PeterJones @James Swallow
                last edited by Feb 11, 2021, 10:07 PM

                @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.

                A 1 Reply Last reply Feb 12, 2021, 1:09 PM Reply Quote 2
                • E
                  Ekopalypse
                  last edited by Ekopalypse Feb 12, 2021, 1:00 PM Feb 12, 2021, 12:59 PM

                  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 a None parameter, because the function expects an args dictionary.

                  A 1 Reply Last reply Feb 12, 2021, 1:12 PM Reply Quote 1
                  • A
                    Alan Kilborn @PeterJones
                    last edited by Alan Kilborn Feb 12, 2021, 1:10 PM Feb 12, 2021, 1:09 PM

                    @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. :-(

                    1 Reply Last reply Reply Quote 0
                    • A
                      Alan Kilborn @Ekopalypse
                      last edited by Feb 12, 2021, 1:12 PM

                      @Ekopalypse

                      So your best advice, as the script’s author, is to add a call to on_set_edge_config(None) in startup.py ?

                      1 Reply Last reply Reply Quote 1
                      • E
                        Ekopalypse
                        last edited by Feb 12, 2021, 1:48 PM

                        @Alan-Kilborn

                        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.

                        1 Reply Last reply Reply Quote 1
                        • J
                          James Swallow
                          last edited by Feb 12, 2021, 3:04 PM

                          Thanks for all the input thus far. Much obliged!

                          1 Reply Last reply Reply Quote 1
                          7 out of 12
                          • First post
                            7/12
                            Last post
                          The Community of users of the Notepad++ text editor.
                          Powered by NodeBB | Contributors