<?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[Poorman regex based styler&#x2F;lexer]]></title><description><![CDATA[<p dir="auto">Recently there was a request by a coworker, to have a python script<br />
which would color a monitored log automatically based on regular expressions.<br />
Script should allow to define multiple regexes and should allow to<br />
monitor different files identified by its extension.</p>
<p dir="auto">Well, this is what came out.<br />
Maybe it is useful for others too.</p>
<p dir="auto">The critical parts are in the configuration area and the first function init_scintilla.</p>
<p dir="auto">Here are the steps which needs to be done if one wants to extend it with another regex.</p>
<ol>
<li>create a new style id like STYLE_INFO and assign the next free integer</li>
<li>define a new color like STYLE_INFO_FOREGROUND = (255,255,255).</li>
<li>define a new regex like REGEX_DICT[‘STYLE_INFO’] = ‘(?-s).<em>INFO:\d{4}\s-.</em>’<br />
The critical part here is that the dictionary key ‘STYLE_INFO’ needs to match the id<br />
you choose in step 1</li>
<li>add the appropriate function(s) to init_scintilla - done.</li>
</ol>
<p dir="auto">This example should result in the following code</p>
<pre><code>STYLE_DEFAULT               = 0 # don't change this
STYLE_WARNINGS              = 1
STYLE_ERRORS                = 2
STYLE_INFO                  = 3

STYLE_DEFAULT_FOREGROUND    = (200,200,200)     # grey
STYLE_DEFAULT_BACKGROUND    = (30,30,30)        # kind of black
STYLE_WARNINGS_FOREGROUND   = (255,255,0)       # yellow
STYLE_ERRORS_FOREGROUND     = (255,0,0)         # red
STYLE_INFO_FOREGROUND       = (255,255,255)

REGEX_DICT = OrderedDict()  # to be sure that regex get called in the same order each time
REGEX_DICT['STYLE_WARNINGS']      = '(?-s).*WARNING:\d{3}\s\-.*'
REGEX_DICT['STYLE_ERRORS']        = '(?-s).*ERROR:\d{4}\s\-.*'
REGEX_DICT['STYLE_INFO']          = '(?-s).*INFO:\d{4}\s\-.*'
    
and

def init_scintilla():
    # this needs to match the definitions in configuration area
    editor.styleSetFore(STYLE_DEFAULT,   STYLE_DEFAULT_FOREGROUND)
    editor.styleSetBack(STYLE_DEFAULT,   STYLE_DEFAULT_BACKGROUND)   
    editor.styleSetFore(STYLE_WARNINGS,  STYLE_WARNINGS_FOREGROUND)  
    editor.styleSetFore(STYLE_ERRORS,    STYLE_ERRORS_FOREGROUND)  
    editor.styleSetFore(STYLE_INFO,      STYLE_INFO_FOREGROUND)  
</code></pre>
<p dir="auto">If one wants to add other file extensions to it modify the list REGISTERED_FILE_EXTENSIONS.<br />
Let’s say, the file extensions .dmp_log should be add then the list needs to look like this</p>
<pre><code>REGISTERED_FILE_EXTENSIONS  = ['.log','.dmp_log']
</code></pre>
<p dir="auto">There is also a boolean USE_AS_DEFAULT_LANGUAGE which could be set to True if<br />
the ‘new ?’ docs should be colored as well.</p>
<p dir="auto">Ok, what else - the order how the REGEX_DICT is created is the order how the different<br />
regexes get called. Why is this important, because if one defines an overlapping results,<br />
means eg. regex 1 colors the term <em><strong>error file copy failed</strong></em> in blue and another regex,<br />
called later, is looking for word failed which it would color in red than it would result<br />
in <em><strong>error file copy</strong></em> being in blue and <em><strong>failed</strong></em> in red.</p>
<p dir="auto">And, if you gonna play with different colors and regexes while testing,<br />
you may notice that “old” color doesn’t get removed if it isn’t part of the new match.<br />
This is because the script don’t uses the styleClearAll method which normally should be<br />
called on each start first. But because one might use themed npp it could result in<br />
undesirable result - so to workaround while testing it would be best to stop the script<br />
and to activate another tab, in the view where the file which needs to be colored is,<br />
and reactivate the file. Now you see that all colors are gone. Restart script.<br />
And, obviously, you cannot use this script for documents which are already colored by<br />
a different lexer. That’s it - I guess.</p>
<p dir="auto">As always, the first run of the script starts it whereas the next call would stop it.</p>
<p dir="auto">Questions or suggestions? Feel free to do so.</p>
<p dir="auto">Cheers<br />
Claudia</p>
<pre><code>import re, os
from collections import OrderedDict

# ---------------------------- configuration area -----------------------------

# stlye definitions - changes here need to match setup calls in init_scintilla()
STYLE_DEFAULT               = 0 # don't change this
STYLE_WARNINGS              = 1
STYLE_ERRORS                = 2

STYLE_DEFAULT_FOREGROUND    = (200,200,200)     # grey
STYLE_DEFAULT_BACKGROUND    = (30,30,30)        # kind of black
STYLE_WARNINGS_FOREGROUND   = (128,255,0)       # yellow
STYLE_ERRORS_FOREGROUND     = (255,0,0)         # red

REGISTERED_FILE_EXTENSIONS  = ['.log']
USE_AS_DEFAULT_LANGUAGE     = False

REGEX_DICT = OrderedDict()  # to be sure that regex get called in the same order each time
REGEX_DICT['STYLE_WARNINGS']      = '(?-s).*WARNING:\d{3}\s\-.*'
REGEX_DICT['STYLE_ERRORS']        = '(?-s).*ERROR:\d{4}\s\-.*'

# -------------------------- configuration area end ---------------------------

CUSTOM_STYLER_IS_RUNNING = globals().get('CUSTOM_STYLER_IS_RUNNING', False) 
LIST_OF_FIRST_RUN_DONE = []
DOC_NEEDS_TO_BE_COLORED = False

def init_scintilla():
    # this needs to match the definitions in configuration area
    editor.styleSetFore(STYLE_DEFAULT,   STYLE_DEFAULT_FOREGROUND)
    editor.styleSetBack(STYLE_DEFAULT,   STYLE_DEFAULT_BACKGROUND)   
    editor.styleSetFore(STYLE_WARNINGS,  STYLE_WARNINGS_FOREGROUND)  
    editor.styleSetFore(STYLE_ERRORS,    STYLE_ERRORS_FOREGROUND)  

def custom_lexer(start_pos, end_pos):
    for k in REGEX_DICT.keys():
        matches = []
        editor.research(REGEX_DICT[k], lambda m: matches.append(m.span()), 0, start_pos, end_pos) 
        for match in matches:
            # console.write('match:{} - {}\n'.format(match, editor.getTextRange(*match)))
            editor.startStyling(match[0],31)
            editor.setStyling(match[1]-match[0], eval(k))

def this_doc_should_be_styled():
    global DOC_NEEDS_TO_BE_COLORED
    current_file = notepad.getCurrentFilename()
    _file, _ext = os.path.splitext(current_file)
    if _ext in REGISTERED_FILE_EXTENSIONS or (USE_AS_DEFAULT_LANGUAGE and _file.startswith('new ')):
        DOC_NEEDS_TO_BE_COLORED = True
    else:
        DOC_NEEDS_TO_BE_COLORED = False
    return DOC_NEEDS_TO_BE_COLORED

def get_visible_area():   
    first_visible_line = editor.getFirstVisibleLine()
    last_visible_line = editor.linesOnScreen() + first_visible_line
    start_pos = editor.positionFromLine(first_visible_line)
    end_pos = editor.positionFromLine(last_visible_line)
    return start_pos, end_pos

def callback_BUFFERACTIVATED(args): 
    if this_doc_should_be_styled():
        init_scintilla()
        if args['bufferID'] not in LIST_OF_FIRST_RUN_DONE:
            custom_lexer(*get_visible_area())
            LIST_OF_FIRST_RUN_DONE.append(args['bufferID'])

def callback_UPDATEUI(args):
    if DOC_NEEDS_TO_BE_COLORED and args['updated'] &gt;= 4:
        custom_lexer(*get_visible_area())

def main():
    global CUSTOM_STYLER_IS_RUNNING
    if CUSTOM_STYLER_IS_RUNNING:
        notepad.clearCallbacks([NOTIFICATION.BUFFERACTIVATED])
        editor.clearCallbacks([SCINTILLANOTIFICATION.UPDATEUI])
        CUSTOM_STYLER_IS_RUNNING = False
    else:
        if this_doc_should_be_styled():
            init_scintilla()
            custom_lexer(*get_visible_area())
        notepad.callback(callback_BUFFERACTIVATED, [NOTIFICATION.BUFFERACTIVATED])
        editor.callback(callback_UPDATEUI, [SCINTILLANOTIFICATION.UPDATEUI])
        CUSTOM_STYLER_IS_RUNNING = True

main()
</code></pre>
]]></description><link>https://community.notepad-plus-plus.org/topic/13183/poorman-regex-based-styler-lexer</link><generator>RSS for Node</generator><lastBuildDate>Fri, 12 Jun 2026 18:00:45 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/13183.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 27 Jan 2017 23:27:27 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Poorman regex based styler&#x2F;lexer on Thu, 04 May 2017 20:28:55 GMT]]></title><description><![CDATA[<p dir="auto">Hi, <a class="plugin-mentions-user plugin-mentions-a" href="/user/claudia-frank" aria-label="Profile: claudia-frank">@<bdi>claudia-frank</bdi></a>,</p>
<p dir="auto">Oh yes, I just forgot that your script acts, exactly, like your <strong><a href="http://RegexTesterPro.py" rel="nofollow ugc">RegexTesterPro.py</a></strong> script. This just proves that I haven’t studied your excellent <strong>regex’s tester</strong> script, since a <strong>long</strong> time !!</p>
<p dir="auto">Concerning the <strong>second</strong> point, I do understand your explanations. To be honest, right after <strong>changing</strong> the extension to <strong>.py</strong> and before restarting your script, I already thought that this change could lead to some <strong>unpredictable</strong> results :-((</p>
<p dir="auto">Cheers,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/24076</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/24076</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Thu, 04 May 2017 20:28:55 GMT</pubDate></item><item><title><![CDATA[Reply to Poorman regex based styler&#x2F;lexer on Thu, 04 May 2017 19:31:25 GMT]]></title><description><![CDATA[<p dir="auto">Hi Guy,</p>
<p dir="auto">rerun two times because I implemented my start/stop logic as in most of my scripts.<br />
See main section</p>
<pre><code>def main():
    global CUSTOM_STYLER_IS_RUNNING
    if CUSTOM_STYLER_IS_RUNNING:
        notepad.clearCallbacks([NOTIFICATION.BUFFERACTIVATED])
        editor.clearCallbacks([SCINTILLANOTIFICATION.UPDATEUI])
        CUSTOM_STYLER_IS_RUNNING = False
    else:
        if this_doc_should_be_styled():
            init_scintilla()
            custom_lexer(*get_visible_area())
        notepad.callback(callback_BUFFERACTIVATED, [NOTIFICATION.BUFFERACTIVATED])
        editor.callbackSync(callback_UPDATEUI, [SCINTILLANOTIFICATION.UPDATEUI])
        CUSTOM_STYLER_IS_RUNNING = True
</code></pre>
<p dir="auto">If CUSTOM_STYLER_IS_RUNNING it clears the callbacks so no further coloring,<br />
if it is not running it registers the callbacks to make coloring happen.</p>
<p dir="auto">Concerning the renaming. This script is <strong>NOT</strong> a real lexer as it doesn’t register itself<br />
to be a lexer by using container object, so it is critical that you choose an extension which hasn’t<br />
a lexer assigned, which by the way means, that this script can’t be used as you normally do have<br />
the python lexer active.</p>
<p dir="auto">Regarding the active line, yes, it gets overwritten by the active line style.</p>
<p dir="auto">In general, scintilla doesn’t provide many functions when it comes to column based coloring,<br />
basically the edge line is the only one I’ve encountered so far. Maybe a solution might be to<br />
draw to window context itself but this would mean one have to handle window resizing messages,<br />
themes etc…</p>
<p dir="auto">Cheers<br />
Claudia</p>
]]></description><link>https://community.notepad-plus-plus.org/post/24071</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/24071</guid><dc:creator><![CDATA[Claudia Frank]]></dc:creator><pubDate>Thu, 04 May 2017 19:31:25 GMT</pubDate></item><item><title><![CDATA[Reply to Poorman regex based styler&#x2F;lexer on Thu, 04 May 2017 18:58:19 GMT]]></title><description><![CDATA[<p dir="auto">Hi, <a class="plugin-mentions-user plugin-mentions-a" href="/user/claudia-frank" aria-label="Profile: claudia-frank">@<bdi>claudia-frank</bdi></a>,</p>
<p dir="auto">When I, first, saw the <a class="plugin-mentions-user plugin-mentions-a" href="/user/jcrmatos" aria-label="Profile: jcrmatos">@<bdi>jcrmatos</bdi></a> post, as the address, below :</p>
<p dir="auto"><a href="https://notepad-plus-plus.org/community/topic/13753/suggestion-please-consider-adding-a-secondary-vertical-edge/1" rel="nofollow ugc">https://notepad-plus-plus.org/community/topic/13753/suggestion-please-consider-adding-a-secondary-vertical-edge/1</a></p>
<p dir="auto">I thought that it should have been possible to use your <strong>great</strong> script to visualize the <strong>gap</strong> between column <strong>73</strong> and <strong>79</strong>, colouring the background. So, <a class="plugin-mentions-user plugin-mentions-a" href="/user/jcrmatos" aria-label="Profile: jcrmatos">@<bdi>jcrmatos</bdi></a> could easily see, at once, the <strong>two</strong> limits, located at columns <strong>72</strong> and <strong>79</strong> !</p>
<p dir="auto">Then, from your <strong>original</strong> script, I built the script, below, which highlights, in <strong>pale blue</strong>, the columns between the columns <strong>73</strong> and <strong>79</strong> :</p>
<pre><code class="language-py">import re, os
from collections import OrderedDict

# ---------------------------- configuration area -----------------------------

# style definitions - changes here need to match setup calls in init_scintilla()
STYLE_DEFAULT               = 0 # don't change this
STYLE_EDGES                 = 1

STYLE_DEFAULT_FOREGROUND    = (0,0,0)           # Black
STYLE_DEFAULT_BACKGROUND    = (255,255,255)     # White
STYLE_EDGES_BACKGROUND      = (208,240,255)     # Pale Blue ( &amp;xD0 , &amp;xF0 , &amp;xFF )

REGISTERED_FILE_EXTENSIONS  = ['.log']
USE_AS_DEFAULT_LANGUAGE     = False

REGEX_DICT = OrderedDict()  # to be sure that regex get called in the same order each time
REGEX_DICT['STYLE_EDGES']  = '(?-s)^.{72}\K.{1,7}'

# -------------------------- configuration area end ---------------------------

CUSTOM_STYLER_IS_RUNNING = globals().get('CUSTOM_STYLER_IS_RUNNING', False) 
LIST_OF_FIRST_RUN_DONE = []
DOC_NEEDS_TO_BE_COLORED = False

def init_scintilla():
    # this needs to match the definitions in configuration area
    editor.styleSetFore(STYLE_DEFAULT,   STYLE_DEFAULT_FOREGROUND)
    editor.styleSetBack(STYLE_DEFAULT,   STYLE_DEFAULT_BACKGROUND)   
    editor.styleSetBack(STYLE_EDGES,     STYLE_EDGES_BACKGROUND)  

def custom_lexer(start_pos, end_pos):
    for k in REGEX_DICT.keys():
        matches = []
        editor.research(REGEX_DICT[k], lambda m: matches.append(m.span()), 0, start_pos, end_pos) 
        for match in matches:
            # console.write('match:{} - {}\n'.format(match, editor.getTextRange(*match)))
            editor.startStyling(match[0],31)
            editor.setStyling(match[1]-match[0], eval(k))

def this_doc_should_be_styled():
    global DOC_NEEDS_TO_BE_COLORED
    current_file = notepad.getCurrentFilename()
    _file, _ext = os.path.splitext(current_file)
    if _ext in REGISTERED_FILE_EXTENSIONS or (USE_AS_DEFAULT_LANGUAGE and _file.startswith('new ')):
        DOC_NEEDS_TO_BE_COLORED = True
    else:
        DOC_NEEDS_TO_BE_COLORED = False
    return DOC_NEEDS_TO_BE_COLORED

def get_visible_area():   
    first_visible_line = editor.getFirstVisibleLine()
    last_visible_line = editor.linesOnScreen() + first_visible_line
    start_pos = editor.positionFromLine(first_visible_line)
    end_pos = editor.positionFromLine(last_visible_line)
    return start_pos, end_pos

def callback_BUFFERACTIVATED(args): 
    if this_doc_should_be_styled():
        init_scintilla()
        if args['bufferID'] not in LIST_OF_FIRST_RUN_DONE:
            custom_lexer(*get_visible_area())
            LIST_OF_FIRST_RUN_DONE.append(args['bufferID'])

def callback_UPDATEUI(args):
    if DOC_NEEDS_TO_BE_COLORED and args['updated'] &gt;= 4:
        custom_lexer(*get_visible_area())

def main():
    global CUSTOM_STYLER_IS_RUNNING
    if CUSTOM_STYLER_IS_RUNNING:
        notepad.clearCallbacks([NOTIFICATION.BUFFERACTIVATED])
        editor.clearCallbacks([SCINTILLANOTIFICATION.UPDATEUI])
        CUSTOM_STYLER_IS_RUNNING = False
    else:
        if this_doc_should_be_styled():
            init_scintilla()
            custom_lexer(*get_visible_area())
        notepad.callback(callback_BUFFERACTIVATED, [NOTIFICATION.BUFFERACTIVATED])
        editor.callbackSync(callback_UPDATEUI, [SCINTILLANOTIFICATION.UPDATEUI])
        CUSTOM_STYLER_IS_RUNNING = True

main()
</code></pre>
<hr />
<p dir="auto">Although, it works fine on <strong>.log</strong> files,  I noticed <strong>two</strong> problems :</p>
<ul>
<li>
<p dir="auto">If I modify a <strong>.log</strong> file, by adding a <strong>new</strong> line, of <strong>more</strong> than <strong>79</strong> characters long, I have to <strong>re-run</strong> the script, <strong>twice</strong>, in order to get this <strong>new</strong> line <strong>highlighted</strong>, between the <strong>73th</strong> and the <strong>79th</strong> character ! ( BTW, a small drawback : the <strong>current</strong> line <strong>cannot</strong> be highlighted ! )</p>
</li>
<li>
<p dir="auto">When I decided to change the <strong>.log</strong> extension by the <strong>.py</strong> extension, I was quite <strong>surprised</strong> to get, almost, all <strong>comments</strong>, of the <strong>python</strong> script, highlighted, too ! And sometimes, the columns between positions <strong>73</strong> and <strong>79</strong> were <strong>not</strong> highlighted.</p>
</li>
</ul>
<p dir="auto">So, <strong>Claudia</strong>, any explanation about these behaviours ?</p>
<p dir="auto">Best Regards,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/24067</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/24067</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Thu, 04 May 2017 18:58:19 GMT</pubDate></item><item><title><![CDATA[Reply to Poorman regex based styler&#x2F;lexer on Fri, 28 Apr 2017 01:27:07 GMT]]></title><description><![CDATA[<p dir="auto">Hello guy,<br />
perfekt!! Thanks for the solution, all happy now:-)<br />
Kind regards,<br />
Johannes</p>
]]></description><link>https://community.notepad-plus-plus.org/post/23953</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/23953</guid><dc:creator><![CDATA[Johannes Dillinger]]></dc:creator><pubDate>Fri, 28 Apr 2017 01:27:07 GMT</pubDate></item><item><title><![CDATA[Reply to Poorman regex based styler&#x2F;lexer on Fri, 28 Apr 2017 01:04:34 GMT]]></title><description><![CDATA[<p dir="auto">Hello, <a class="plugin-mentions-user plugin-mentions-a" href="/user/claudia-frank" aria-label="Profile: Claudia-frank">@<bdi>Claudia-frank</bdi></a>, <a class="plugin-mentions-user plugin-mentions-a" href="/user/johannes-dillinger" aria-label="Profile: johannes-dillinger">@<bdi>johannes-dillinger</bdi></a> and <strong>All</strong></p>
<p dir="auto">A quick reply, because it’s <strong>3h00 am</strong>, in <strong>France</strong>, and… I work, tomorrow !</p>
<ul>
<li><a class="plugin-mentions-user plugin-mentions-a" href="/user/claudia-frank" aria-label="Profile: Claudia-frank">@<bdi>Claudia-frank</bdi></a> :</li>
</ul>
<p dir="auto">It’s just fine ! No problem, anymore, with the <strong>synchronous</strong>  UPDATEUI callback :-))) So, thanks to you, you have a <strong>new wonderful</strong> world to discover, with <strong>multiple colouring</strong> of, either, <strong>foreground</strong> and/or <strong>background</strong> of lines of files, with a specific <strong>extension</strong>, handled with <strong>regular</strong> expressions !!</p>
<hr />
<ul>
<li><a class="plugin-mentions-user plugin-mentions-a" href="/user/johannes-dillinger" aria-label="Profile: johannes-dillinger">@<bdi>johannes-dillinger</bdi></a> :</li>
</ul>
<p dir="auto">I think that the <strong>correct</strong> regex ( tested, with a <strong>grey</strong> colour, on <strong>foreground</strong> and <strong>background</strong> ! ) should be, as below :</p>
<pre><code class="language-py">REGEX_DICT[‘STYLE_COMM’] = '(?-s)\$.*'
</code></pre>
<p dir="auto"><strong>Notes</strong> :</p>
<ul>
<li>
<p dir="auto">The <strong><code>(?-s)</code></strong> modifier tells the regex engine that the <strong>meta</strong>-character <strong><code>.</code></strong> matches a <strong>single standard</strong> character, only</p>
</li>
<li>
<p dir="auto">The <strong><code>\$</code></strong> searches for a <strong>literal</strong> <strong><code>$</code></strong> character</p>
</li>
<li>
<p dir="auto">The final part <strong><code>.*</code></strong> looks for the remainder of <strong>current</strong> line, possibly <strong>empty</strong> !</p>
</li>
</ul>
<hr />
<p dir="auto">Once more, a very <strong>powerful</strong> script, that you give us, <strong>Claudia</strong> ! A thousand thanks, Yeah !</p>
<p dir="auto">Cheers,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/23952</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/23952</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Fri, 28 Apr 2017 01:04:34 GMT</pubDate></item><item><title><![CDATA[Reply to Poorman regex based styler&#x2F;lexer on Thu, 27 Apr 2017 23:16:41 GMT]]></title><description><![CDATA[<p dir="auto">Hi Claudia,<br />
got it working, thanks a lot! Also the synchronous version works well, better than the asynchronous in my case I guess.</p>
<p dir="auto"><a href="https://goo.gl/photos/yqRr2o8rDJUm7Z2x6" rel="nofollow ugc">https://goo.gl/photos/yqRr2o8rDJUm7Z2x6</a></p>
<p dir="auto">(never mind the colors…)</p>
<p dir="auto">One last question… I want to grey out comments-lines, which in this language start with a dollar sign and last till the end of the line (always). The dollar-sign can appear in the middle of a line, so also after a few numbers of actual code.<br />
I thought that this regex might do, but it does not:</p>
<p dir="auto">REGEX_DICT[‘STYLE_COMM’]      = ‘(?&lt;=[$]).+$’</p>
<p dir="auto">Can you give me a hint on how it should look like?<br />
Thanks again!<br />
Kind regards,</p>
<p dir="auto">Johannes</p>
]]></description><link>https://community.notepad-plus-plus.org/post/23951</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/23951</guid><dc:creator><![CDATA[Johannes Dillinger]]></dc:creator><pubDate>Thu, 27 Apr 2017 23:16:41 GMT</pubDate></item><item><title><![CDATA[Reply to Poorman regex based styler&#x2F;lexer on Thu, 27 Apr 2017 20:05:00 GMT]]></title><description><![CDATA[<p dir="auto">Hi Guy,</p>
<p dir="auto">scrolling that fast - you must be one of those who can read a whole book in under a minute ;-)</p>
<p dir="auto">I assume the asynchronous updateui callback isn’t good in such a case.<br />
Give it a try with the synchronous version.</p>
<pre><code>editor.callbackSync(callback_UPDATEUI, [SCINTILLANOTIFICATION.UPDATEUI])
</code></pre>
<p dir="auto">Cheers<br />
Claudia</p>
]]></description><link>https://community.notepad-plus-plus.org/post/23946</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/23946</guid><dc:creator><![CDATA[Claudia Frank]]></dc:creator><pubDate>Thu, 27 Apr 2017 20:05:00 GMT</pubDate></item><item><title><![CDATA[Reply to Poorman regex based styler&#x2F;lexer on Thu, 27 Apr 2017 19:35:11 GMT]]></title><description><![CDATA[<p dir="auto">Hello <a class="plugin-mentions-user plugin-mentions-a" href="/user/claudia-frank" aria-label="Profile: Claudia-frank">@<bdi>Claudia-frank</bdi></a> and <strong>All</strong>,</p>
<p dir="auto">If you don’t mind, <strong>Claudia</strong>, I would like you to test my <strong>example</strong> text, with my <strong>own</strong> version of your script !</p>
<p dir="auto">Here is the <strong>sample</strong> text, in the <strong>Test.log</strong> file :</p>
<pre><code>1234567890123456789012345

