From a5a8bc2e7183768e0bdf1cb2532bdd24ebccd02b Mon Sep 17 00:00:00 2001 From: Robby Findler Date: Sat, 26 Jan 2013 09:04:51 -0600 Subject: [PATCH] adjust find-next-outer-paren to avoid editing the buffer related to PR 13454 original commit: aaf4a2e16d5b4218ca4bd6788525fa7541879daa --- collects/framework/private/color.rkt | 43 ++++++++++++++-------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/collects/framework/private/color.rkt b/collects/framework/private/color.rkt index a6943e83..0dcf771b 100644 --- a/collects/framework/private/color.rkt +++ b/collects/framework/private/color.rkt @@ -947,27 +947,28 @@ added get-regions ;; find-next-outer-paren : number (list string) ;; -> (values (or #f number) (or #f number) (or #f string)) (define/private (find-next-outer-paren pos closers) - (cond - [(null? closers) (values #f #f #f)] - [else - (define c (car closers)) ; pick a close parens - (define l (string-length c)) - (define ls (find-ls pos)) - (cond - [(not ls) (values #f #f #f)] - [else - (define start-pos (lexer-state-start-pos ls)) - (insert c pos) ; temporarily insert c - (define m (backward-match (+ l pos) start-pos)) ; find matching open parens - (delete pos (+ l pos)) ; delete c - (define n ; now from the open parens find the *real* matching close parens - (and m (forward-match m (last-position)))) ; n is the position *after* the close - #;(printf "outer: ~a~n" (list pos n m (and n m (let-values ([(a b) (get-token-range (- n l))]) - (list a b))))) - (if n - (let-values ([(a b) (get-token-range (- n l))]) - (values a b (get-text a b))) - (find-next-outer-paren pos (cdr closers)))])])) + (let loop ([pos pos]) + (define after-ws (skip-whitespace pos 'forward #f)) + (cond + [after-ws + (define tok (classify-position after-ws)) + (define-values (a b) (get-token-range after-ws)) + (cond + [(eq? tok 'parenthesis) + (define str (get-text a b)) + (cond + [(member str closers) + (values a b str)] + [else + (define m (forward-match a (last-position))) + (cond + [m (loop m)] + [else (values #f #f #f)])])] + [(<= b (last-position)) + (loop b)] + [else + (values #f #f #f)])] + [else (values #f #f)]))) ;; returns the start and end positions of the next token at or after