[c#] Adding a custom styler or lexer in C# for scintilla/notepad++
I tried the edifact lexer with a 20MB file and the first load
took about 7 seconds, but then each change was made
in 4-7 ms according to
A good test to see if a lexer is fast enough is to press a key and hold it.
If you don’t see any stuttering while rendering, the lexer is fast enough.
According to the property, it looks like it is used immediately,
but I have found that it can take a while, depending on where
you are in the current file, since it starts changing from position 0 (
A possible solution would be to start with the first visible line
to speed things up.
As for the (re)styling, I haven’t found a good general approach.
I suppose this is something each lexer has to take care of itself.
Bas de Reuver last edited by Bas de Reuver
The CSV Lint plug-in uses the custom lexer and it’s working quite nicely, but a colleague pointed something out.
The default color styles for the plug-in uses background colors, so that you can clearly see the data columns. Btw it’s not always vertically aligned as columns, but that’s not the point, the plug-in is used to quickly eyeball the data and the colors help to spot any weird values.
Anyway currently the selected line, or cursor line, is always a blue/purple background color, and this blue background “erases” the column background colors. So when the user selects a line to edit values, the column colors on that line are not visible anymore and it’s harder to see which value is which column. You then have to move the line up or down to see the correct background colors again.
It would be nicer if the selected line has the same background colors except a little darker (or lighter or inverse colors or whatever) shade of the background colors. See mockup below, is it possible to do something like this in the lexer code?
Alan Kilborn last edited by
A suggestion that isn’t answering what you asked…have you considered turning this option off?:
@Alan-Kilborn Thanks for the suggestion 👍 I’ve tried that, although when you turn it off you do miss it, you do notice that having the selected line highlight is a very convenient option.
But it works in keeping the background colors, so I’ll recomment that for now.
@Ekopalypse Thanks, but if I understand correctly, the
SCI_SETSELBACK()affects the color of any selected text (default=grey) not of the current line highlighting (default=blue).
Ekopalypse last edited by Ekopalypse
oops - did I link the wrong function, sorry. But there is one for the current selected line.
Let me check.
I’ve tried both SCI_SETCARETLINEBACK and SCI_SETCARETLINEBACKALPHA with all kinds of parameter values, but as far as I can tell they don’t seem to do anything.
Win32.SendMessage(PluginBase.nppData._nppHandle, SciMsg.SCI_SETCARETLINEBACK, new Colour(255, 0, 0).Value, (IntPtr)0); Win32.SendMessage(PluginBase.nppData._nppHandle, SciMsg.SCI_SETCARETLINEBACKALPHA, (IntPtr)0, (IntPtr)0);
The documentation also mentions
SC_ELEMENT_CARET_LINE_BACKbut that one is not available in the
Any idea how to make the caret line tansparant so that you can also see the background colors of a selected line?
Another question about the colors. For a custom lexer you also have to distribute a color settings xml file.
It’s easiest to generate it at first time start-up, see this post.
This works great, but different users will have different preferences, in particular when running in dark mode. I know uesrs can change this in the
Settings > Style Configurator, but I would like to provide a few color presets that look pretty decent, see screenshot below and the LexerStyles xml. I know I could generate all 4 with 3 of them commented out or something like that, but not all users know how to find the XML file let alone edit it.
So is it possible to provide different XMLs for the different Notepad++ style themes? Or alternatively, can I somehow detect if Notepad++ is in dark mode? Then the plugin can just generate the approporiate dark mode colors to the xml.