1234567890123456789012345
1234567890123456789012345
1234567890123456789012345
12
123456
1234567890123456789012345
1234567890123456789012345
1234567890123456789012345
1234567890
1234567890123456789012345
1234567890123456789012345
1234567890
1234567890123456789012345


1234567890123456789012345

1234567890123456789012345
1234567890123456789012345
1234567890123456789012345
12
123456
1234567890123456789012345
1234567890123456789012345
1234567890123456789012345
1234567890
1234567890123456789012345
1234567890123456789012345
1234567890
1234567890123456789012345


1234567890123456789012345

1234567890123456789012345
1234567890123456789012345
1234567890123456789012345
12
123456
1234567890123456789012345
1234567890123456789012345
1234567890123456789012345
1234567890
1234567890123456789012345
1234567890123456789012345
1234567890
1234567890123456789012345


1234567890123456789012345

1234567890123456789012345
1234567890123456789012345
1234567890123456789012345
12
123456
1234567890123456789012345
1234567890123456789012345
1234567890123456789012345
1234567890
1234567890123456789012345
1234567890123456789012345
1234567890
1234567890123456789012345
</code></pre>
<hr />
<p dir="auto">Now, here is the <strong>part</strong> of your script, that I <strong>slightly</strong> changed :</p>
<pre><code class="language-py"># ---------------------------- configuration area -----------------------------

