<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[[c#] Adding a custom styler or lexer in C# for scintilla&#x2F;notepad++]]></title><description><![CDATA[<p dir="auto">I’m working on a plugin using the <a href="https://github.com/kbilsted/NotepadPlusPlusPluginPack.Net" rel="nofollow ugc">kbilsted/NotepadPlusPlusPluginPack.Net</a> so working in C#. I would like to implement a styler to apply custom CSV colors to the text line-by-line, so similar to the <a href="https://marketplace.visualstudio.com/items?itemName=mechatroner.rainbow-csv" rel="nofollow ugc">Rainbow CSV</a> for Visual Studio Code.</p>
<p dir="auto">However, I’m having trouble setting up a custom lexer or styler in C# at all. At the moment I’m not worried about how to parse CSV etc. but first just setting up any custom style using C# and getting it to work.</p>
<p dir="auto">I’ve found <a href="https://community.notepad-plus-plus.org/topic/10352/plugin-development-implementing-a-self-contained-lexer-for-scintilla">an old post here</a>, by user <a class="plugin-mentions-user plugin-mentions-a" href="/user/greenzest" aria-label="Profile: greenzest">@<bdi>greenzest</bdi></a> and <a class="plugin-mentions-user plugin-mentions-a" href="/user/nick-brown" aria-label="Profile: Nick-Brown">@<bdi>Nick-Brown</bdi></a> and the original poster mentions that he managed to set the lexer to <code>SCLEX_CONTAINER</code> without problems in C#. But he doesn’t give example code or hints on how he was able to do it. ☹</p>
<p dir="auto">And I’ve found <a href="https://github.com/jacobslusser/ScintillaNET/blob/master/src/ScintillaNET/Lexer.cs" rel="nofollow ugc">the ScintillaNET C# library</a> which mentioned lexer style a lot, but the sourcecode is mostly just enums and interfaces, as far as I can see there is no example code on how to start a custom lexer or styler.</p>
<p dir="auto">Also, I’ve found <a href="https://community.notepad-plus-plus.org/topic/11913/syntax-highlight-entire-line-or-to-end-of-line/5">example code here</a>, but it looks like it’s using LuaScript. How would you do something like that in C#? So if I wanted to just start the custom lexer by pressing a button, I’ve based my C# code on the LuaScript but it doesn’t even compile obviously. Because I don’t know how to set call the <code>AddEventHandler</code> or which class type the <code>Styler</code> is supposed to be.</p>
<pre><code>    private void OnMyButton_Click(object sender, EventArgs e)
    {
        ScintillaGateway editor = PluginBase.CurrentScintillaGateway;
        const int SCLEX_CONTAINER = 0;

        //  cpp example found here https://community.notepad-plus-plus.org/topic/11913/syntax-highlight-entire-line-or-to-end-of-line/5
        // and see also https://github.com/jacobslusser/ScintillaNET/blob/master/src/ScintillaNET/NativeMethods.cs

        // TESTING: button will toggle lexer on and off
        _lexerOn = !_lexerOn;

        // set or remove custom CSV lexer styler
        if (_lexerOn)
        {
            npp.AddEventHandler("OnStyle", StyleCSV);

            editor.SetLexer(SCLEX_CONTAINER);

            editor.StyleSetBack(1, 0xffffff);
            editor.StyleSetBack(2, 0xC0D9AF);

            editor.StyleSetEOLFilled(1, true);
            editor.StyleSetEOLFilled(2, true);
            editor.ClearDocumentStyle();
            editor.Colourise(0, -1);
            editor.SetCaretLineVisible(false);
        }
        else
        {
            npp.RemoveEventHandler("OnStyle", StyleCSV)
            editor.SetCaretLineVisible(true);
        }
    }

    private void StyleCSV(styler)
    {
        ScintillaGateway editor = PluginBase.CurrentScintillaGateway;

        // A line oriented lexer - style the line according to the line number
        int lineStart = editor.LineFromPosition(styler.startPos);

        int lineEnd = editor.LineFromPosition(styler.startPos + styler.lengthDoc)
        editor.StartStyling(styler.startPos, 31);

        for (int line = lineStart; line &lt; lineEnd; line++)
        {
            int lengthLine = editor.PositionFromLine(line + 1) - editor.PositionFromLine(line);
            if (line % 2 == 0)
            {
                editor.SetStyling(lengthLine, 1);
            }
            else
            {
                editor.SetStyling(lengthLine, 2);
            }
        }
    }
</code></pre>
<p dir="auto">Any help to get me started in the right direction would be greatly appreciated.</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/21124/c-adding-a-custom-styler-or-lexer-in-c-for-scintilla-notepad</link><generator>RSS for Node</generator><lastBuildDate>Sat, 13 Jun 2026 00:43:22 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/21124.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 04 May 2021 23:00:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [c#] Adding a custom styler or lexer in C# for scintilla&#x2F;notepad++ on Mon, 12 Sep 2022 22:20:08 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ekopalypse" aria-label="Profile: Ekopalypse">@<bdi>Ekopalypse</bdi></a> thanks for the answer. 🤔 Adding listeners for the BufferActivated event and manually setting the style each time the user switches to a different tab adds a lot of code and possibilities for bugs, for something that the user typically only does once…</p>
<p dir="auto">Honestly I think I’ll undo the new code and go back to just asking the user to restart Notepad++ after they change the default color set.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/79724</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/79724</guid><dc:creator><![CDATA[Bas de Reuver]]></dc:creator><pubDate>Mon, 12 Sep 2022 22:20:08 GMT</pubDate></item><item><title><![CDATA[Reply to [c#] Adding a custom styler or lexer in C# for scintilla&#x2F;notepad++ on Mon, 12 Sep 2022 09:25:51 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bas-de-reuver" aria-label="Profile: Bas-de-Reuver">@<bdi>Bas-de-Reuver</bdi></a></p>
<blockquote>
<p dir="auto">…  to another file, the colors in the other file are still in the old/original color style. And when I go back to the first file tab, the colors are also back in the old color style.</p>
</blockquote>
<blockquote>
<p dir="auto">… I suspect it has to do with getting a handle on the editor via the GetCurrentScintilla function. But that doesn’t explain why all the colors were reset to the original, and not just for one tab.</p>
</blockquote>
<p dir="auto">Npp only knows that styles for this lexer should be changed by reading the XML when starting the application or if modified via the style dialog during runtime. Whenever switching to another tab, Npp will determine which lexer is used for this buffer and accordingly changes the styles via StyleSet… Functions. There is no other official way, that I know of, to make this known to Npp at runtime.</p>
<blockquote>
<p dir="auto">Do I need to do something additional in the code to make the style change permanent? It seems that the Lexer plugin also has the original colors from the start (read from the XML) stored somewhere, but where is that?</p>
</blockquote>
<p dir="auto">There is of course the way to find out where Npp keeps the data in memory and then modify accordingly, but you don’t want to go that way, it is not only highly error prone but more likely to crash Npp. One possibility would be to do the same as Npp, when a BufferActivated event is triggered, set the styles as you already did.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/79701</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/79701</guid><dc:creator><![CDATA[Ekopalypse]]></dc:creator><pubDate>Mon, 12 Sep 2022 09:25:51 GMT</pubDate></item><item><title><![CDATA[Reply to [c#] Adding a custom styler or lexer in C# for scintilla&#x2F;notepad++ on Sat, 10 Sep 2022 10:29:50 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ekopalypse" aria-label="Profile: Ekopalypse">@<bdi>Ekopalypse</bdi></a> I can update the style using <code>StyleSetBack</code> and <code>StyleSetFore</code> and this works, the new colors are immediately visible. I also overwrite the new style to the XML styler file, so on next start-up it keeps the news colors.</p>
<p dir="auto">However, I just noticed that when I don’t restart Notepad++ and switch to a different file, the colors in the other file are still in the old/original color style. And when I go back to the first file tab that’s now also back in the old color style. (Btw the colors <em>are</em> correctly changed when I restart Notepad++ because of also the XML update, but I don’t want the user to have to restart)</p>
<p dir="auto">I suspect it has to do with getting a handle to the editor through <a href="https://github.com/BdR76/CSVLint/blob/master/CSVLintNppPlugin/PluginInfrastructure/NppPluginNETBase.cs#L51" rel="nofollow ugc">GetCurrentScintilla</a> function. But that doesn’t explain why all colors as changed back to the original, and not just for one tab.</p>
<p dir="auto">Do I have to do anything additional in code to make the style change permanent? Seems like the lexer plugin also stored the original colors from startup (read form the XML) somewhere, but where is that?</p>
]]></description><link>https://community.notepad-plus-plus.org/post/79646</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/79646</guid><dc:creator><![CDATA[Bas de Reuver]]></dc:creator><pubDate>Sat, 10 Sep 2022 10:29:50 GMT</pubDate></item><item><title><![CDATA[Reply to [c#] Adding a custom styler or lexer in C# for scintilla&#x2F;notepad++ on Fri, 09 Sep 2022 04:19:43 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bas-de-reuver" aria-label="Profile: Bas-de-Reuver">@<bdi>Bas-de-Reuver</bdi></a> said in <a href="/post/79621">[c#] Adding a custom styler or lexer in C# for scintilla/notepad++</a>:</p>
<blockquote>
<p dir="auto">StyleSetBack and StyleSetFore</p>
</blockquote>
<p dir="auto">btw … this is usually what Npp does when the buffer is activated or a user changes the configuration via the style configuration dialog.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/79629</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/79629</guid><dc:creator><![CDATA[Ekopalypse]]></dc:creator><pubDate>Fri, 09 Sep 2022 04:19:43 GMT</pubDate></item><item><title><![CDATA[Reply to [c#] Adding a custom styler or lexer in C# for scintilla&#x2F;notepad++ on Fri, 09 Sep 2022 04:11:06 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bas-de-reuver" aria-label="Profile: Bas-de-Reuver">@<bdi>Bas-de-Reuver</bdi></a></p>
<p dir="auto">The xml file is only there to tell Npp how the<br />
properties of the various styles CSVLint uses are to be set<br />
once a buffer is activated, reflecting of course what has been coded internally,<br />
so GetNamedStyles returns what your <a href="https://github.com/BdR76/CSVLint/blob/089b8d54282514bbb93facddd9219c3442e84f16/CSVLintNppPlugin/PluginInfrastructure/Lexer.cs#L727" rel="nofollow ugc">lexer has specified</a> and in fact<br />
the CSVLintLexer has only <a href="https://github.com/BdR76/CSVLint/blob/089b8d54282514bbb93facddd9219c3442e84f16/CSVLintNppPlugin/PluginInfrastructure/Lexer.cs#L42" rel="nofollow ugc">one style</a> defined.</p>
<p dir="auto">You need to find a way to map your <a href="https://github.com/BdR76/CSVLint/blob/089b8d54282514bbb93facddd9219c3442e84f16/CSVLintNppPlugin/PluginInfrastructure/Lexer.cs#L471" rel="nofollow ugc">idx</a> to the styles you<br />
provided in the xml, and then code the associated functions</p>
<pre><code class="language-csharp">            public ILexerNamedStyles NamedStyles;
            public ILexerNameOfStyle NameOfStyle;
            public ILexerTagsOfStyle TagsOfStyle;
            public ILexerDescriptionOfStyle DescriptionOfStyle;
</code></pre>
<p dir="auto">to your liking.</p>
<p dir="auto">I hope I have understood the question correctly this time. :-)</p>
]]></description><link>https://community.notepad-plus-plus.org/post/79628</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/79628</guid><dc:creator><![CDATA[Ekopalypse]]></dc:creator><pubDate>Fri, 09 Sep 2022 04:11:06 GMT</pubDate></item><item><title><![CDATA[Reply to [c#] Adding a custom styler or lexer in C# for scintilla&#x2F;notepad++ on Thu, 08 Sep 2022 22:51:56 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ekopalypse" aria-label="Profile: Ekopalypse">@<bdi>Ekopalypse</bdi></a> thanks for the answer and looking into this, really appreciate it. I am able to update the custom style of my lexer plug-in, using <code>StyleSetBack</code> and <code>StyleSetFore</code>. The style changes are immediately visible, so that is a nice Quality-Of-Life improvement I will put in the next update. 😀</p>
<pre><code>// get handle for editor
var IScintillaGateway editor = new ScintillaGateway(PluginBase.GetCurrentScintilla());
	
// etc..
	
// update style immediately
var fgcolor = x0ff00ff; //pink
var fgcolor = x000ffff; //yellow, apparently it's stored b-g-r so not x0ffff00
	
editor.StyleSetBack(idx, new Colour(fgcolor));
editor.StyleSetFore(idx, new Colour(bgcolor));
editor.StyleSetBold(idx, bold);
</code></pre>
<p dir="auto">However, I wasn’t looking for that in my previous post. And to be clear I also wasn’t looking to reload the XML dynamically or live-update any changes made externally to the XML settings file.</p>
<p dir="auto">I meant, programmatically get the number of Style items currently in the lexer (also storedin in the XML file). Or maybe get a string-list of the currently available styles. I tried the method <code>GetNamedStyles</code>, expecting to return the number of Styles in the list</p>
<pre><code>// color index
var test123 = editor.GetNamedStyles(); // always returns 1?
</code></pre>
<p dir="auto">So in the lexer in the example screenshot, I expected it to return <code>10</code> but it returns <code>1</code>(?)</p>
]]></description><link>https://community.notepad-plus-plus.org/post/79621</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/79621</guid><dc:creator><![CDATA[Bas de Reuver]]></dc:creator><pubDate>Thu, 08 Sep 2022 22:51:56 GMT</pubDate></item><item><title><![CDATA[Reply to [c#] Adding a custom styler or lexer in C# for scintilla&#x2F;notepad++ on Thu, 08 Sep 2022 19:37:43 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bas-de-reuver" aria-label="Profile: Bas-de-Reuver">@<bdi>Bas-de-Reuver</bdi></a></p>
<p dir="auto">If I did my homework, STYLE_LASTPREDEFINED is only used internally by Scintilla and is only available in a header to inform implementing applications and lexers that this range, 32-STYLE_LASTPREDEFINED, should not be used.<br />
As for the actual problem, from my point of view there is a problem. Npp reads the XML file before the user uses it, and there is currently no way to change this from Npp so that Npp would re-read this file. That means the user would have to restart Npp every time they changed it, or you provide that option via the lexer and a custom configuration menu.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/79614</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/79614</guid><dc:creator><![CDATA[Ekopalypse]]></dc:creator><pubDate>Thu, 08 Sep 2022 19:37:43 GMT</pubDate></item><item><title><![CDATA[Reply to [c#] Adding a custom styler or lexer in C# for scintilla&#x2F;notepad++ on Thu, 08 Sep 2022 10:52:01 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bas-de-reuver" aria-label="Profile: Bas-de-Reuver">@<bdi>Bas-de-Reuver</bdi></a></p>
<p dir="auto">STYLE_LASTPREDEFINED is used internally by Scintilla and is not publicly available through the API, but I’ll have to double check. Your lexer has 256 styles available, with Scintilla using IDs from 32-39 internally. Since it’s your lexer, you should be able to get the list of style IDs used via some configuration settings.<br />
I’m at the end of my lunch break right now, but I’ll try to come back to this later in the day. See you then.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/79596</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/79596</guid><dc:creator><![CDATA[Ekopalypse]]></dc:creator><pubDate>Thu, 08 Sep 2022 10:52:01 GMT</pubDate></item><item><title><![CDATA[Reply to [c#] Adding a custom styler or lexer in C# for scintilla&#x2F;notepad++ on Wed, 07 Sep 2022 21:21:34 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ekopalypse" aria-label="Profile: Ekopalypse">@<bdi>Ekopalypse</bdi></a> I’ve got some more time to work on the plug-in again. And I’m looking at the <code>STYLE_LASTPREDEFINED</code> but how do I use this, is this a notification message, or do I need to send it Scintilla using <code>Win32.SendMessage(scintilla, ..</code> ?</p>
<p dir="auto">I’m trying to dynamically (at runtime) determine how many Styles are defined for the custom Lexer. The idea is that the user can decide to add more or fewer color styles in the XML, and the plug-in Lexer will use more or fewer of those styles, depending on how many there are.</p>
<p dir="auto">So is it possible to get the maximum valid styleID? Or maybe a list of the Style names? So in the example below, it’s 10 styles, from <code>Default</code> to <code>HigLightNumeric</code></p>
<p dir="auto"><img src="/assets/uploads/files/1662585553559-notepad_style_items.png" alt="notepad_style_items.png" class=" img-fluid img-markdown" /></p>
]]></description><link>https://community.notepad-plus-plus.org/post/79588</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/79588</guid><dc:creator><![CDATA[Bas de Reuver]]></dc:creator><pubDate>Wed, 07 Sep 2022 21:21:34 GMT</pubDate></item><item><title><![CDATA[Reply to [c#] Adding a custom styler or lexer in C# for scintilla&#x2F;notepad++ on Wed, 18 May 2022 07:25:24 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bas-de-reuver" aria-label="Profile: bas-de-reuver">@<bdi>bas-de-reuver</bdi></a></p>
<p dir="auto">What you are looking for are the <a href="https://www.scintilla.org/ScintillaDoc.html#StyleDefinition" rel="nofollow ugc">style definitions</a>.<br />
The <code>styleID</code> from the xml is the <code>int style</code> value from the methods.<br />
But that doesn’t inform Npp (afaik, there is no official API that can be used to do this) that there are changes that need to be reaccounted for,<br />
and you therefore need to do this with each bufferactivated event which means it is effectively done twice, once by Npp and once by your lexer.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/76879</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/76879</guid><dc:creator><![CDATA[Ekopalypse]]></dc:creator><pubDate>Wed, 18 May 2022 07:25:24 GMT</pubDate></item><item><title><![CDATA[Reply to [c#] Adding a custom styler or lexer in C# for scintilla&#x2F;notepad++ on Tue, 17 May 2022 20:04:27 GMT]]></title><description><![CDATA[<p dir="auto">With a custom lexer, is it possible to update the syntax highlighting colors through code?</p>
<p dir="auto">In <a href="https://github.com/BdR76/CSVLint" rel="nofollow ugc">my plug-in</a> the user can select 4 pre-set colors schemes, and the plugin just overwrites the <code>&lt;plug-in name&gt;.xml</code> file with the new colors and then shows a dialog asking the user to restart Notepad++ so that the new colors are applied.</p>
<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;NotepadPlus&gt;
	&lt;Languages&gt;&lt;!-- etc.. --&gt;&lt;/Languages&gt;
	&lt;LexerStyles&gt;
		&lt;LexerType name="CSVLint" desc="CSV Linter and validator" excluded="no"&gt;
			&lt;WordsStyle styleID="0" name="Default" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" /&gt;
			&lt;WordsStyle styleID="1" name="ColumnColor1" fgColor="000000" bgColor="E0E0FF" fontName="" fontStyle="0" /&gt;
			&lt;WordsStyle styleID="2" name="ColumnColor2" fgColor="000000" bgColor="FFFF80" fontName="" fontStyle="0" /&gt;
			&lt;WordsStyle styleID="3" name="ColumnColor3" fgColor="000000" bgColor="FFE0FF" fontName="" fontStyle="0" /&gt;
			&lt;!-- etc.. --&gt;
</code></pre>
<p dir="auto">But is it possible to update the syntax highlighting colors immediately without restarting Notepad++? So update the color settings through code or a API call?</p>
<p dir="auto">I know something might be possible, because when you go to <code>Settings -&gt; Style Configurator..</code> and change the syntax highlighting colors, Notepad++ will immediately update them visibly. Meaning that, if you have a file opened with that particular syntax highlighting then you will see the new colors being applied right away.</p>
<p dir="auto">I’ve looked at <a href="https://www.scintilla.org/ScintillaDoc.html" rel="nofollow ugc">the documentation</a> but couldn’t find anything for this.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/76873</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/76873</guid><dc:creator><![CDATA[Bas de Reuver]]></dc:creator><pubDate>Tue, 17 May 2022 20:04:27 GMT</pubDate></item><item><title><![CDATA[Reply to [c#] Adding a custom styler or lexer in C# for scintilla&#x2F;notepad++ on Sun, 30 Jan 2022 10:23:48 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bas-de-reuver" aria-label="Profile: bas-de-reuver">@<bdi>bas-de-reuver</bdi></a></p>
<p dir="auto">to be honest, I have no experience with this feature.<br />
I’ve never tested or researched what idle styling means for UI responsiveness in general, or when it was introduced and under what conditions at the time. If it really runs in the main Scintilla thread, then it could mean that on a machine that is always highly loaded, the editing part is significantly worse, meaning noticeable to a user.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/73474</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/73474</guid><dc:creator><![CDATA[Ekopalypse]]></dc:creator><pubDate>Sun, 30 Jan 2022 10:23:48 GMT</pubDate></item><item><title><![CDATA[Reply to [c#] Adding a custom styler or lexer in C# for scintilla&#x2F;notepad++ on Sat, 29 Jan 2022 23:50:06 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ekopalypse" aria-label="Profile: ekopalypse">@<bdi>ekopalypse</bdi></a> Thanks the <code>SetIdleStyling</code> seems to work as intended. When I set the following at the beginning, then large files will open faster</p>
<pre><code>    var editor = new ScintillaGateway(PluginBase.GetCurrentScintilla());

    editor.SetIdleStyling(IdleStyling.ALL); // instead of default IdleStyling.NONE
</code></pre>
<p dir="auto">The file is not immediately colored, which is as expected, and the syntax coloring runs in the background. You can freely scroll to the end of a large &gt;10MB csv file,. At first it’s white and then the syntax colors will apear from top to bottom with a short delay. Also, smaller files still work as well, if you open them they are immediately in the correct colors.</p>
<p dir="auto">I wonder though, why is <code>IdleStyling.NONE</code> the standard, why not always use <code>IdleStyling.ALL</code> by default?</p>
]]></description><link>https://community.notepad-plus-plus.org/post/73468</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/73468</guid><dc:creator><![CDATA[Bas de Reuver]]></dc:creator><pubDate>Sat, 29 Jan 2022 23:50:06 GMT</pubDate></item><item><title><![CDATA[Reply to [c#] Adding a custom styler or lexer in C# for scintilla&#x2F;notepad++ on Sat, 22 Jan 2022 11:28:28 GMT]]></title><description><![CDATA[<p dir="auto">The <a href="https://www.scintilla.org/ScintillaDoc.html#SCI_CREATELOADER" rel="nofollow ugc">ILoader</a> interface could help here.<br />
First load only the “visible” part and then more and more. But I suppose without Npp taking this into account as well, it might be difficult to implement this in a safe way.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/73150</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/73150</guid><dc:creator><![CDATA[Ekopalypse]]></dc:creator><pubDate>Sat, 22 Jan 2022 11:28:28 GMT</pubDate></item><item><title><![CDATA[Reply to [c#] Adding a custom styler or lexer in C# for scintilla&#x2F;notepad++ on Sat, 22 Jan 2022 11:20:21 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bas-de-reuver" aria-label="Profile: bas-de-reuver">@<bdi>bas-de-reuver</bdi></a></p>
<p dir="auto">Afaik, calculating the area of the document to color is an internal Scintilla thing, and I suppose it makes a difference if you open a document where the cursor is at the very top or rather at the end of the document.<br />
The tip <a class="plugin-mentions-user plugin-mentions-a" href="/user/michael-vincent" aria-label="Profile: michael-vincent">@<bdi>michael-vincent</bdi></a> gave to use getfirstvisibleline and linesonscreen might help if</p>
<ul>
<li>the lexer is line-based</li>
<li>all lines are visible</li>
<li>and wrapped lines are taken into account<br />
I’m not sure what happens when you scroll up when you have only a bottom part lexed. Does Scintilla think that everything has already been edited?</li>
</ul>
]]></description><link>https://community.notepad-plus-plus.org/post/73149</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/73149</guid><dc:creator><![CDATA[Ekopalypse]]></dc:creator><pubDate>Sat, 22 Jan 2022 11:20:21 GMT</pubDate></item><item><title><![CDATA[Reply to [c#] Adding a custom styler or lexer in C# for scintilla&#x2F;notepad++ on Fri, 21 Jan 2022 20:26:27 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bas-de-reuver" aria-label="Profile: bas-de-reuver">@<bdi>bas-de-reuver</bdi></a> said in <a href="/post/73140">[c#] Adding a custom styler or lexer in C# for scintilla/notepad++</a>:</p>
<blockquote>
<p dir="auto">Ideally the user scrolls through the file, and the colors are incrementally applied to the visible areas, is that possible?</p>
</blockquote>
<p dir="auto">Yes, but maybe not by default?  Not sure how the <code>Lex()</code> thing works, but your plugin can see the “active” lines and act on them.   See:</p>
<p dir="auto"><a href="https://www.scintilla.org/ScintillaDoc.html#SCI_GETFIRSTVISIBLELINE" rel="nofollow ugc">SCI_GETFIRSTVISIBLELINE</a><br />
<a href="https://www.scintilla.org/ScintillaDoc.html#SCI_LINESONSCREEN" rel="nofollow ugc">SCI_LINESONSCREEN</a></p>
<p dir="auto">Cheers.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/73141</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/73141</guid><dc:creator><![CDATA[Michael Vincent]]></dc:creator><pubDate>Fri, 21 Jan 2022 20:26:27 GMT</pubDate></item><item><title><![CDATA[Reply to [c#] Adding a custom styler or lexer in C# for scintilla&#x2F;notepad++ on Fri, 21 Jan 2022 20:21:14 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: peterjones">@<bdi>peterjones</bdi></a> said in <a href="/post/73137">[c#] Adding a custom styler or lexer in C# for scintilla/notepad++</a>:</p>
<blockquote>
<p dir="auto">Maybe just to make it harder to accidentally change the default extension? (To avoid a billion “why don’t .cpp files get highlighted with the C++ language highlighting?” to find out that the user had intentionally or accidentally edited the default extension list.)</p>
</blockquote>
<p dir="auto">Sounds like a good explanation. The actual problem is that the lexer is too slow on large csv files, which seems to freeze Notepad++ when opening like &gt;10MB files. But the <code>Lex()</code> function implements the syntax highlighting and Notepad calls this function, including the start/end parameters.</p>
<p dir="auto">So if I understand correctly Notepad++ takes care of efficiently calling this syntax highlighting function (see also this <a href="https://github.com/notepad-plus-plus/notepad-plus-plus/blob/master/scintilla/doc/ScintillaHistory.html#L2682" rel="nofollow ugc">January 2016 update</a>). afaik the custom lexer doesn’t need to implement extra functions or settings to ensure that the rendering is only done to the visible parts, is that correct?</p>
<p dir="auto">If not, how can I ensure that the custom lexer doesn’t apply syntax highlighting to the entire file at once from beginning to end, but instead only renders colors for the visible area? Ideally the user scrolls through the file, and the colors are incrementally applied to the visible areas, is that possible?</p>
<p dir="auto"><img src="/assets/uploads/files/1642796311133-csv_lint_lex_question.png" alt="csv_lint_lex_question.png" class=" img-fluid img-markdown" /></p>
]]></description><link>https://community.notepad-plus-plus.org/post/73140</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/73140</guid><dc:creator><![CDATA[Bas de Reuver]]></dc:creator><pubDate>Fri, 21 Jan 2022 20:21:14 GMT</pubDate></item><item><title><![CDATA[Reply to [c#] Adding a custom styler or lexer in C# for scintilla&#x2F;notepad++ on Fri, 21 Jan 2022 18:41:38 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bas-de-reuver" aria-label="Profile: bas-de-reuver">@<bdi>bas-de-reuver</bdi></a> said in <a href="/post/73136">[c#] Adding a custom styler or lexer in C# for scintilla/notepad++</a>:</p>
<blockquote>
<p dir="auto">So why is the Default ext. textbox read-only? When users want to disable the always automatically applying colors to .csv files (so make ext. empty), they have to go to the settings XML file and change it there.</p>
</blockquote>
<p dir="auto">Agree with <a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: PeterJones">@<bdi>PeterJones</bdi></a> , not sure why, but there is a “workaround”.  I set <code>ext=""</code> in the  ‘CSVLint.xml’ file and the in my Style Configurator window, the “Default ext.” is blank, so I add <code>csv</code> in the “User ext.” text box.  Now I can enable/disable auto-lexing by just editing the editable (non-read-only) “User ext.” text box.</p>
<p dir="auto">I believe that is the desired <em><strong>behavior</strong></em>, if not the desired <em>implementation</em> to achieve it.</p>
<p dir="auto">Cheers.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/73138</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/73138</guid><dc:creator><![CDATA[Michael Vincent]]></dc:creator><pubDate>Fri, 21 Jan 2022 18:41:38 GMT</pubDate></item><item><title><![CDATA[Reply to [c#] Adding a custom styler or lexer in C# for scintilla&#x2F;notepad++ on Fri, 21 Jan 2022 18:28:38 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bas-de-reuver" aria-label="Profile: bas-de-reuver">@<bdi>bas-de-reuver</bdi></a> said in <a href="/post/73136">[c#] Adding a custom styler or lexer in C# for scintilla/notepad++</a>:</p>
<blockquote>
<p dir="auto">So why is the Default ext. textbox read-only? When users want to disable the always automatically applying colors to .csv files (so make ext. empty), they have to go to the settings XML file and change it there.</p>
</blockquote>
<p dir="auto">This is just a guess (how can we be expected to know the “why”?): Maybe just to make it harder to accidentally change the default extension? (To avoid a billion “why don’t <code>.cpp</code> files get highlighted with the C++ language highlighting?” to find out that the user had intentionally or accidentally edited the default extension list.)</p>
<p dir="auto">Or maybe because the developer’s intention was that default extensions would always be handled, and the user-extension was thus enough of a feature for adding new file types, but hadn’t considered wanting to remove a filetype by a “normal” user.</p>
<p dir="auto">But maybe there is a technical reason – a guess for a possible technical reason: maybe there’s some internal variables that are only setup during the initial launch of Notepad++, which include looking at those default extensions for each lexer, and the developers didn’t want to re-work the logic to allow those to change every time that the dialog is edited.</p>
<p dir="auto">Also, on a lexer-plugin like the CSVLint, which seems to be using a separate XML file compared to the builtin <code>langs.xml</code>, there might be the added technical hurdle of knowing whether to edit <code>langs.xml</code> or some lexer-plugin-specific file.</p>
<p dir="auto">It probably wouldn’t hurt to make it a feature request to change that from read-only to user-editable (with the explanation that it’s hard to delete extensions)… but don’t be surprised if it never gets implemented, because it may not be as simple as “just make the box not read-only”.  If you do, please link us to that feature request.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/73137</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/73137</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Fri, 21 Jan 2022 18:28:38 GMT</pubDate></item><item><title><![CDATA[Reply to [c#] Adding a custom styler or lexer in C# for scintilla&#x2F;notepad++ on Fri, 21 Jan 2022 18:06:15 GMT]]></title><description><![CDATA[<p dir="auto">A custom lexer can automatically apply the syntax highlighting to files with a certain extension. This setting is visible in the menu under <code>Settings &gt; Style Configuration</code> and then the textbox “Default ext.”.</p>
<p dir="auto">However, the extension textbox is readonly, user cannot change this value.</p>
<p dir="auto"><img src="/assets/uploads/files/1642788300073-npp_style_configurator_default_ext.png" alt="npp_style_configurator_default_ext.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">So why is the Default ext. textbox read-only? When users want to disable the always automatically applying colors to <code>.csv</code> files (so make ext. empty), they have to go to the settings XML file and change it there.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/73136</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/73136</guid><dc:creator><![CDATA[Bas de Reuver]]></dc:creator><pubDate>Fri, 21 Jan 2022 18:06:15 GMT</pubDate></item><item><title><![CDATA[Reply to [c#] Adding a custom styler or lexer in C# for scintilla&#x2F;notepad++ on Fri, 29 Oct 2021 22:57:28 GMT]]></title><description><![CDATA[<p dir="auto">Another question about the colors. For a custom lexer you also have to distribute a color settings xml file.<br />
It’s easiest to generate it at first time start-up, see <a href="https://community.notepad-plus-plus.org/post/70972">this post</a>.</p>
<p dir="auto">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 <code>Settings &gt; Style Configurator</code>, but I would like to provide a few color presets that look pretty decent, see screenshot below and the <a href="https://github.com/BdR76/CSVLint/blob/master/config/CSVLint.xml" rel="nofollow ugc">LexerStyles xml</a>. 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.</p>
<p dir="auto">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.</p>
<p dir="auto"><img src="/assets/uploads/files/1635547767671-csvlint_color_test2.png" alt="csvlint_color_test2.png" class=" img-fluid img-markdown" /></p>
]]></description><link>https://community.notepad-plus-plus.org/post/71013</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/71013</guid><dc:creator><![CDATA[Bas de Reuver]]></dc:creator><pubDate>Fri, 29 Oct 2021 22:57:28 GMT</pubDate></item><item><title><![CDATA[Reply to [c#] Adding a custom styler or lexer in C# for scintilla&#x2F;notepad++ on Thu, 28 Oct 2021 23:31:35 GMT]]></title><description><![CDATA[<p dir="auto">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.</p>
<pre><code>        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);
</code></pre>
<p dir="auto">The documentation also mentions <code>SC_ELEMENT_CARET_LINE_BACK</code>  but that one is not available in the <code>Scintilla_ifaces</code> file.<br />
Any idea how to make the caret line tansparant so that you can also see the background colors of a selected line?</p>
]]></description><link>https://community.notepad-plus-plus.org/post/70994</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/70994</guid><dc:creator><![CDATA[Bas de Reuver]]></dc:creator><pubDate>Thu, 28 Oct 2021 23:31:35 GMT</pubDate></item><item><title><![CDATA[Reply to [c#] Adding a custom styler or lexer in C# for scintilla&#x2F;notepad++ on Tue, 28 Sep 2021 20:53:27 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bas-de-reuver" aria-label="Profile: Bas-de-Reuver">@<bdi>Bas-de-Reuver</bdi></a> - <a href="https://www.scintilla.org/ScintillaDoc.html#SCI_SETCARETLINEBACK" rel="nofollow ugc">https://www.scintilla.org/ScintillaDoc.html#SCI_SETCARETLINEBACK</a></p>
]]></description><link>https://community.notepad-plus-plus.org/post/70115</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/70115</guid><dc:creator><![CDATA[Ekopalypse]]></dc:creator><pubDate>Tue, 28 Sep 2021 20:53:27 GMT</pubDate></item><item><title><![CDATA[Reply to [c#] Adding a custom styler or lexer in C# for scintilla&#x2F;notepad++ on Tue, 28 Sep 2021 20:52:37 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bas-de-reuver" aria-label="Profile: Bas-de-Reuver">@<bdi>Bas-de-Reuver</bdi></a></p>
<p dir="auto">oops - did I link the wrong function, sorry. But there is one for the current selected line.<br />
Let me check.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/70114</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/70114</guid><dc:creator><![CDATA[Ekopalypse]]></dc:creator><pubDate>Tue, 28 Sep 2021 20:52:37 GMT</pubDate></item></channel></rss>