[plt-scheme] text% : snips, styles and delta-styles

From: Robby Findler (robby at cs.uchicago.edu)
Date: Sun Oct 14 18:48:30 EDT 2007

I think you might want to make the styles not be "sticky". (Try
searching for that in Help Desk.)

hth,
Robby

On 10/14/07, Cyprien Nicolas <c.nicolas at gmail.com> wrote:
> Hi folks
>
> Inside a text% editor, I trying to change the delta-style from some snips.
> However, when I change the delta-style for a style for the first snip,
> all the text in the editor get the same style, even if I change the
> delta style for others snip further.
>
> Maybe I missed something about styles and delta-styles...
>
> Here is my code for changing the styles :
>   (define colorize
>     (lambda (a-text)
>       (let* ((input (open-input-string (send a-text get-text)))
>              (lex (makeLexer input))
>              (lexed (analyse-all lex))) ; lexed is a list of (id text position)
>         (let ((oldIndex 0) ; It is unused right now
>               (color-snip
>                (lambda (l)
>                  (let ((type (car l)) (pos (caddr l)))
>                    (send a-text split-snip pos) ;  for splitting snips
>                    (let ((snip (send a-text find-snip pos 'before))) ;
> and get the one before
>                      (printf "~a: ~a~n" type (send snip get-text 0
> (send snip get-count)))
>                      (let ((snip-style (send snip get-style))
> (new-snip-delta (assv type get-delta)))
>                        (when new-snip-delta
>                          (let ((snip-delta (cadr new-snip-delta)))
>                            (send snip-style get-delta snip-delta)
>                            (send snip-style set-delta (send snip-delta
> set-delta-foreground (cadr (assv type types-style))))))
>                        ))))))
>           (for-each color-snip lexed)))
>       ))
>
> get-delta is a a-list with delta styles :
>   (define get-delta
>     `(; Syntax: (identifier a-style-delta)
>       (keyword ,(let ((new-delta (make-object style-delta%
> 'change-normal-color)))
>                   (send new-delta set-delta-foreground "blue")))
>       (empty ,(let ((new-delta (make-object style-delta% 'change-normal-color)))
>                (send new-delta set-delta-foreground "orange")))
>       (string ,(let ((new-delta (make-object style-delta%
> 'change-normal-color)))
>                   (send new-delta set-delta-foreground "green")))
>       (int ,(let ((new-delta (make-object style-delta% 'change-normal-color)))
>                   (send new-delta set-delta-foreground "red"))))
>     )
>
> and types-style is another a-list with (keyword "color") elements.
>
>
> For my example, all the editor is orange colored, because the first
> snip style is linked with empty, for other snip, with get-style,
> get-delta and get-delta-foreground, I'm able to see that the colors in
> the delta are differents, but these differences are not visible.
>
>
> Does anyone has an example with style-list, snip and colors for a text% object ?
>
>
> Thanks,
> --
> Cyprien Nicolas
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>


Posted on the users mailing list.