Community

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

    Anyone used the new v8.3.3 API calls yet?

    Plugin Development
    4
    16
    309
    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.
    • PeterJones
      PeterJones last edited by

      I am trying to implement the new v8.3.3 API calls for my Perl Script behaves-like-a-plugin, but NPPM_GETEXTERNALLEXERAUTOINDENTMODE and NPPM_SETEXTERNALLEXERAUTOINDENTMODE are always returning 0 (which indicates a failure), and I cannot figure out what I’m doing wrong.

      Generally, when I have this problem, I switch over to my C/C++ testbed, which I can use to do SendMessage to the Notepad++ executable, and I can figure out what it needs to look like in the C/C++ realm… and once I’m there, I can do the tranlsations into all my Perl wrappers. But when I compile and run nppClientClassEnums.cpp, I can see that I can do old messages, but no matter what I have tried, I cannot get the two new calls to behave as I expect (they alwasy return 0, and the SET doesn’t seem to affect Notepad++ in any way).

      ...
          char x[] = "C++";
          fprintf(stderr, "x address = 0x%p => \"%s\"\n", x, x);
      
          ExternalLexerAutoIndentMode indentMode = ExternalLexerAutoIndentMode::Custom;
          fprintf(stderr, "try to write indentMode = %d for \"%s\"\n", indentMode, x);
      
          ret = SendMessage((HWND)hWnd, (UINT)(msg=NPPM_SETEXTERNALLEXERAUTOINDENTMODE), (WPARAM)(w=(LRESULT)x), (LPARAM)(l=(LRESULT)(&indentMode)));
          fprintf(stderr, "run SendMessage(0x%016I64x,0x%016I64x,0x%016I64x,0x%016I64x) = %016I64x\n", (LRESULT)hWnd, msg, w, l, ret);
      
          ret = SendMessage((HWND)hWnd, (UINT)(msg=NPPM_GETEXTERNALLEXERAUTOINDENTMODE), (WPARAM)(w=(LRESULT)x), (LPARAM)(l=(LRESULT)(indentMode)));
          fprintf(stderr, "run SendMessage(0x%016I64x,0x%016I64x,0x%016I64x,0x%016I64x) = %016I64x\n", (LRESULT)hWnd, msg, w, l, ret);
          fprintf(stderr, "read indentMode = %d\n", indentMode);
      

      Does anyone have (or can anyone come up with) example code that actually can SET and GET that lexer auto-indent mode correctly? It will be easiest for me to understand C/C++ (whether as a standalone external or as part of a plugin), but if you’ve got a plugin written in some other language, I might be able to muddle through (especially if you’re able to include debug prints that show the actual arguments to the SendMessage). (I am thinking maybe the GET will require some of the virtual memory allocation, because it’s GETting into an LPARAM, but the SET should be able to send just raw values, because it shouldn’t need any of the shared memory… but maybe I’m wrong and the WPARAM string also needs to be virtual memory. But if someone else has already had a chance to figure this out, or would be interested in figuring it out for their own use, I could use the help.)

      Ekopalypse 1 Reply Last reply Reply Quote 3
      • Ekopalypse
        Ekopalypse @PeterJones last edited by

        @peterjones

        It is looking for an external lexer like Vlang or Gedcom.

        >>> SendMessage(notepad.hwnd, 1024+1000+104, 'VLang', 1)
        1
        >>> SendMessage(notepad.hwnd, 1024+1000+104, 'VLang', 2)
        1
        >>> SendMessage(notepad.hwnd, 1024+1000+104, 'perl', 2)
        0
        >>> SendMessage(notepad.hwnd, 1024+1000+104, 'Perl', 0)
        0
        
        PeterJones 1 Reply Last reply Reply Quote 4
        • PeterJones
          PeterJones @Ekopalypse last edited by

          @ekopalypse ,

          That makes sense.

          Unfortunately, I cannot get it to return 1 with the GEDCOM lexer (with "Gedcom" or "GEDCOM" as the language name; I can see GEDCOM in my Langauge menu), whether I do 1024+1000+104 from PythonScript (like you showed) or from external C++ or PerlScript. :-(

          Ekopalypse 1 Reply Last reply Reply Quote 1
          • Ekopalypse
            Ekopalypse @PeterJones last edited by

            @peterjones

            Strange, works for me.

            c91ac3e3-ebca-4326-b0b7-12e61d0c8f87-image.png

            import ctypes
            ctypes.windll.user32.SendMessageW(notepad.hwnd, 1024+1000+104, 'GEDCOM', 2)
            
            mode = ctypes.c_ssize_t(0)
            ctypes.windll.user32.SendMessageW(notepad.hwnd, 1024+1000+103, 'GEDCOM', ctypes.pointer(mode))
            mode.value
            
            PeterJones 1 Reply Last reply Reply Quote 2
            • Ekopalypse
              Ekopalypse last edited by

              The name of the lexer seems to be case sensitive.

              1 Reply Last reply Reply Quote 2
              • PeterJones
                PeterJones @Ekopalypse last edited by PeterJones

                @ekopalypse ,

                b64c9ca5-951d-4916-b5b7-abd5c158cb6f-image.png

                and to prove that otherwise, Notepad++/PythonScript can do message communication:

                >>> winv = ctypes.windll.user32.SendMessageW(notepad.hwnd, 1024+1000+42,0,0)
                >>> console.write("Win v{}\n".format(winv))
                Win v14
                >>> nppv = ctypes.windll.user32.SendMessageW(notepad.hwnd, 1024+1000+50,0,0)
                >>> console.write("NPP v{}.{}\n".format(nppv>>16, nppv&0xFFFF))
                NPP v8.33
                

                I would be surprised if it’s Python 2.7.18 vs Python 3.8.5 (especially since I get the same 0s when I run from an external C++ program as well). But I’ll try that:

                984e090e-2b92-47fb-a413-d74388852d1a-image.png

                Weird… I would have expected the same results from PythonScript 2.0.0 as I got in PythonScript 3.0.12 alpha, since SendMessageW shouldn’t be significantly different between the two.

                At least I have a known working setup, and can start comparing what C++ and/or Perl are sending, as compared to Python.

                (Do you have notepad.hwnd set during your startup.py? Because I don’t have that attribute to the notepad object…)

                –
                Anyway, now time to go enjoy a few days at the coast with the family. I probably won’t be posting again in the forum until Sunday

                Alan Kilborn 2 Replies Last reply Reply Quote 2
                • Alan Kilborn
                  Alan Kilborn @PeterJones last edited by

                  @peterjones

                  Under Python 2, wouldn’t you want to pass u'GEDCOM' to SendMessageW, not 'GEDCOM' ?

                  1 Reply Last reply Reply Quote 1
                  • Ekopalypse
                    Ekopalypse last edited by

                    It’s like Alan said.
                    With Python2 you have to use a Unicode string u'GEDCOM' if you want to use the W version of SendMessage.
                    Another way would be to use SendMessageA and 'GEDCOM'.
                    With Python3 it is the other way round: 'GEDCOM' is the Unicode version and you would have to use b'GEDCOM' if you want to use SendMessageA.

                    This is the main difference between python2 and python3.

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

                      Sorry, I forgot to answer your question.
                      Yes, notepad.hwnd is set by my startup.py.

                      notepad.hwnd = user32.FindWindowW('Notepad++', None)
                      editor1.hwnd = user32.FindWindowExW(notepad.hwnd, None, "Scintilla", None)
                      editor2.hwnd = user32.FindWindowExW(notepad.hwnd, editor1.hwnd, "Scintilla", None)
                      notepad.splitter_hwnd = user32.FindWindowExW(notepad.hwnd,
                                                                   None,
                                                                   'splitterContainer',
                                                                   None)
                      

                      where user32 is

                      user32 = ctypes.WinDLL('user32')
                      

                      Enjoy your holidays/vacation/days off …

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

                        @ekopalypse said in Anyone used the new v8.3.3 API calls yet?:

                        Yes, notepad.hwnd is set by my startup.py.

                        More PS3 code, unless from __future__ import unicode_literals is at the top.

                        I don’t know, has everyone made the jump from PS2 to PS3, except me?

                        Ekopalypse Michael Vincent 2 Replies Last reply Reply Quote 1
                        • Ekopalypse
                          Ekopalypse @Alan Kilborn last edited by

                          @alan-kilborn

                          I assume that most users use Python 2, as it is the default PythonScript version installed via the plugin admin.

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

                            @alan-kilborn said in Anyone used the new v8.3.3 API calls yet?:

                            I don’t know, has everyone made the jump from PS2 to PS3, except me?

                            We dumped Python2 back in December 2019 right before it was sunsetted. A few months of migration prior and then all new scripts were Python3. Since Python3 is the only Python installed on my Windows system, I first started with PythonScript 3.0.7-alpha (since it matched my Python 3.8 version) and I haven’t changed since.

                            Cheers.

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

                              @michael-vincent

                              Note that I said:

                              has everyone made the jump from PS2 to PS3, except me?

                              which is NOT equivalent to:

                              “has everyone made the jump from Python2 to Python3, except me?”

                              The jump to Python3 for all purposes other than N++ scripting was made long ago.

                              :-)

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

                                @alan-kilborn said in Anyone used the new v8.3.3 API calls yet?:

                                “has everyone made the jump from Python2 to Python3, except me?”
                                The jump to Python3 for all purposes other than N++ scripting was made long ago.

                                Agreed. I didn’t explain in detail enough, sorry.

                                Since I’m coding in Python3 and my goal to install PythonScript was to get some Language Server / IDE-like features when coding Python, I needed to run PythonScript 3 so my parsing libraries (Jedi, Rope, PyFlakes) are installed in my system Python3 and will parse Python3 code and PythonScript 3 will find them and execute them.

                                Cheers.

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

                                  @peterjones said in Anyone used the new v8.3.3 API calls yet?:

                                  Anyway, now time to go enjoy a few days at the coast with the family. I probably won’t be posting again in the forum until Sunday

                                  If you put the same effort into your day job as you do here in the Community and also on the N++ user manual, a resounding “WELL DESERVED!” :-)

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

                                    @alan-kilborn & @Ekopalypse ,

                                    After getting back from the coast, I confirmed that

                                    import ctypes
                                    notepad.hwnd = ctypes.windll.user32.FindWindowW(u'Notepad++', None)
                                    nppv = ctypes.windll.user32.SendMessageW(notepad.hwnd, 1024+1000+50,0,0)
                                    console.write("NPP v{}.{}\n".format(nppv>>16, nppv&0xFFFF))
                                    ctypes.windll.user32.SendMessageW(notepad.hwnd, 1024+1000+104, u'GEDCOM', 2)
                                    mode = ctypes.c_ssize_t(0)
                                    ctypes.windll.user32.SendMessageW(notepad.hwnd, 1024+1000+103, u'GEDCOM', ctypes.pointer(mode))
                                    mode.value
                                    

                                    did what I wanted in old PythonScript, so it was a matter of the missing unicode marker. Which probably means that the reason my compiled version failed was probably that it wasn’t in UTF-16-LE like it should have been. But it gives me a lead, and I know in my PerlScript source code what I need to do to make sure that I send the string as UTF-16-LE.

                                    –
                                    c4847b06-4ba8-4e99-a958-78dcbcbfe77f-image.png
                                    (A few minutes before the moon set behind the clouds this morning. Twas a nice few days… but now, back to reality.)

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