<?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[Define custom syntax hilighting with Pythonscript plugin]]></title><description><![CDATA[<p dir="auto">I want to try сustomize the syntax colors using the Pythonscript plugin.<br />
I’ve looked into examples by <a class="plugin-mentions-user plugin-mentions-a" href="/user/claudia-frank" aria-label="Profile: Claudia-Frank">@<bdi>Claudia-Frank</bdi></a> here:<br />
<a href="https://notepad-plus-plus.org/community/topic/16088/does-the-udl-miss-the-ablity-to-recognize-methods-and-classes" rel="nofollow ugc">custom colors for methods</a></p>
<p dir="auto">One thing I want to know: is it possible to make the code more ‘procedural-style’?</p>
<p dir="auto">In those examples I am trying to understand what all those <code>class</code>, <code>__metaclass__</code>, etc.<br />
things are and how it all works together.<br />
Looks really hacky, to me at least. I am quite proficient with programming<br />
but when I see a word <code>class</code>, I already get some kind of disturbance.</p>
<p dir="auto">So the question is basically - is involving classes and method tweaking the only<br />
approach in this case?</p>
<p dir="auto">I am thinking about the algorithm and how would I go about colorising<br />
characters and it comes down to such pseudo-program:</p>
<ol>
<li>Take the indexes of start and end of visible chunk -<br />
no problem, I can do it.</li>
<li>Find the indexes of needed characters sequence -<br />
and store it in say “group 1”. No problem so far.</li>
<li>Do same for some other searches, store as “group 2”,<br />
“3”, … etc. So end up with N groups of indexes.</li>
<li>In a loop, take each index group and mark with its own style , i.e.<br />
group i -&gt; style i</li>
</ol>
<p dir="auto">It seems everything is super-simple and I can cope with each step easily.<br />
But is it possible to make the above steps into working example without<br />
going into PhD-level meta-programming techniques?</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/16216/define-custom-syntax-hilighting-with-pythonscript-plugin</link><generator>RSS for Node</generator><lastBuildDate>Sun, 10 May 2026 05:27:23 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/16216.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 25 Aug 2018 15:30:53 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Define custom syntax hilighting with Pythonscript plugin on Fri, 31 Aug 2018 23:08:08 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/claudia-frank" aria-label="Profile: Claudia-Frank">@<bdi>Claudia-Frank</bdi></a><br />
Thanks  for the input!</p>
<p dir="auto">I got to do a lot of experimenting with it.<br />
What comes to my mind - I could use some external libararies for<br />
the lexical analysis, but then I have another task - to import and use 3d party<br />
libraries with the PS plugin…  but anyway, it seems that is not necessary – I have<br />
regex and could loop over bytes as well, so it is not main problem here.</p>
<p dir="auto">All in all, sounds like an interesting challenge.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/34529</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/34529</guid><dc:creator><![CDATA[Mikhail V]]></dc:creator><pubDate>Fri, 31 Aug 2018 23:08:08 GMT</pubDate></item><item><title><![CDATA[Reply to Define custom syntax hilighting with Pythonscript plugin on Mon, 27 Aug 2018 00:42:45 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mikhail-v" aria-label="Profile: Mikhail-V">@<bdi>Mikhail-V</bdi></a></p>
<p dir="auto">I have uploaded a proof-of-concept regex based lexer <a href="https://gist.github.com/ClaudiaFrank/4b4327d1b503004da3a991fc3b8374e5" rel="nofollow ugc">here</a>.</p>
<p dir="auto">Cheers<br />
Claudia</p>
]]></description><link>https://community.notepad-plus-plus.org/post/34349</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/34349</guid><dc:creator><![CDATA[Claudia Frank]]></dc:creator><pubDate>Mon, 27 Aug 2018 00:42:45 GMT</pubDate></item><item><title><![CDATA[Reply to Define custom syntax hilighting with Pythonscript plugin on Mon, 27 Aug 2018 00:31:55 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mikhail-v" aria-label="Profile: Mikhail-V">@<bdi>Mikhail-V</bdi></a></p>
<blockquote>
<p dir="auto">I hope it does not look like I want to make fun of you coding style.</p>
</blockquote>
<p dir="auto">No problem, I haven’t understood it that way anyway. :-)<br />
But I hope that I do get critics when I post something which could/should<br />
be coded differently. For example like guy038 does when I post regexes which<br />
can be simplified or aren’t correct at all.<br />
I’m still learning new things every day. If you would have asked 6 month ago<br />
whether it is possible to have two different lexer acting on the same documented<br />
I would have posted NO, nowadays I know better or I should say, nowadays I know a<br />
way around that problem.</p>
<blockquote>
<p dir="auto">So I was able to run that example in the linked post.<br />
Though I can run only on the new Npp version with the latest Pythonscript plugin.<br />
I suspect you have some knowledge of non-documented features ;)</p>
</blockquote>
<p dir="auto">I hope I haven’t used undocumented features but yes pythonscript &gt; 1.0.8 is needed<br />
as we have added notepad functions like notepad.getLanguageName(notepad.getLangType())<br />
only recently. I should have made clear - thx for pointing out.</p>
<p dir="auto">Before answering the two question let me clarify the two possible ways scintilla supports<br />
to colorize the documents from my understanding about it.<br />
The first one, used from the beginning of scintilla is styling and later there were indicators added.<br />
The idea of having indicators is totally different to styling and, as far as I understand, it wasn’t<br />
intended to use it as another way of styling. I just misuse it as some kind of light-way styler.<br />
And yes, there are differences, when using styler and indicators.<br />
A lexer(styler) get the information which part of the document needs to be restyled, indicators don’t get this info.<br />
When using styling you have full control over every piece of styles, like different font,<br />
with indicators you only can modify the foreground and background color<br />
(ignoring the different shapes you can put around of text for the moment).<br />
But because they are handled independently they can be used together and from my understanding indicators are<br />
the only safe way to enhance an existing lexer.</p>
<blockquote>
<p dir="auto">Can I apply a styler to specific range? I make<br />
emphasis on “styler” because in your examples you deal only with<br />
“indicator” which only changes the color, but I want to change font and<br />
size of the characters if it is possible.</p>
</blockquote>
<p dir="auto">You can by using styling functions but with the price that you have to write your own lexer.<br />
Means you cannot use it together with an existing lexer.</p>
<blockquote>
<p dir="auto">Can I get the information about currently applied styler or<br />
any info about the lexer state for the character at specific index?<br />
Styles can be retrieved e.g. editor.getStyleAt function.<br />
You cannot get an lexer state, in terms of a builtin lexer or an udl lexer.</p>
</blockquote>
<blockquote>
<p dir="auto">SCI_GETLINESTATE(int line) → int<br />
As well as the 8 bits of lexical state stored for each character there<br />
is also an integer stored for each line.<br />
This mentions some “state for each character”. ?? But I can’t find any other calls<br />
that refers to this state. I guess the active lexer should store this useful info, but how to read it?</p>
</blockquote>
<p dir="auto">My understanding is that this is stored by scintilla internally instead of the lexer but haven’t really checked the sources.<br />
The additional linestate functions have been introduced to provide a way to the lexer to have sub-lexers working.<br />
Like in the html lexer where it is needed to have different lines colored different depending on which sub-lexer (php, js, html …) is used.</p>
<blockquote>
<p dir="auto">I am just trying to understand how plausible is the idea of writing a fully<br />
custom highlighting with the PS plugin, and I am still in doubt.</p>
</blockquote>
<p dir="auto">I would say it depends - a full python lexer is always slower like an builtin or udl lexer,<br />
but nowadays with such computing power it might be possible that you do not even notice the difference<br />
if the documents which should be colored are only thousand, and not millions, of lines.<br />
Writing your own lexer gives you the full control which means you can possibly do what a builtin or udl lexer can’t do<br />
like having a regex based lexer.<br />
Whether it makes sense or not is always up to the one who thinks about a possible solution.</p>
<p dir="auto">I hope I was able to demystify this a little bit, if not, let me know.</p>
<p dir="auto">Cheers<br />
Claudia</p>
]]></description><link>https://community.notepad-plus-plus.org/post/34348</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/34348</guid><dc:creator><![CDATA[Claudia Frank]]></dc:creator><pubDate>Mon, 27 Aug 2018 00:31:55 GMT</pubDate></item><item><title><![CDATA[Reply to Define custom syntax hilighting with Pythonscript plugin on Sun, 26 Aug 2018 23:23:34 GMT]]></title><description><![CDATA[<p dir="auto">Follow-up: regarding question #1, there are related <a href="https://www.scintilla.org/ScintillaDoc.html#Styling" rel="nofollow ugc">Scintilla API calls</a>:</p>
<pre><code class="language-z">SCI_GETENDSTYLED → position
SCI_STARTSTYLING(int start, int unused)
SCI_SETSTYLING(int length, int style)
SCI_SETSTYLINGEX(int length, const char *styles)
SCI_SETIDLESTYLING(int idleStyling)
SCI_GETIDLESTYLING → int
SCI_SETLINESTATE(int line, int state)
SCI_GETLINESTATE(int line) → int
SCI_GETMAXLINESTATE → int
</code></pre>
<p dir="auto">So I suggest this might work to set the styles somehow.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/34346</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/34346</guid><dc:creator><![CDATA[Mikhail V]]></dc:creator><pubDate>Sun, 26 Aug 2018 23:23:34 GMT</pubDate></item><item><title><![CDATA[Reply to Define custom syntax hilighting with Pythonscript plugin on Sun, 26 Aug 2018 23:08:49 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/claudia-frank" aria-label="Profile: Claudia-Frank">@<bdi>Claudia-Frank</bdi></a> said:</p>
<blockquote>
<p dir="auto">I’m confident that the classes can be rewritten to use a more procedural-style as you said.<br />
There are two reasons why I used classes here.</p>
</blockquote>
<p dir="auto">Thanks for clarification :) I hope it does not look like I want to make fun of<br />
you coding style. It is just my pet-peeve (OOP).</p>
<p dir="auto">So I was able to run that example in the linked post.<br />
Though I can  run only on the new Npp version with the latest Pythonscript plugin.<br />
I suspect you have some knowledge of non-documented features ;)</p>
<p dir="auto">So I am still trying to understand the <strong>possibilities</strong> in the first place.<br />
Earlier you have written about possibilities:</p>
<blockquote>
<p dir="auto">a) writing a lexer entirely with python script<br />
b) writing an “xml-linter” with python script</p>
</blockquote>
<p dir="auto">This is taken out of the context but seems you got some experience.<br />
So maybe you know the answer for these 2 questions:</p>
<ol>
<li>
<p dir="auto">Can I apply a <strong>styler</strong> to specific range? I make<br />
emphasis on “styler” because in your examples you deal only with<br />
“indicator” which only changes the color, but I want to change <strong>font</strong> and<br />
size of the characters if it is possible.</p>
</li>
<li>
<p dir="auto">Can I get the information about currently applied styler or<br />
any info about the lexer state for the character at specific index?</p>
</li>
</ol>
<p dir="auto">In Scintilla <a href="https://www.scintilla.org/ScintillaDoc.html#Styling" rel="nofollow ugc">Documentation</a> I find this:</p>
<pre><code class="language-z">SCI_GETLINESTATE(int line) → int
As well as the 8 bits of lexical state stored for each character there 
is also an integer stored for each line. 
</code></pre>
<p dir="auto">This mentions some “state for each character”. ?? But I can’t find any other calls<br />
that refers to this state. I guess the active lexer should store this useful info, but how to read it?</p>
<p dir="auto">I am just trying to understand how plausible is the idea of writing a fully<br />
custom highlighting with the PS plugin, and I am still in doubt.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/34345</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/34345</guid><dc:creator><![CDATA[Mikhail V]]></dc:creator><pubDate>Sun, 26 Aug 2018 23:08:49 GMT</pubDate></item><item><title><![CDATA[Reply to Define custom syntax hilighting with Pythonscript plugin on Sat, 25 Aug 2018 21:57:19 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mikhail-v" aria-label="Profile: Mikhail-V">@<bdi>Mikhail-V</bdi></a></p>
<p dir="auto">I’m confident that the classes can be rewritten to use a more procedural-style as you said.</p>
<p dir="auto">There are two reasons why I used classes here.</p>
<p dir="auto">The first one involves the metaclass<br />
As the script is using callbacks and the intention is to use this script<br />
on several documents with the possibility to reassign a different lexer<br />
and if needed, reassign this “pseudo”-lexer I wanted to make sure that<br />
I do register the callback function only once - otherwise I do get<br />
the callback function called multiple times and this already explains<br />
what this metaclass feature does - it ensures that you always get the same<br />
object when calling EnhancedUDLLexer.</p>
<p dir="auto">The second reason is similar to the first one - make sure that the variables/functions<br />
used are not overwritten by another (or the same) script as it would break the script immediately.</p>
<p dir="auto">So, if you plan to use such a script on multiple documents then you need to solve this issue<br />
otherwise you might see unexpected behavior.</p>
<p dir="auto">Cheers<br />
Claudia</p>
]]></description><link>https://community.notepad-plus-plus.org/post/34320</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/34320</guid><dc:creator><![CDATA[Claudia Frank]]></dc:creator><pubDate>Sat, 25 Aug 2018 21:57:19 GMT</pubDate></item><item><title><![CDATA[Reply to Define custom syntax hilighting with Pythonscript plugin on Sat, 25 Aug 2018 15:51:24 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/scott-sumner" aria-label="Profile: Scott-Sumner">@<bdi>Scott-Sumner</bdi></a> said:</p>
<blockquote>
<p dir="auto">Well-worded…is the feeling similar to motion sickness?  :-D</p>
</blockquote>
<p dir="auto">Yes similar to that :)<br />
Or for example a feeling when I have to fill in an application form<br />
which should be easy, but the wording of questions gets  irritating.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/34313</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/34313</guid><dc:creator><![CDATA[Mikhail V]]></dc:creator><pubDate>Sat, 25 Aug 2018 15:51:24 GMT</pubDate></item><item><title><![CDATA[Reply to Define custom syntax hilighting with Pythonscript plugin on Sat, 25 Aug 2018 15:36:44 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mikhail-v" aria-label="Profile: Mikhail-V">@<bdi>Mikhail-V</bdi></a> said:</p>
<blockquote>
<p dir="auto">but when I see a word class, I already get some kind of disturbance</p>
</blockquote>
<p dir="auto">Well-worded…is the feeling similar to motion sickness?  :-D</p>
]]></description><link>https://community.notepad-plus-plus.org/post/34312</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/34312</guid><dc:creator><![CDATA[Scott Sumner]]></dc:creator><pubDate>Sat, 25 Aug 2018 15:36:44 GMT</pubDate></item></channel></rss>