How can I can overlay a "temporary" styling with what a lexer has already done?

58 views
Skip to first unread message

John Vella

unread,
Jul 2, 2012, 11:20:35 PM7/2/12
to scintilla...@googlegroups.com
I'm using the lexers that come with Scintilla(eg C++, Verilog, VHDL, etc). I have a need to "overlay" a style temporarily and when done with it I need the style that the lexer had applied to reappear. For example, say the C++ lexer applied style 10 for a range of text. I then create my own custom style and apply it to that same range of text(via SCI_SETSTYLING). How do I then remove my custom styling so the original style 10 will once again be used? 

A small code snippet would really help me out.

Thanks in advance,
-John

Neil Hodgson

unread,
Jul 3, 2012, 9:45:49 AM7/3/12
to scintilla...@googlegroups.com
John Vella:

I'm using the lexers that come with Scintilla(eg C++, Verilog, VHDL, etc). I have a need to "overlay" a style temporarily and when done with it I need the style that the lexer had applied to reappear.

   This is somewhat dangerous as lexers may assume they are the only writers to the document styles. For example they may seek backward to determine the start of some construct and use the styles to guide their way. For example, the Python lexer looks back for backslash continuations in string styles.

   An alternative for some cases is to use indicators although these can not change the styles appearance as much.


For example, say the C++ lexer applied style 10 for a range of text. I then create my own custom style and apply it to that same range of text(via SCI_SETSTYLING). How do I then remove my custom styling so the original style 10 will once again be used? 

   The safest way is to allow the lexer to restyle those characters by resetting the end of valid styling to the start of the line with the temporary styles with SCI_STARTSTYLING.

   Neil

John Vella

unread,
Jul 3, 2012, 9:49:58 AM7/3/12
to scintilla...@googlegroups.com
So what else do I need to call after SCI_STARTSTYLING? And also what would the mask value be?

Thanks,
-John


--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To post to this group, send email to scintilla...@googlegroups.com.
To unsubscribe from this group, send email to scintilla-inter...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/scintilla-interest?hl=en.

John Vella

unread,
Jul 3, 2012, 12:16:33 PM7/3/12
to scintilla...@googlegroups.com
Neil, here's a little more info. I would like to create a set of styles which is independent from those used by the lexers(so they all have IDs > STYLE_MAX). The purpose of these styles would be for things like flagging "places of interest" within the text. I would like to assign these "auxiliary" styles to arbitrary ranges of text, overwriting temporarily what the lexer has assigned. Then when I remove the auxiliary style, I will need to have the lexer's style reapplied.

Could you tell me if what I want to do is even possible with Scintilla? I'm hoping "yes" and that I'm just missing some step I need to follow.

It seems not since the mask value in SCI_STARTSTYLING is documented to be only 8-bits, which would only cover the styles defined by lexers.

Thanks a lot for the help,
-John


On Tue, Jul 3, 2012 at 6:45 AM, Neil Hodgson <nyama...@me.com> wrote:

Neil Hodgson

unread,
Jul 3, 2012, 6:41:22 PM7/3/12
to scintilla...@googlegroups.com
John Vella:

Neil, here's a little more info. I would like to create a set of styles which is independent from those used by the lexers(so they all have IDs > STYLE_MAX).

   The styling information is only 8-bits wide. It is not possible to use IDs > STYLE_MAX for document styles.

Could you tell me if what I want to do is even possible with Scintilla? I'm hoping "yes" and that I'm just missing some step I need to follow.

   This is not supported by Scintilla currently.

   Neil

Dave Brotherstone

unread,
Jul 4, 2012, 1:53:15 AM7/4/12
to scintilla...@googlegroups.com
On Tue, Jul 3, 2012 at 6:16 PM, John Vella <jvel...@gmail.com> wrote:
Neil, here's a little more info. I would like to create a set of styles which is independent from those used by the lexers(so they all have IDs > STYLE_MAX). The purpose of these styles would be for things like flagging "places of interest" within the text. I would like to assign these "auxiliary" styles to arbitrary ranges of text, overwriting temporarily what the lexer has assigned. Then when I remove the auxiliary style, I will need to have the lexer's style reapplied.

Could you tell me if what I want to do is even possible with Scintilla? I'm hoping "yes" and that I'm just missing some step I need to follow.



Although as Neil says, you can't really do this with lexer styles, you should look at indicators - http://www.scintilla.org/ScintillaDoc.html#Indicators
It sounds like that will do what you need, even though the implementation is different to what you describe, and doesn't allow as much flexibility as with styles.

Cheers,
Dave.
Reply all
Reply to author
Forward
0 new messages