Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Request: default filename is first line of file

    Plugin Development
    feature request
    4
    6
    434
    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.
    • Doug Rogers
      Doug Rogers last edited by

      With Word (et al) the first time you hit save it will enter the first line of the file as the default filename. For example, if my file is:
      Do List for 21-11-26
      task 1
      task 2

      the first time I hit Ctrl+S it will use “Do List for 21-11-26.txt” as the default filename. I wish Np++ would do this. Right now I have to copy the first line, hit Ctrl+S, then paste the first line in the save box.

      Alan Kilborn 1 Reply Last reply Reply Quote 0
      • Alan Kilborn
        Alan Kilborn @Doug Rogers last edited by

        @doug-rogers

        It makes zero sense for programmers, and Notepad++ is first and foremost a programmer’s text editor, so I don’t see something like this happening natively.

        However, something like this could be easily scripted with a PythonScript. A really barebones version (just as a demo) of SaveUsingFirstLineAsFilename.py might be:

        # -*- coding: utf-8 -*-
        
        from Npp import *
        
        class SUFLAF(object):
        
            def __init__(self):
                f = notepad.getCurrentFilename()
                if f.startswith('new '):
                    l = editor.getLine(0)
                    notepad.saveAs(l + '.txt')
        
        if __name__ == '__main__': SUFLAF()
        

        You’d run this script when you want to save such a file, rather than pressing Ctrl+s.

        1 Reply Last reply Reply Quote 2
        • stephane352
          stephane352 last edited by

          Using first line as default filename would be nice for text files though.

          Alan Kilborn 1 Reply Last reply Reply Quote 0
          • Alan Kilborn
            Alan Kilborn @stephane352 last edited by Alan Kilborn

            @stephane352 said in Request: default filename is first line of file:

            Using first line as default filename would be nice for text files though.

            Even that feels yucky to me and not something the Notepad++ developers would be likely to implement.

            If you must have it, go with the script approach. To work effectively, though, the script needs to be “rounded out” a bit more. I wasn’t inclined to do that, because I’d only do that kind of thing if it was some capability I had a lot of interest in. Because I don’t…someone else would have to do it.

            1 Reply Last reply Reply Quote 1
            • Doug Rogers
              Doug Rogers last edited by

              Thank you Alan K for that script. I used to use NPP for all my programming but now I use VSCode; but I still use NPP for all other text files (do lists, notes, etc) and for those this is a very useful feature.

              I didn’t know how to use it, so for others in the same predicament I had to:

              1. Go to Plugins menu | Plugins Admin; install PythonScript
              2. Plugins | PythonScript | New Script
              3. Paste the script, save it as FirstLineAsFileName

              to run it I have to do:
              Alt (to show menu) | Plugins | PythonScript | Scripts | FirstLineAsFileName

              I’m trying to figure out how to create a shortcut to run this script because it takes a lot of mousing to get to it

              PeterJones 1 Reply Last reply Reply Quote 0
              • PeterJones
                PeterJones @Doug Rogers last edited by

                @doug-rogers said in Request: default filename is first line of file:

                I’m trying to figure out how to create a shortcut to run this script because it takes a lot of mousing to get to it

                First, you have to tell PythonScript to add it to the menu: Plugins > PythonScript > Configuration…, then select the script and click the left Add button. Then restart Notepad++, and you will see that your chosen script is now at the Plugins > PythonScript > scriptname level instead of buried deeper. Once that’s true, then Notepad++'s Preferences > Shortcut Mapper > Plugin Commands will list your script (you can filter by PythonScript to find it faster), and you can assign a shortcut that way.

                1 Reply Last reply Reply Quote 1
                • First post
                  Last post
                Copyright © 2014 NodeBB Forums | Contributors