How to integrate external lexer with NPP?
-
Thanks, but I wonder then how the Gedcom plugin lexer manages it!?
I’ve been looking through it’s source, but I can’t figure out how it does it yet…
-
Putting it into the menu isn’t the problem.
I assume it is calling InsertMenu(A/W) at some point and is hooking
the message queue to receive the click event.The problem starts when you want to appear it in the settings dialog and want npp to interact with it.
All in all, you can make it work if you start subclassing everything npp offers.
-
looks like I’m wrong, there is a way, npp knows something about external lexers.
Edit: and this.
-
-
Thanks again - will be able to try some more based on highlighted NPP source.
The issue is probably my imperfect understanding of C++ - especially exports etc!
-
I don’t know if you are using PS, probably not but in case you do,
here a little script which would check if your plugin has the exports
and do act correctly.import ctypes from ctypes import wintypes external_lexer = ctypes.WinDLL(r'D:\temp\GedcomLexer\GedcomLexer.dll') GetLexerCount = external_lexer.GetLexerCount GetLexerName = external_lexer.GetLexerName GetLexerName.argtypes = [wintypes.UINT, wintypes.LPCSTR, wintypes.INT] GetLexerStatusText = external_lexer.GetLexerStatusText GetLexerStatusText.argtypes = [wintypes.UINT, wintypes.LPCWSTR, wintypes.INT] GetLexerFactory = external_lexer.GetLexerFactory # ?? MAX_EXTERNAL_LEXER_NAME_LEN = 16 #+1 MAX_EXTERNAL_LEXER_DESC_LEN = 32 #+1 numLexers = GetLexerCount() print('Lexers:{}'.format(numLexers)) lexName = ctypes.create_string_buffer(MAX_EXTERNAL_LEXER_NAME_LEN) lexDesc = ctypes.create_unicode_buffer(MAX_EXTERNAL_LEXER_DESC_LEN) for x in range(numLexers): GetLexerName(x, lexName, MAX_EXTERNAL_LEXER_NAME_LEN) print(lexName.value) GetLexerStatusText(x, lexDesc, MAX_EXTERNAL_LEXER_DESC_LEN) print(lexDesc.value)
Testing with Gedcom lexer returns
Lexers:1 GEDCOM GEDCOM file
and a Npp pop saying that the GedcomLexer.xml is missing.
Not a surprise as I just loaded the dll but did not install the plugin at all.
Note, the GetLexerFactory is missing in the script.
-
@Ekopalypse Cool! It gave me expected count, but no name - I will investigate further tomorrow.
-
Hello @moon6969 ,
how are you, I hope good.
One question, did you follow up on your lexer plugin?
If so, one question, where does your lexer appear in the language menu?What I see so far is that external lexers appear since 7.?? above the builtin lexers.
Like here the nim lexer.
What is strange is that my VLang lexer does not do this.
I just can’t figure out what I’m missing. Do you have any ideas? -
@moon6969
I think I have found it. It is a “feature”.
When the name of the lexer comes before the “normal text” lexer, from the alphabetical point of view, it appears before “normal text”, but when it comes after that, it appears below it, but inside the Builtin lexers. Hmm. -
@Ekopalypse said in How to integrate external lexer with NPP?:
@moon6969
I think I have found it. It is a “feature”.
When the name of the lexer comes before the “normal text” lexer, from the alphabetical point of view, it appears before “normal text”, but when it comes after that, it appears below it, but inside the Builtin lexers. Hmm.I’d recommend pointing that out as a bug. I don’t know if they’ll fix it, but it should be officially documented.
-
It probably became a bug recently when None (Normal Text) was moved out of the N 's and up to the top.
Wasn’t I the one that said that change shouldn’t negatively impact anything (to @guy038)? :-)
@Ekopalypse Yea, it seems like you should put a bug report in on it.
-