# stlye definitions - changes here need to match setup calls in init_scintilla()
STYLE_DEFAULT               = 0 # don't change this
STYLE_WARNINGS              = 1
STYLE_ERRORS                = 2

STYLE_DEFAULT_FOREGROUND    = (0,0,0)           # Black
STYLE_DEFAULT_BACKGROUND    = (255,255,255)     # White
STYLE_WARNINGS_BACKGROUND   = (0,255,0)         # Green
STYLE_ERRORS_BACKGROUND     = (255,0,0)         # Red

REGISTERED_FILE_EXTENSIONS  = ['.log']
USE_AS_DEFAULT_LANGUAGE     = False

REGEX_DICT = OrderedDict()  # to be sure that regex get called in the same order each time
REGEX_DICT['STYLE_WARNINGS']      = '(?-s)^.{8}'
REGEX_DICT['STYLE_ERRORS']        = '(?-s)^.{16}\K.{4}'

# -------------------------- configuration area end ---------------------------

CUSTOM_STYLER_IS_RUNNING = globals().get('CUSTOM_STYLER_IS_RUNNING', False) 
LIST_OF_FIRST_RUN_DONE = []
DOC_NEEDS_TO_BE_COLORED = False

def init_scintilla():
    # this needs to match the definitions in configuration area
    editor.styleSetFore(STYLE_DEFAULT,   STYLE_DEFAULT_FOREGROUND)
    editor.styleSetBack(STYLE_DEFAULT,   STYLE_DEFAULT_BACKGROUND)   
    editor.styleSetBack(STYLE_WARNINGS,  STYLE_WARNINGS_BACKGROUND)  
    editor.styleSetBack(STYLE_ERRORS,    STYLE_ERRORS_BACKGROUND)  
