Get Scintilla HWND for an ILexer/syntax highlighter plugin
-
Was looking at the possibility of doing some extra config (e.g.
SCI_STYLESETEOLFILLEDand some other style things Notepad++ hardcoded for the built in styling) and so want to send messages to the Scintilla editor control.The
NppDatastruct has a_scintillaMainHandleand_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_GETCURRENTSCINTILLAto 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
OnSwitchFileisNPPN_BUFFERACTIVATEDandnpp.BufferLangType[bufferid]isNPPM_GETBUFFERLANGTYPE?But not sure about the third line though, how does
editorknow to which of those 2 handles to send the message? Also id need to know what index aboveL_EXTERNALmy lexer is. I see that being stored byNppParameters.I think I can listen to
NPPN_BUFFERACTIVATEDandNPPN_LANGCHANGED(although sent afterILexer::Lex, hopefully that is ok). Then maybeSCI_GETLEXERLANGUAGEto both windows instead of theL_*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 ofScintillaEditView::setExternalLexer. Just from reading all that code think I’ll end up wantingScintillaEditView::makeStyleanyway… -
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_BUFFERACTIVATEDit internally callsNPPM_GETCURRENTSCINTILLAand updateseditorto 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_GETLANGUAGENAMEto 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.
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