Get Scintilla HWND for an ILexer/syntax highlighter plugin



  • 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)?



  • 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.



  • 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…



  • 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?



  • 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.



  • 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.


Log in to reply