</code></pre>
<p dir="auto"><strong>Notes</strong> :</p>
<ul>
<li>
<p dir="auto">As you can see, as I, usually, work with the <strong>default</strong> colours, I changed the <strong>STYLE_DEFAULT_… …</strong> colours</p>
</li>
<li>
<p dir="auto">Of course, I changed the <strong>two</strong> regexes for testing :-D</p>
</li>
<li>
<p dir="auto">In the <strong>init_scintilla()</strong> function, the <strong>last two</strong> lines, begin with <strong>editor.styleSetBack</strong> ( instead of <strong>editor.styleSetFore</strong> )</p>
</li>
<li>
<p dir="auto">And, accordingly, I renamed the <strong>two</strong> variables <strong>STYLE_WARNINGS_FOREGROUND</strong> and  <strong>STYLE_ERRORS_FOREGROUND</strong> into <strong>STYLE_WARNINGS_BACKGROUND</strong> and <strong>STYLE_ERRORS_BACKGROUND</strong></p>
</li>
</ul>
<p dir="auto">After starting N++ and opening the <strong>Test.log</strong> file, I ran your script and… bingo : Wow, I got <strong>two coloured</strong> columns :</p>
<ul>
<li>
<p dir="auto">The <strong>eight</strong> characters and <strong>green</strong> one, between column <strong>1</strong> and column <strong>8</strong></p>
</li>
<li>
<p dir="auto">The <strong>four</strong> characters and <strong>red</strong> one, between column <strong>17</strong> and column <strong>20</strong></p>
</li>
</ul>
<p dir="auto">That’s great, indeed !</p>
<hr />
<p dir="auto">Now, there an <strong>small</strong> problem : If you scroll <strong>up</strong> and <strong>down</strong>, the editor window, <strong>quickly</strong> enough, with the <strong>mouse</strong>, some parts of the text, which should <strong>not</strong> be matched, are <strong>highlighted</strong> too :-((. I, first, thought it was due to the <strong><code>\K</code></strong> syntax. <strong>Unfortunately</strong>, even if you write, as below :</p>
<pre><code class="language-py">REGEX_DICT['STYLE_ERRORS'] = 'XYZ'
</code></pre>
<p dir="auto">You’ll surely notice, some <strong>green</strong> parts of text are <strong>wrongly</strong> highlighted !</p>
<p dir="auto">What do you think about it ?</p>
<p dir="auto">Cheers,</p>
<p dir="auto">guy038</p>
]]></description><link>https://community.notepad-plus-plus.org/post/23945</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/23945</guid><dc:creator><![CDATA[guy038]]></dc:creator><pubDate>Thu, 27 Apr 2017 19:35:11 GMT</pubDate></item><item><title><![CDATA[Reply to Poorman regex based styler&#x2F;lexer on Thu, 27 Apr 2017 18:41:33 GMT]]></title><description><![CDATA[<p dir="auto">Hello Johannes,</p>
<p dir="auto">I do understand that you will give it a try yourself<br />
and you will come back in case of a question, correct?</p>
<p dir="auto">Cheers<br />
Claudia</p>
]]></description><link>https://community.notepad-plus-plus.org/post/23943</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/23943</guid><dc:creator><![CDATA[Claudia Frank]]></dc:creator><pubDate>Thu, 27 Apr 2017 18:41:33 GMT</pubDate></item><item><title><![CDATA[Reply to Poorman regex based styler&#x2F;lexer on Thu, 27 Apr 2017 11:34:53 GMT]]></title><description><![CDATA[<p dir="auto">Hello Claudia,</p>
<p dir="auto">thanks again for the quick reply! Oh, does not have to to without callbacks, I thought it might make life easier. In my version I tried without, but it did not work, so…:)</p>
<p dir="auto">The 8 columns are fix.</p>
<p dir="auto">In the meantime I will try some more if I find the time; in case I can get something to work, will let you know…</p>
<p dir="auto">Thanks a lot again!<br />
Kind regards,</p>
<p dir="auto">Johannes</p>
]]></description><link>https://community.notepad-plus-plus.org/post/23937</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/23937</guid><dc:creator><![CDATA[Johannes Dillinger]]></dc:creator><pubDate>Thu, 27 Apr 2017 11:34:53 GMT</pubDate></item><item><title><![CDATA[Reply to Poorman regex based styler&#x2F;lexer on Thu, 27 Apr 2017 11:19:11 GMT]]></title><description><![CDATA[<p dir="auto">Hello Johannes,</p>
<p dir="auto">will follow up on this when back from work.</p>
<p dir="auto">But, without callbacks would mean that you have to run it over and over again<br />
to make it coloring again if text changes.</p>
<p dir="auto">One question in the meantime, is the 8 columns as shown in your photo,<br />
also fix or could it be that more or less columns are required.</p>
<p dir="auto">Cheers<br />
Claudia</p>
]]></description><link>https://community.notepad-plus-plus.org/post/23936</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/23936</guid><dc:creator><![CDATA[Claudia Frank]]></dc:creator><pubDate>Thu, 27 Apr 2017 11:19:11 GMT</pubDate></item><item><title><![CDATA[Reply to Poorman regex based styler&#x2F;lexer on Thu, 27 Apr 2017 02:30:21 GMT]]></title><description><![CDATA[<p dir="auto">Dear Claudia,</p>
<p dir="auto">thanks for the quick response, this really gives me hope that somewhen soon I can solve this looong lasting problem of mine…<br />
The task the script should perform is actually rather simple I suppose:</p>
<p dir="auto">I use a script-language called Nastran, that is an old, fortran related language, where everything is written in a ascii-text-file on a "fixed width basis, meaning, that each text-package has to be written in fields of length 8 (-&gt;column-width 8).<br />
In linux, I use nedit as text text editor for these ascii-files, and in nedit I have the option to highlight columns, independent of there content. This makes programming very easy, since input errors based on accidentially shifted input is nicely visualized:</p>
<p dir="auto"><a href="https://goo.gl/photos/t3RKWFenAixy5Eve9" rel="nofollow ugc">https://goo.gl/photos/t3RKWFenAixy5Eve9</a></p>
<p dir="auto">(can you see this pic?)</p>
<p dir="auto">Since I am switching more and more to windows and npp, it would be great to have the same coloring-option…</p>
<p dir="auto">With your input above I still cant get it to work I have to admit… I adapted it to highlight at least the first 8 columns, but it does not show any change when running the script… Maybe you can think of a simple version of highlighting colors independent of their content? I think it should not look too different from what you proposed, maybe without all the callbacks?<br />
I think, the script has to be run only once, since the coloring is independent of whats actually in the text file…</p>
<p dir="auto">Thanks a lot again in advance!!<br />
Kind regards,</p>
<p dir="auto">Johannes</p>
]]></description><link>https://community.notepad-plus-plus.org/post/23930</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/23930</guid><dc:creator><![CDATA[Johannes Dillinger]]></dc:creator><pubDate>Thu, 27 Apr 2017 02:30:21 GMT</pubDate></item><item><title><![CDATA[Reply to Poorman regex based styler&#x2F;lexer on Wed, 26 Apr 2017 23:12:46 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/johannes-dillinger" aria-label="Profile: Johannes-Dillinger">@<bdi>Johannes-Dillinger</bdi></a></p>
<p dir="auto">first make sure that no other lexer is active. Meaning if you open a python file<br />
and run the script it won’t work as the default python lexer will overwrite the styles.<br />
So if your file is already assigned to another lexer (builtin or user defined) use<br />
<strong>Normal text</strong> from language menu and then run the script.</p>
<p dir="auto">The scripts purpose was to color monitored files therefore the following code has been created</p>
<pre><code>def callback_UPDATEUI(args):
    if DOC_NEEDS_TO_BE_COLORED and args['updated'] &gt;= 4:
        custom_lexer(*get_visible_area())
