From d2e13d3f39c2c6de66d229e9a9850faf9a2fdf39 Mon Sep 17 00:00:00 2001 From: Robby Findler Date: Wed, 5 Jan 2011 16:05:55 -0600 Subject: [PATCH] added an observer for the colorer original commit: 92d9ce38d3d568daf72ba8f98080cdf9110fc1d9 --- collects/framework/private/color.rkt | 18 ++++++++++++++++-- collects/scribblings/framework/color.scrbl | 9 +++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/collects/framework/private/color.rkt b/collects/framework/private/color.rkt index 25ee0731..1b5c0f9e 100644 --- a/collects/framework/private/color.rkt +++ b/collects/framework/private/color.rkt @@ -209,7 +209,8 @@ added get-regions (loop (cdr old) (cdr new)))] [else (cons (make-new-lexer-state (caar new) (cadar new)) - (loop null (cdr new)))])))) + (loop null (cdr new)))]))) + (update-lexer-state-observers)) (define/public (get-regions) @@ -236,6 +237,16 @@ added get-regions local-edit-sequence? get-styles-fixed has-focus? get-fixed-style) + (define lexers-all-valid? #t) + (define/private (update-lexer-state-observers) + (define new (for/and ([ls (in-list lexer-states)]) + (lexer-state-up-to-date? ls))) + (unless (eq? new lexers-all-valid?) + (set! lexers-all-valid? new) + (on-lexer-valid lexers-all-valid?))) + (define/pubment (on-lexer-valid valid?) + (inner (void) on-lexer-valid valid?)) + (define/private (reset-tokens) (for-each (lambda (ls) @@ -247,6 +258,7 @@ added get-regions (set-lexer-state-current-lexer-mode! ls #f) (set-lexer-state-parens! ls (new paren-tree% (matches pairs)))) lexer-states) + (update-lexer-state-observers) (set! restart-callback #f) (set! force-recolor-after-freeze #f) (set! colors null) @@ -374,6 +386,7 @@ added get-regions (send valid-tree search-max!) (data-lexer-mode (send valid-tree get-root-data)))))) (set-lexer-state-up-to-date?! ls #f) + (update-lexer-state-observers) (queue-callback (λ () (colorer-callback)) #f))) ((>= edit-start-pos (lexer-state-invalid-tokens-start ls)) (let-values (((tok-start tok-end valid-tree invalid-tree orig-data) @@ -454,7 +467,8 @@ added get-regions (when (coroutine-run 10 tok-cor) (for-each (lambda (ls) (set-lexer-state-up-to-date?! ls #t)) - lexer-states))) + lexer-states) + (update-lexer-state-observers))) #;(printf "end lexing\n") #;(printf "begin coloring\n") ;; This edit sequence needs to happen even when colors is null diff --git a/collects/scribblings/framework/color.scrbl b/collects/scribblings/framework/color.scrbl index 258932d3..2b727ac8 100644 --- a/collects/scribblings/framework/color.scrbl +++ b/collects/scribblings/framework/color.scrbl @@ -220,6 +220,15 @@ Must only be called while the tokenizer is started. } + + @defmethod[#:mode augment (on-lexer-valid [valid? boolean?]) any]{ + This method is an observer for when the lexer is working. + It is called when the lexer's state changes from valid to invalid (and back). + The @racket[valid?] argument indicates if the lexer has finished running over the editor (or not). + + The default method just returns @racket[(void)]. + } + } @defmixin[color:text-mixin (text:basic<%>) (color:text<%>)]{ Adds the functionality needed for on-the-fly coloring and parenthesis