Community
    • Login

    Get Scintilla HWND for an ILexer/syntax highlighter plugin

    Scheduled Pinned Locked Moved Notepad++ & Plugin Development
    6 Posts 2 Posters 4.6k Views 2 Watching
    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.
    • William NewberyW Offline
      William Newbery
      last edited by

      Was looking at the possibility of doing some extra config (e.g. SCI_STYLESETEOLFILLED and some other style things Notepad++ hardcoded for the built in styling) and so want to send messages to the Scintilla editor control.

      The NppData struct has a _scintillaMainHandle and _scintillaSecondHandle. Anyone know of a way to determine which one owns a specific lexer instance (at the time it is being set, so changes apply to the initial rendering)?

      1 Reply Last reply Reply Quote 0
      • dailD Offline
        dail
        last edited by

        You can catch certain notifications from Notepad++ and then use NPPM_GETCURRENTSCINTILLA to see which handle to use.

        That being said…

        I’ve ran across this before – wanting to tweak style settings that aren’t configurable. You can easily do it with one of the scripting plugins. For example using LuaScript you could use something like:

        npp.AddEventHandler("OnSwitchFile", function(filename, bufferid)
            if npp.BufferLangType[bufferid] == L_CPP then
                editor.StyleEOLFilled[SCE_C_COMMENTLINE] = true
            end
        end)
        

        Also easily doable with PythonScript if you are familiar with it.

        1 Reply Last reply Reply Quote 0
        • William NewberyW Offline
          William Newbery
          last edited by

          Not really familiar with LuaScript/Python script for Notepad++, but looks like OnSwitchFile is NPPN_BUFFERACTIVATED and npp.BufferLangType[bufferid] is NPPM_GETBUFFERLANGTYPE?

          But not sure about the third line though, how does editor know to which of those 2 handles to send the message? Also id need to know what index above L_EXTERNAL my lexer is. I see that being stored by NppParameters.

          I think I can listen to NPPN_BUFFERACTIVATED and NPPN_LANGCHANGED (although sent after ILexer::Lex, hopefully that is ok). Then maybe SCI_GETLEXERLANGUAGE to both windows instead of the L_* enum as I get a string.

          Will give it a go, but for now I patched in a execute(SCI_PRIVATELEXERCALL, 1, reinterpret_cast<LPARAM>(_hSelf)); to the end of ScintillaEditView::setExternalLexer. Just from reading all that code think I’ll end up wanting ScintillaEditView::makeStyle anyway…

          1 Reply Last reply Reply Quote 0
          • dailD Offline
            dail
            last edited by

            but looks like OnSwitchFile is NPPN_BUFFERACTIVATED and npp.BufferLangType[bufferid] is NPPM_GETBUFFERLANGTYPE?

            Yep.

            But not sure about the third line though

            It is equivalent to SendMessage(theScintillaHandle, SCI_STYLESETEOLFILLED, SCE_C_COMMENTLINE, true);

            how does editor know to which of those 2 handles to send the message?

            When the plugin catches NPPN_BUFFERACTIVATED it internally calls NPPM_GETCURRENTSCINTILLA and updates editor to be the appropriate scintilla handle before running the chunk of Lua.

            Also id need to know what index above L_EXTERNAL my lexer is.

            That I’m not sure. Haven’t done much with external lexers. You might have to use something like NPPM_GETLANGUAGENAME to see if the name of the language matches your external lexer’s name.

            Will give it a go, but for now I patched in a execute(SCI_PRIVATELEXERCALL, 1, reinterpret_cast<LPARAM>(_hSelf)); to the end of ScintillaEditView::setExternalLexer. Just from reading all that code think I’ll end up wanting ScintillaEditView::makeStyle anyway…

            Are you making your own plugin or a custom Notepad++ version?

            1 Reply Last reply Reply Quote 0
            • William NewberyW Offline
              William Newbery
              last edited by William Newbery

              Ah, yes, that seems a cleaner way to get the window.

              If I can make it all in a separate plugin that would seem more ideal.

              But going to see where I end up with a personal prototype, don’t think any of it is new concepts, just finding ways to access them (e.g. how L_JS / “JavaScript (embedded)” works in the makeStyle case). I certainly don’t want to maintain a fork of either Notepad++ or SciLexer.dll (although I think they already provide all the needed tools, except maybe the specific lexers not being extendable other than copying the code) for this.

              1 Reply Last reply Reply Quote 0
              • dailD Offline
                dail
                last edited by

                Ok. I just wanted to make sure you weren’t heading down a path you didn’t need to :). Under normal situations, an external lexer can be fully contained within a plugin.

                1 Reply Last reply Reply Quote 0

                Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                With your input, this post could be even better 💗

                Register Login
                • First post
                  Last post
                The Community of users of the Notepad++ text editor.
                Powered by NodeBB | Contributors