Community
    • Login

    Looking for tips/directions on how to best approach creating a custom plugin for Notepad++

    Scheduled Pinned Locked Moved Notepad++ & Plugin Development
    28 Posts 7 Posters 3.2k 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.
    • Michael VincentM
      Michael Vincent @Slusher59
      last edited by

      @slusher59 said in Looking for tips/directions on how to best approach creating a custom plugin for Notepad++:

      For example, I never saw this function “editor” in Python, but it seems like it’s related to Notepad/Scintilla.

      It is. At the top of your Npp PythonScript scripts, add the line:

      from Npp import *
      

      and that should be good enough to get past that “error” you’re now seeing.

      Cheers.

      1 Reply Last reply Reply Quote 1
      • Michael VincentM
        Michael Vincent @Slusher59
        last edited by

        @slusher59 said in Looking for tips/directions on how to best approach creating a custom plugin for Notepad++:

        I got a whole bunch of these saved regex searches, but when the search results in NPP look like in the screen above, where next to the number of hits the regex formula itself is displayed, it does not tell anything to colleagues who don’t know the regex syntax. And this in turn makes it very hard for them to understand what the searches are actually searching for.

        Workaround. Not pretty, but may be useful. Create your RegEx with the (?x) modifier to allow inline comments and free space. So here’s an example in my ‘shortcuts.xml’:

                <Macro name="Mike Test" Ctrl="no" Alt="no" Shift="no" Key="0">
                    <Action type="3" message="1700" wParam="0" lParam="0" sParam="" />
                    <Action type="3" message="1601" wParam="0" lParam="0" sParam="(?x) # Find Header 
        (?m)(?'PACKAGE_HEADER'^(?-i:package\b))(?s:.*?)(?=\s*(?:(?&PACKAGE_HEADER)|\Z))" />
                    <Action type="3" message="1625" wParam="0" lParam="2" sParam="" />
                    <Action type="3" message="1702" wParam="0" lParam="3" sParam="" />
                    <Action type="3" message="1701" wParam="0" lParam="1636" sParam="" />
                </Macro>
        
        

        Notice I use the (?x) modifier followed by a # to introduce the comment describing what the RegEx does. Then a line break and the actual RegEx.

        Running that macro in N++ produces:

        0c068f4e-b270-4e4c-b127-0114084a9644-image.png

        which of course still shows the complex RegEx in the search results, but notice the line “before” it is the nice comment.

        Does that help a little?

        Cheers.

        Slusher59S 1 Reply Last reply Reply Quote 2
        • Slusher59S
          Slusher59 @Michael Vincent
          last edited by

          @michael-vincent said in Looking for tips/directions on how to best approach creating a custom plugin for Notepad++:

          Does that help a little?

          This helps a ton!! Thank you! I will add these comments/descriptions to all current regexes and this will give me plenty of time to work on the actual plugin in python and taking my time to understand it all properly, without worrying that my colleagues are losing out on some of the functionalities of our tools!
          This will be a game changer and a first step in a new direction. Thank you again!

          Slusher59S 1 Reply Last reply Reply Quote 2
          • Slusher59S
            Slusher59 @Slusher59
            last edited by

            One more question, while I still remember it. Is it possible, in any way, even a crude one at the moment (due to my lack of skills), that if one of the search regex finds a string, NPP would prompt a user with a pop up window/message in any other form, that “hey, this has been found in your file, you might want to take a look at it”?

            Michael VincentM 1 Reply Last reply Reply Quote 1
            • Michael VincentM
              Michael Vincent @Slusher59
              last edited by Michael Vincent

              @slusher59 said in Looking for tips/directions on how to best approach creating a custom plugin for Notepad++:

              One more question, while I still remember it. Is it possible, in any way, even a crude one at the moment (due to my lack of skills), that if one of the search regex finds a string, NPP would prompt a user with a pop up window/message in any other form, that “hey, this has been found in your file, you might want to take a look at it”?

              I don’t think so with just the Macro approach. If you implement the searches in PythonScript, then yes absolutely possible as with any other scripting solution (NppExec for example) and certainly with a proper plugin.

              Cheers.

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

                @slusher59 said in Looking for tips/directions on how to best approach creating a custom plugin for Notepad++:

                Hey Guys,
                sorry for late response

                There’s a lot going on with this thread starting with “Hey Guys”.
                I’ll try to address some things further, in this and subsequent postings in this thread…

                @michael-vincent said in Looking for tips/directions on how to best approach creating a custom plugin for Notepad++:

                Create your RegEx with the (?x) modifier to allow inline comments and free space

                But using (?x) at the start can affect the meaning of what follows, unless you use (?-x) at some point after.

                Why not avoid that possibility and just use the comment specifier, example: (?#hello there I'm a comment) at the start of the regex?

                Michael VincentM 1 Reply Last reply Reply Quote 4
                • Alan KilbornA
                  Alan Kilborn @Michael Vincent
                  last edited by

                  @michael-vincent said in Looking for tips/directions on how to best approach creating a custom plugin for Notepad++:

                  if one of the search regex finds a string, NPP would prompt a user with a pop up window/message in any other form, that “hey, this has been found in your file, you might want to take a look at it”?

                  I don’t think so with just the Macro approach. If you implement the searches in PythonScript, then yes absolutely possible as with any other scripting solution (NppExec for example) and certainly with a proper plugin.

                  No way to do this in a macro, as stated. PythonScript has two functions for prompting the user:

                  notepad.prompt()
                  notepad.messageBox()

                  Each returns data which can impact script logic flow after the prompting box window is closed.

                  1 Reply Last reply Reply Quote 2
                  • Alan KilbornA
                    Alan Kilborn @Slusher59
                    last edited by

                    @slusher59 said in Looking for tips/directions on how to best approach creating a custom plugin for Notepad++:

                    I would also not want to lose on the great functionality of the search result window from Notepad++, that it provides on it’s own.

                    So that window and PythonScript don’t typically play well together. If you script searches, you have to find your own way of presenting the output to the user.

                    1 Reply Last reply Reply Quote 1
                    • Michael VincentM
                      Michael Vincent @Alan Kilborn
                      last edited by

                      @alan-kilborn said in Looking for tips/directions on how to best approach creating a custom plugin for Notepad++:

                      Why not avoid that possibility and just use the comment specifier, example: (?#hello there I’m a comment) at the start of the regex?

                      Much nicer solution!

                      EkopalypseE 1 Reply Last reply Reply Quote 2
                      • EkopalypseE
                        Ekopalypse @Michael Vincent
                        last edited by

                        @Slusher59

                        Plugins are usually shared libraries (dll) and creating them with Python is not as easy as with a language that is supposed to create them natively, like C++, C, D, Rust, C#, V or others. Yes, one way to create them is with Cython or also with cffi.

                        But I would recommend using another language instead, because as far as I know, including Python 3.10, there is still a problem if you want to embed more than one Python interpreter into a running process, which means that as long as you are the only one writing plugins for your own use, it’s fine, but as soon as another plugin developer decides to do so as well or someone wants to use the existing PythonScript plugin, then the problems start.

                        1 Reply Last reply Reply Quote 1
                        • Slusher59S
                          Slusher59
                          last edited by

                          Thank you. As a temporary band-aid fix for this (until I learn how to do the thing properly), is it possible in NPP to display only the search results that have > 0 hits, and hide all searches that returned 0 results?

                          EkopalypseE Alan KilbornA 2 Replies Last reply Reply Quote 0
                          • EkopalypseE
                            Ekopalypse @Slusher59
                            last edited by

                            @slusher59
                            No, as far as I know there is neither a built-in option nor a plugin message that would allow you to do this. And hacking it might be a bad idea because it could then conflict with subsequent searches.

                            1 Reply Last reply Reply Quote 1
                            • Alan KilbornA
                              Alan Kilborn @Slusher59
                              last edited by

                              @slusher59 said in Looking for tips/directions on how to best approach creating a custom plugin for Notepad++:

                              is it possible in NPP to display only the search results that have > 0 hits, and hide all searches that returned 0 results?

                              As I said before:

                              @alan-kilborn said in Looking for tips/directions on how to best approach creating a custom plugin for Notepad++:

                              So Search results window and PythonScript don’t typically play well together.

                              If you script searches, you have to find your own way of presenting the output to the user.

                              One way of doing this is having your script write output to a new (file) tab that it creates. That way you have total control of what goes into the output. You can even make it appear a lot like the usual Search results. If you want to get really fancy, you could even set it up so that double-clicking in this output would open the file where the hit was found.

                              It just depends if the time you want to spend on this is better spent scripting or developing a true plugin. But even a true plugin isn’t going to have an easy time of doing custom things with Notepad++'s Search results area.

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