[plt-scheme] [Mred] - syntax coloring in editor canvas
On Dec 7, 2006, at 9:03 AM, jack jack wrote:
> Hi all,
>
> i'm trying to make automatic syntax coloring of editor-canvas%'s
> content.
Do you know that we already have a library that does that? It is
based on Scott Owen's parser generators. See color:text% in Help Desk.
> For testing, i made changes manually, then entered text in the
> editor.
>
> like this:
> "entered text into editor"
>> (define style-delta (make-object style-delta% 'change-weight 'bold))
>> (send text1 change-style (send style-delta2 set-delta-foreground
>> "navy"))
> "entered text into editor"
>
> That works but since yet i don't know how to change the style from
> an existing text.
change-style takes two more arguments that specify a range in the
editor. use those to change existing text.
> i saw methods which changes colors but wasn't able to make them
> work at all, because the way i meant it is: using regexp-match to
> look for the keyword each time the user type text into the edit
> canvas (when i get an on-char event i call for the coloring
> function, on the line or the entire editor canvas content)
You probably want after-insert and after-delete, rather than on-char.
> Since regexp returns a list containing the matched string(s), what
> do i need to do now?
use regexp-match-positions
> Perhaps getting the start & end offset and change the color using a
> method which is called like change color from start offset until
> stop offset??? (how to?)
>
> Or is there another, much easier, way doing it?
Just the library that's already there. :)
>
> Thx in advance, helping me out,
> jack.
>
> _________________________________________________________________
> Découvrez le blog Eragon sur Windows Live Spaces! http://eragon-
> heroic-fantasy.spaces.live.com/
>
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>