Feature request (and temporary solution): a registered file type for NP++ session files



  • I save families of text files all the time, e.g., SQL queries related to a database project, VBA source files extracted from a big Excel-macro project, etc.; I’m sure many others do too. And to that end NP++ has implemented a feature to save and load session files.

    But there’s no default extension for session files, although, since the plain-text content looks like XML, it’s logical to give session files the extension XML if only to have NP++ open them and work with them in the XML language. So the first part of my request is that there should be a specific extension, NXML for example, which should be registered in Windows as Notepad++ Session File.

    The second part of my request is that NXML files, when double-clicked in Windows, open NP++'s Load Session command. That is, not the normal Notepad++ <filename>, but Notepad++ -openSession <filename>.

    My temporary solution is the following:

    • Create the following one-line Windows batch file, NP++Session.bat:
      start “%~n0” “%ProgramFiles%\Notepad++\notepad++.exe” -openSession “%*”

    • If you have a session file, change its extension to NXML; if not, open a bunch of text files, do File / Save Session, and save the session as an NXML file.

    • Right-click the NXML file, choose Open With and then Choose another app, scroll the list to the bottom, and choose Find an app on this PC – maybe that’s not the exact dialog, but you need to be browsing for a program.

    • Point to your NP++Session.bat file as the program with which to open NXML files.

    It would also help to register the NXML file type in Notepad++ as an XML-language file type.



  • @J.-Andrew-Smith said:

    there should be a specific extension, NXML for example,

    interesting idea. I don’t know what the Session Manager plugin does, but I’ve heard rumors that it highly enhances the

    Windows batch file, NP++Session.bat: start “%~n0” “%ProgramFiles%\Notepad++\notepad++.exe” -openSession “%*”

    If you were willing to manually edit your registry (or make a .reg file), you could actually directly associate that same command directly in the registry entry, rather than going through a batch file.

    It would also help to register the NXML file type in Notepad++ as an XML-language file type.
    Settings > Style Configurator > XML, add nxml to the “user ext.” list.

    BTW: this FAQ explains a better location for feature requests…



  • Peter, I tried modifying the registry, but it didn’t work. I searched for “nxml”, found “.nxml” and “nxml_auto_file”, found “NP++Session.bat” and changed it to “NotePad++ -OpenSession” but nothing changed even after restarting.

    It used to be simpler that that: how do I now modify my registry?



  • @J-Andrew-Smith ,

    First off, sorry for the poor quality of that last post: re-reading it to regather my context, I could barely understand what I was saying then; I’m sure it was nearly nonsense to you. Sorry.

    found “NP++Session.bat” and changed it to “NotePad++ -OpenSession” but nothing changed

    if you used those exact text in the registry, it wouldn’t surprise me if it didn’t work. You need to specify the full path to notepad++.exe (remembering to put quotes around it if it has spaces), and notepad++ options are case-sensitive, so -OpenSession is not the same as -openSession.

    how do I now modify my registry?

    So, if I were wanting to associate .nxml as a Notepad++ Session using my registry editing, I’d put it in the per-using registry settings, using the following sequence

    1. First, I’d make sure that there weren’t existing associations.
      • You already said you found the .nxml entry. If it is the HKEY_CLASSES_ROOT\.nxml, delete that whole key (because it’s in the global). If it’s in the HKEY_CURRENT_USER\Software\Classes\.nxml, leave it there and skip to step 3.
    2. Go to HKEY_CURRENT_USER\Software\Classes, right click on Classes on the left, and create a new KEY called .nxml.
    3. Edit the (Default) in HKEY_CURRENT_USER\Software\Classes\.nxml, set it to NppSession
    4. Right click on Classes again, and create a new key called NppSession
    5. Edit the (Default) in HKEY_CURRENT_USER\Software\Classes\NppSession, set it to Notepad++ Saved Session
    6. Right click on HKEY_CURRENT_USER\Software\Classes\NppSession, and add key Shell, and give it the (Default) = open
    7. Right click on HKEY_CURRENT_USER\Software\Classes\NppSession\Shell, and add key open, with (Default) = Open Notepad++ Session
    8. Right click on HKEY_CURRENT_USER\Software\Classes\NppSession\Shell\open, and add key command
    9. Give that new command key a (Default) = "%ProgramFiles%\Notepad++\notepad++.exe" -openSession "%1" %*
      • note the standard double-quotes around the executable path and the %1: that will help things if you have a space in either the folder for %ProgramFiles% (which is usually c:\program files\) or if you have a space in the path to the .nxml session file.

    At this point, you may have to log out and back in, and/or reboot, to get the change to propagate, though often times, that’s not necessary, and it’s immediately available. (I actually use the NirSoft nircmd, which has some verbs nircmd shellrefresh and nircmd sysrefresh which make Windows re-read the registry for file associations and other such registry changes, just to make sure, but avoiding having to log out. So if it didn’t update the association immediately, I would run those, then open a new Windows Explorer. )

    After starting a new Windows Explorer window, my blah.nxml is now listed with file type Notepad++ Saved Session, has an Open Notepad++ Session command in the right-click context menu, and selecting that (or double-clicking the blah.nxml) will open that session.



  • @PeterJones said:

    (Default) = "%ProgramFiles%\Notepad++\notepad++.exe" -openSession "%1" %*

    If you use this association, and double-click on multiple .nxml session files, all those sessions will likely overlap in the same Notepad++ instance (depending on your Settings > Preferences > Multi-Instance settings).

    As described here, if you change that line to

    (Default) = "%ProgramFiles%\Notepad++\notepad++.exe" -multiInst -openSession "%1" %*

    then each .nxml session file will open a separate instance of Notepad++.



  • @PeterJones said:

    double-click on multiple .nxml session files

    Curious. How does one actually do this? As a related experiment I took two .txt files in the same folder and selected them both in Explorer. Then, trying to double-click to get them both to open resulted in only one opening (the one my mouse cursor was on when I attempted the double-click).



  • @J.-Andrew-Smith

    There already is a possibility to define a file type for Notepad++ session files. Go to (menu) Settings -> Preferences -> (register) MISC -> Session file ext. and define a file type. The image below shows that I’ve choosen nppssn.

    Imgur

    If you save a session file with this extension, you can open it by right-clicking it in Explorer and choose Edit with Notepad++. All the files part of the session will be loaded.



  • @Alan-Kilborn said:

    @PeterJones said:

    double-click on multiple .nxml session files

    Curious. How does one actually do this?

    I meant double click on the first, then double click on the second.



  • @dinkumoil said:

    Session file ext. and define a file type. The image below shows that I’ve choosed nppssn.

    Cool, I didn’t know that’s what those preference fields were for. I’ve added that tidbit to my TODO list for the preferences documentation update.

    One benefit of my method vs yours (or of combining our two methods: using the same extension in both registry and Session file ext) – mine allows adding the -multiInst flag, so that if you’re normally in single-instance mode, but want to open multiple sessions simultaneously in separate instances, it will not work with always-single-instance mode. Oh, that’s what “open session in a new instance” is for. More clarifications to make in docs.

    Looks like I have enough TODOs in that file that I should be making a preferences-documentation pull request as soon as I have time. :-)


Log in to reply