</code></pre>
<p dir="auto">the  args[‘updated’] &gt;= 4 is the critical part which means that it only updates the ui<br />
if a scroll action happend. See <a href="http://www.scintilla.org/ScintillaDoc.html#SCN_UPDATEUI" rel="nofollow ugc">here</a> for more details, maybe you wanna use a different value for your purpose.</p>
<p dir="auto">Now the regex part.<br />
The re engine always returns whole and partial matches which means if you are<br />
looking for .{8}(.{8}) the engine returns the whole match containing the 16 chars<br />
and a submatch returning the second 8 chars.<br />
The script ignores submatches. If you need to work with submatches<br />
<a href="https://sourceforge.net/p/npppythonscript/discussion/1199074/thread/f59511a4/" rel="nofollow ugc">here</a> my regex tester which shows how to handle those.</p>
<p dir="auto">Otherwise you have to create something like this.</p>
<p dir="auto">REGEX_DICT[‘STYLE_COL1’]        = ‘(?-s)^.{8}’<br />
REGEX_DICT[‘STYLE_COL2’]        = ‘(?-s)^.{8}\K.{8}’<br />
REGEX_DICT[‘STYLE_COL3’]        = ‘(?-s)^.{16}\K.{8}’</p>
<p dir="auto">Just another question, what do you try to achieve?</p>
<p dir="auto">If you just want to have an column view on text you need to make<br />
sure that all rows contain the same amount of text otherwise you will<br />
see gaps.</p>
<p dir="auto">If there is something else I can do, let me know.</p>
<p dir="auto">Cheers<br />
Claudia</p>
]]></description><link>https://community.notepad-plus-plus.org/post/23927</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/23927</guid><dc:creator><![CDATA[Claudia Frank]]></dc:creator><pubDate>Wed, 26 Apr 2017 23:12:46 GMT</pubDate></item><item><title><![CDATA[Reply to Poorman regex based styler&#x2F;lexer on Wed, 26 Apr 2017 19:28:44 GMT]]></title><description><![CDATA[<p dir="auto">Hello everyone,<br />
maybe someone can help me out, I cant really get it to work…<br />
I would like to color columns in fixed width (alternating, in columns of 8: 8-8-8-8-8…), independent of the content of the line. I tried to apply the poormans script:-)<br />
Here is what I wrote, but the coloring for the first 8 columns already does not work…<br />
Maybe someone knows a solution. I guess the regex is still wrong, but I dont know, it works here:<br />
<a href="https://regex101.com/r/wuvNR3/2" rel="nofollow ugc">https://regex101.com/r/wuvNR3/2</a><br />
Thanks a lot in advance!<br />
Kind regards,<br />
Johannes</p>
<p dir="auto">import re, os<br />
from collections import OrderedDict</p>
<p dir="auto">STYLE_DEFAULT               = 0 # don’t change this<br />
STYLE_COL1                  = 1</p>
<p dir="auto">STYLE_DEFAULT_FOREGROUND    = (255,0,255)     	# black<br />
STYLE_DEFAULT_BACKGROUND    = (245,245,245)   	# white<br />
STYLE_COL1_BACKGROUND       = (0,255,0)			# green</p>
<p dir="auto">REGEX_DICT = OrderedDict()  # to be sure that regex get called in the same order each time<br />
REGEX_DICT[‘STYLE_COL1’]          = ‘(?-s).{8}(.{8})’     # <a href="http://stackoverflow.com/questions/12559144/regex-for-fixed-position-and-length-field" rel="nofollow ugc">http://stackoverflow.com/questions/12559144/regex-for-fixed-position-and-length-field</a></p>
<h1>REGISTERED_FILE_EXTENSIONS  = [‘.bdf’]</h1>
<p dir="auto">def init_scintilla():<br />
# this needs to match the definitions in configuration area<br />
editor.styleSetFore(STYLE_DEFAULT,   STYLE_DEFAULT_FOREGROUND)<br />
editor.styleSetBack(STYLE_DEFAULT,   STYLE_DEFAULT_BACKGROUND)<br />
editor.styleSetBack(STYLE_COL1,      STYLE_COL1_BACKGROUND)</p>
<p dir="auto">init_scintilla()</p>
]]></description><link>https://community.notepad-plus-plus.org/post/23923</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/23923</guid><dc:creator><![CDATA[Johannes Dillinger]]></dc:creator><pubDate>Wed, 26 Apr 2017 19:28:44 GMT</pubDate></item><item><title><![CDATA[Reply to Poorman regex based styler&#x2F;lexer on Sat, 28 Jan 2017 01:35:54 GMT]]></title><description><![CDATA[<p dir="auto">this is absolutely great</p>
<p dir="auto">it is super useful for noobs like me, who are trying to learn how to interface python with NPP</p>
<p dir="auto">thank you</p>
]]></description><link>https://community.notepad-plus-plus.org/post/21327</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/21327</guid><dc:creator><![CDATA[Js jS]]></dc:creator><pubDate>Sat, 28 Jan 2017 01:35:54 GMT</pubDate></item></channel></rss>