custom lexer or syntax highlighting

467 views
Skip to first unread message

Denis Spasyuk

unread,
Aug 2, 2015, 10:51:17 PM8/2/15
to scintilla-interest
Hi Gentlemen,
I am looking for a way to use styling functions of scintilla to highlight a few keywords in the text. I am using python (wx) at this point, but it's very slow. I was wondering if there is a way to do that with scintilla?


thank you in advance,

here is my python function:

styled_text=["CELL", "FLAT", "ZERR", "LIST", "SWAT", "LATT"]
fulltext = self.text.GetText()
#self.text.StyleSetSpec (2, "fore:#0000FF")
if ossystem.startswith("darwin"):
self.text.StyleSetSpec(2, 'fore:#221dff,back:#FFFFFF,bold,face:Courier,size:'+str(self.fsg))
else:
self.text.StyleSetSpec(2, 'fore:#221dff,back:#FFFFFF,bold,face:Courier New,size:'+str(self.fsg))
for item in styled_text:
pos = fulltext.find(item)
while pos in range(0, len(fulltext)):
self.text.StartStyling(pos, 2)
self.text.SetStyling(len(item), 2)
pos=fulltext.find(item, pos+1)

Matthew Brush

unread,
Aug 3, 2015, 2:06:11 AM8/3/15
to scintilla...@googlegroups.com
On 15-08-02 07:05 PM, Denis Spasyuk wrote:
> Hi Gentlemen,
> I am looking for a way to use styling functions of scintilla to highlight a few keywords in the text. I am using python (wx) at this point, but it's very slow. I was wondering if there is a way to do that with scintilla?
>

Indeed. There's 3 good links at the start of the Scintilla documentation
that describe how to do it, in addition to the reference material in the
rest of the docs.

Cheers,
Matthew Brush

Neil Hodgson

unread,
Aug 3, 2015, 4:04:12 AM8/3/15
to scintilla...@googlegroups.com
Denis Spasyuk:

> I am looking for a way to use styling functions of scintilla to highlight a few keywords in the text. I am using python (wx) at this point, but it's very slow. I was wondering if there is a way to do that with scintilla?
> …
> here is my python function:
> …

That should be reasonably fast if its just being run once on a reasonable sized (<1MB) file. If this is being run after every change to the document then it will be slow. Lexers work by only processing from the last change to the end of the screen which allows them to work reasonably on every change. Either write your process as a lexer or use the same approach: only process what needs to be.

Neil

Denis Spasyuk

unread,
Aug 3, 2015, 4:32:20 PM8/3/15
to scintilla-interest, nyama...@me.com
Thanks guys,

The python way works fine but if there is a faster way of doing the same thing that would be great. I read all the scintilla documentation but I cannot seems to find a nice example on how to actually implement custom lexer. If anyone can point me to that, I would be grateful.

cheers

denis

Matthew Brush

unread,
Aug 3, 2015, 4:53:50 PM8/3/15
to scintilla...@googlegroups.com
On 15-08-03 01:32 PM, Denis Spasyuk wrote:
> Thanks guys,
>
> The python way works fine but if there is a faster way of doing the same
> thing that would be great. I read all the scintilla documentation but I
> cannot seems to find a nice example on how to actually implement custom
> lexer. If anyone can point me to that, I would be grateful.
>

One of the links at the top of the documentation I mentioned explains
how to implement a "container lexer" (lexer implemented in the application):

http://sphere.sourceforge.net/flik/docs/scintilla-container_lexer.html

Another of the links at the top of the docs explains how to write a
"real" lexer (loadable by Scintilla):

https://bitbucket.org/StarFire/scintilla-doc/downloads/Scintilla-var%27aq-Tutorial.pdf

And then there's around of 100 examples inside Scintilla's source code:

http://sourceforge.net/p/scintilla/code/ci/default/tree/lexers/

If you really only need to highlight keywords a "container lexer" is
probably the simplest. I'm assuming wxStyleTextControl or whatever it's
called lets you do that.

Cheers,
Matthew Brush

Denis Spasyuk

unread,
Aug 7, 2015, 11:19:12 PM8/7/15
to scintilla-interest
Thank you Matthew, much appreciated !
Reply all
Reply to author
Forward
0 new messages