diff --git a/drracket-tool-lib/drracket/private/standalone-module-browser.rkt b/drracket-tool-lib/drracket/private/standalone-module-browser.rkt index 807be068e..fdc4494fb 100644 --- a/drracket-tool-lib/drracket/private/standalone-module-browser.rkt +++ b/drracket-tool-lib/drracket/private/standalone-module-browser.rkt @@ -1272,7 +1272,8 @@ [(null? ms) (substring short-name 0 (min 2 (string-length short-name)))] [else (apply string-append - (cons (substring short-name 0 1) (map (λ (x) (substring x 1 2)) ms)))])])] + (substring short-name 0 1) + (map (λ (x) (substring x 1 2)) ms))])])] [(long) word] [(very-long) (string-append word ": " (format "~s" require-phases))])) last-name])) diff --git a/drracket/browser/private/bullet.rkt b/drracket/browser/private/bullet.rkt index 3ec528198..554bdaa9d 100644 --- a/drracket/browser/private/bullet.rkt +++ b/drracket/browser/private/bullet.rkt @@ -11,8 +11,7 @@ (define bullet-size (make-parameter - (let ([s (send (send (send (make-object text%) get-style-list) basic-style) - get-size)]) + (let ([s (send+ (make-object text%) (get-style-list) (basic-style) (get-size))]) (max 7 (quotient s 2))))) (define (get-bullet-width) @@ -51,16 +50,15 @@ [(0) (values (lambda (x y w h) (send dc draw-ellipse x y w h)) #t)] [(1) (values (lambda (x y w h) (send dc draw-ellipse x y w h)) #f)] [else (values (lambda (x y w h) (send dc draw-rectangle x y w h)) #f)])]) - (let ([b (send dc get-brush)]) - (send dc set-brush - (if solid? - (send the-brush-list - find-or-create-brush - (send (send dc get-pen) get-color) - 'solid) - transparent-brush)) - (draw x y bsize bsize) - (send dc set-brush b)))))] + (define b (send dc get-brush)) + (send dc set-brush + (if solid? + (send the-brush-list find-or-create-brush + (send (send dc get-pen) get-color) + 'solid) + transparent-brush)) + (draw x y bsize bsize) + (send dc set-brush b))))] [define/override copy (lambda () (make-object bullet-snip% depth))] @@ -69,11 +67,10 @@ (send stream put depth))] [define/override get-text (lambda (offset num flattened?) - (if (< num 1) - "" - (if flattened? - "* " - "*")))] + (cond + [(< num 1) ""] + [flattened? "* "] + [else "*"]))] (super-new) (set-snipclass bullet-snip-class) (set-count 1))) diff --git a/drracket/browser/private/html.rkt b/drracket/browser/private/html.rkt index 3514dd669..e482f3b6f 100644 --- a/drracket/browser/private/html.rkt +++ b/drracket/browser/private/html.rkt @@ -118,19 +118,17 @@ (super on-event dc x y editor-x editor-y evt)) (define/override (adjust-cursor dc x y editor-x editor-y evt) - (let ([snipx (- (send evt get-x) x)] - [snipy (- (send evt get-y) y)]) - (if (find-rect snipx snipy) - finger-cursor - #f))) + (define snipx (- (send evt get-x) x)) + (define snipy (- (send evt get-y) y)) + (if (find-rect snipx snipy) finger-cursor #f)) ;; warning: buggy. This doesn't actually copy the bitmap ;; over because there's no get-bitmap method for image-snip% ;; at the time of this writing. (define/override (copy) - (let ([cp (new image-map-snip% (html-text html-text))]) - (send cp set-key key) - (send cp set-rects rects))) + (define cp (new image-map-snip% (html-text html-text))) + (send cp set-key key) + (send cp set-rects rects)) (super-make-object) @@ -143,9 +141,9 @@ ;; (define (make-racket-color-delta col) - (let ([d (make-object style-delta%)]) - (send d set-delta-foreground col) - d)) + (define d (make-object style-delta%)) + (send d set-delta-foreground col) + d) (define racket-code-delta (make-racket-color-delta "brown")) (define racket-code-delta/keyword @@ -163,17 +161,17 @@ (define current-style-class (make-parameter null)) (define (lookup-class-delta class) - (let ([class-path (cons class (current-style-class))]) - (cond - [(sub-path? class-path '("racket")) racket-code-delta] - [(sub-path? class-path '("keyword" "racket")) racket-code-delta/keyword] - [(sub-path? class-path '("variable" "racket")) racket-code-delta/variable] - [(sub-path? class-path '("global" "racket")) racket-code-delta/global] - [(or (sub-path? class-path '("selfeval" "racket")) - (sub-path? class-path '("racketresponse"))) racket-code-delta/selfeval] - [(sub-path? class-path '("comment" "racket")) racket-code-delta/comment] - [(sub-path? class-path '("navigation")) navigation-delta] - [else #f]))) + (define class-path (cons class (current-style-class))) + (cond + [(sub-path? class-path '("racket")) racket-code-delta] + [(sub-path? class-path '("keyword" "racket")) racket-code-delta/keyword] + [(sub-path? class-path '("variable" "racket")) racket-code-delta/variable] + [(sub-path? class-path '("global" "racket")) racket-code-delta/global] + [(or (sub-path? class-path '("selfeval" "racket")) (sub-path? class-path '("racketresponse"))) + racket-code-delta/selfeval] + [(sub-path? class-path '("comment" "racket")) racket-code-delta/comment] + [(sub-path? class-path '("navigation")) navigation-delta] + [else #f])) (define (sub-path? a b) (cond @@ -193,99 +191,85 @@ (define re:hexcolor (regexp "^#([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])$")) -(define color-string->color - (lambda (str) - (let ([m (regexp-match re:hexcolor str)]) - (if m - (make-object color% - (string->number (cadr m) 16) - (string->number (caddr m) 16) - (string->number (cadddr m) 16)) - (send the-color-database find-color str))))) +(define (color-string->color str) + (let ([m (regexp-match re:hexcolor str)]) + (if m + (make-object color% + (string->number (cadr m) 16) + (string->number (caddr m) 16) + (string->number (cadddr m) 16)) + (send the-color-database find-color str)))) (define html-eval-ok (make-parameter #t)) (define html-img-ok (make-parameter #t)) (define (get-bitmap-from-url url) - (if (html-img-ok) - (let ([tmp-filename (make-temporary-file "rktguiimg~a")]) - (load-status #t "image" url) - (call-with-output-file* tmp-filename - (lambda (op) - (with-handlers ([exn:fail? - (lambda (x) - (printf "exn.9 ~s\n" (and (exn? x) - (exn-message x))) - (void))]) - (call/input-url - url - get-pure-port - (lambda (ip) - (copy-port ip op))))) - #:exists 'truncate) - (pop-status) - (let ([bitmap (make-object bitmap% tmp-filename)]) - (with-handlers ([exn:fail? - (lambda (x) - (message-box "Warning" - (format "Could not delete file ~s\n\n~a" - tmp-filename - (if (exn? x) - (exn-message x) - x))))]) - (delete-file tmp-filename)) - (if (send bitmap ok?) - bitmap - #f))) - #f)) + (and (html-img-ok) + (let ([tmp-filename (make-temporary-file "rktguiimg~a")]) + (load-status #t "image" url) + (call-with-output-file* + tmp-filename + (lambda (op) + (with-handlers ([exn:fail? (lambda (x) + (printf "exn.9 ~s\n" (and (exn? x) (exn-message x))) + (void))]) + (call/input-url url get-pure-port (lambda (ip) (copy-port ip op))))) + #:exists 'truncate) + (pop-status) + (let ([bitmap (make-object bitmap% tmp-filename)]) + (with-handlers ([exn:fail? (lambda (x) + (message-box "Warning" + (format "Could not delete file ~s\n\n~a" + tmp-filename + (if (exn? x) + (exn-message x) + x))))]) + (delete-file tmp-filename)) + (if (send bitmap ok?) bitmap #f))))) ;; cache-bitmap : string -> (is-a?/c bitmap%) (define (cache-bitmap url) - (let ([url-string (url->string url)]) - (let loop ([n 0]) - (cond - [(= n NUM-CACHED) - ;; Look for item to uncache - (vector-set! cached-use 0 (max 0 (sub1 (vector-ref cached-use 0)))) - (let ([m (let loop ([n 1][m (vector-ref cached-use 0)]) - (if (= n NUM-CACHED) - m - (begin - (vector-set! cached-use n (max 0 (sub1 (vector-ref cached-use n)))) - (loop (add1 n) (min m (vector-ref cached-use n))))))]) - (let loop ([n 0]) - (if (= (vector-ref cached-use n) m) - (let ([bitmap (get-bitmap-from-url url)]) - (cond + (define url-string (url->string url)) + (let loop ([n 0]) + (cond + [(= n NUM-CACHED) + ;; Look for item to uncache + (vector-set! cached-use 0 (max 0 (sub1 (vector-ref cached-use 0)))) + (let ([m (let loop ([n 1] + [m (vector-ref cached-use 0)]) + (if (= n NUM-CACHED) + m + (begin + (vector-set! cached-use n (max 0 (sub1 (vector-ref cached-use n)))) + (loop (add1 n) (min m (vector-ref cached-use n))))))]) + (let loop ([n 0]) + (if (= (vector-ref cached-use n) m) + (let ([bitmap (get-bitmap-from-url url)]) + (cond [bitmap (vector-set! cached n bitmap) (vector-set! cached-name n url-string) (vector-set! cached-use n 5) bitmap] [else #f])) - (loop (add1 n)))))] - [(equal? url-string (vector-ref cached-name n)) - (vector-set! cached-use n (min 10 (add1 (vector-ref cached-use n)))) - (vector-ref cached n)] - [else - (loop (add1 n))])))) + (loop (add1 n)))))] + [(equal? url-string (vector-ref cached-name n)) + (vector-set! cached-use n (min 10 (add1 (vector-ref cached-use n)))) + (vector-ref cached n)] + [else (loop (add1 n))]))) (define (update-image-maps image-map-snips image-maps) - (for-each - (lambda (image-map-snip) - (let ([image-map-key (send image-map-snip get-key)]) - (let loop ([image-maps image-maps]) - (cond - [(null? image-maps) (void)] - [else - (let* ([image-map (car image-maps)] - [name (get-field image-map 'name)]) - (if (and name - (equal? (format "#~a" name) - (send image-map-snip get-key))) - (find/add-areas image-map-snip image-map) - (loop (cdr image-maps))))])))) - image-map-snips)) + (for ([image-map-snip (in-list image-map-snips)]) + (send image-map-snip get-key) + (let loop ([image-maps image-maps]) + (cond + [(null? image-maps) (void)] + [else + (let* ([image-map (car image-maps)] + [name (get-field image-map 'name)]) + (if (and name (equal? (format "#~a" name) (send image-map-snip get-key))) + (find/add-areas image-map-snip image-map) + (loop (cdr image-maps))))])))) (define (find/add-areas image-map-snip image-map) (let loop ([sexp image-map]) @@ -305,28 +289,25 @@ ;; matches the above, it is interprted propoerly; ;; otherwise silently nothing happens. (define (add-area image-map-snip sexp) - (let ([shape #f] - [coords #f] - [href #f]) - (let loop ([sexp sexp]) - (cond - [(pair? sexp) - (let ([fst (car sexp)]) - (when (and (pair? fst) - (symbol? (car fst)) - (pair? (cdr fst)) - (string? (cadr fst))) - (case (car fst) - [(shape) (set! shape (cadr fst))] - [(coords) (set! coords (cadr fst))] - [(href) (set! href (cadr fst))] - [else (void)])) - (loop (cdr sexp)))] - [else (void)])) - (when (and shape coords href) - (let ([p-coords (parse-coords coords)]) - (when p-coords - (send image-map-snip add-area shape p-coords href)))))) + (define shape #f) + (define coords #f) + (define href #f) + (let loop ([sexp sexp]) + (cond + [(pair? sexp) + (let ([fst (car sexp)]) + (when (and (pair? fst) (symbol? (car fst)) (pair? (cdr fst)) (string? (cadr fst))) + (case (car fst) + [(shape) (set! shape (cadr fst))] + [(coords) (set! coords (cadr fst))] + [(href) (set! href (cadr fst))] + [else (void)])) + (loop (cdr sexp)))] + [else (void)])) + (when (and shape coords href) + (let ([p-coords (parse-coords coords)]) + (when p-coords + (send image-map-snip add-area shape p-coords href))))) ;; parse-coords : string -> (listof number) ;; separates out a bunch of comma separated numbers in a string @@ -337,10 +318,9 @@ [(regexp-match #rx"^[ \t\n]*([0-9]+)[ \t\n]*,(.*)$" str) => (lambda (m) - (let ([num (cadr m)] - [rst (caddr m)]) - (cons (string->number num) - (loop rst))))] + (define num (cadr m)) + (define rst (caddr m)) + (cons (string->number num) (loop rst)))] [(regexp-match #rx"^[ \t\n]*([0-9]+)[ \t\n]*" str) => (lambda (m) @@ -348,21 +328,14 @@ [else null]))) (define (make-get-field str) - (let ([s (apply - string-append - (map - (lambda (c) - (format "[~a~a]" - (char-upcase c) - (char-downcase c))) - (string->list str)))] - [spc (string #\space #\tab #\newline #\return #\vtab)]) - (let ([re:plain (regexp (format "(^|[~a])~a[~a]*=[~a]*([^~a]*)" spc s spc spc spc))] - [re:quote (regexp (format "(^|[~a])~a[~a]*=[~a]*\"([^\"]*)\"" spc s spc spc))]) - (lambda (args) - (let ([m (or (regexp-match re:quote args) - (regexp-match re:plain args))]) - (and m (caddr m))))))) + (define s + (apply string-append + (map (lambda (c) (format "[~a~a]" (char-upcase c) (char-downcase c))) (string->list str)))) + (define spc (string #\space #\tab #\newline #\return #\vtab)) + (define re:plain (regexp (format "(^|[~a])~a[~a]*=[~a]*([^~a]*)" spc s spc spc spc))) + (define re:quote (regexp (format "(^|[~a])~a[~a]*=[~a]*\"([^\"]*)\"" spc s spc spc))) + (lambda (args) + (let ([m (or (regexp-match re:quote args) (regexp-match re:plain args))]) (and m (caddr m))))) (define (get-field e name) (let ([a (assq name (cadr e))]) diff --git a/drracket/browser/private/option-snip.rkt b/drracket/browser/private/option-snip.rkt index 4d3610dd1..caaba6064 100644 --- a/drracket/browser/private/option-snip.rkt +++ b/drracket/browser/private/option-snip.rkt @@ -52,19 +52,18 @@ (unless w (define font (send (get-style) get-font)) (define w+h+ds - (map (lambda (o) - (let-values ([(tw th td ta) (send dc get-text-extent (car o) font)]) - (list tw th td))) - options)) - (if (null? w+h+ds) - (begin - (set! w 10) - (set! h 10) - (set! d 2)) - (begin - (set! w (+ (* 2 inset) arrow-sep 2 (* 2 arrow-height) (apply max (map car w+h+ds)))) - (set! h (+ (* 2 inset) 1 (apply max arrow-height (map cadr w+h+ds)))) - (set! d (+ inset 1 (apply max (map caddr w+h+ds))))))) + (for/list ([o (in-list options)]) + (define-values (tw th td ta) (send dc get-text-extent (car o) font)) + (list tw th td))) + (cond + [(null? w+h+ds) + (set! w 10) + (set! h 10) + (set! d 2)] + [else + (set! w (+ (* 2 inset) arrow-sep 2 (* 2 arrow-height) (apply max (map car w+h+ds)))) + (set! h (+ (* 2 inset) 1 (apply max arrow-height (map cadr w+h+ds)))) + (set! d (+ inset 1 (apply max (map caddr w+h+ds))))])) (when hbox (set-box! hbox h)) (when wbox @@ -101,16 +100,15 @@ [on-event (lambda (dc x y editorx editory event) (when (send event button-down?) (define popup (make-object popup-menu%)) - (for-each (lambda (o) - (make-object menu-item% - (car o) - popup - (lambda (i e) - (set! current-option o) - (let ([a (get-admin)]) - (when a - (send a needs-update this 0 0 w h)))))) - options) + (for ([o (in-list options)]) + (make-object menu-item% + (car o) + popup + (lambda (i e) + (set! current-option o) + (let ([a (get-admin)]) + (when a + (send a needs-update this 0 0 w h)))))) (define a (get-admin)) (when a (send a popup-menu popup this 0 0))))] diff --git a/drracket/gui-debugger/debug-tool.rkt b/drracket/gui-debugger/debug-tool.rkt index 722ddee82..7a5f94f7d 100644 --- a/drracket/gui-debugger/debug-tool.rkt +++ b/drracket/gui-debugger/debug-tool.rkt @@ -486,26 +486,26 @@ (when (and (send (get-tab) debug?) (not before)) ;; render breakpoints (let ([breakpoints (send (get-tab) get-breakpoints)]) - (for ([(pos enabled?) (in-hash breakpoints)]) - (when (and (>= pos 0) (or enabled? (and mouse-over-pos (= mouse-over-pos pos)))) - (define-values (xl yl xr yr) (find-char-box this pos)) - (define diameter (- xr xl)) - (define yoff (/ (- yr yl diameter) 2)) - (define op (send dc get-pen)) - (define ob (send dc get-brush)) - (case enabled? - [(#t) - (send dc set-pen bp-pen) - (send dc set-brush bp-brush)] - [(#f) - (send dc set-pen bp-mo-pen) - (send dc set-brush bp-mo-brush)] - [else - (send dc set-pen bp-tmp-pen) - (send dc set-brush bp-tmp-brush)]) - (send dc draw-ellipse (+ xl dx) (+ yl dy yoff) diameter diameter) - (send dc set-pen op) - (send dc set-brush ob)))) + (for ([(pos enabled?) (in-hash breakpoints)] + #:when (and (>= pos 0) (or enabled? (and mouse-over-pos (= mouse-over-pos pos))))) + (define-values (xl yl xr yr) (find-char-box this pos)) + (define diameter (- xr xl)) + (define yoff (/ (- yr yl diameter) 2)) + (define op (send dc get-pen)) + (define ob (send dc get-brush)) + (case enabled? + [(#t) + (send dc set-pen bp-pen) + (send dc set-brush bp-brush)] + [(#f) + (send dc set-pen bp-mo-pen) + (send dc set-brush bp-mo-brush)] + [else + (send dc set-pen bp-tmp-pen) + (send dc set-brush bp-tmp-brush)]) + (send dc draw-ellipse (+ xl dx) (+ yl dy yoff) diameter diameter) + (send dc set-pen op) + (send dc set-brush ob))) ;; mark the boundaries of the current stack frame ;; unless we're at the end of the expression and looking at the top frame, ;; in which case just mark the current location @@ -1234,21 +1234,20 @@ (define/public (register-stack-frames frames already-stopped?) (define trimmed-exprs - (map (lambda (frame) - (let ([expr (mark-source frame)]) - (cond - ; should succeed unless the user closes a secondary tab during debugging - [(and expr (filename->defs (syntax-source expr))) - => - (lambda (defs) - (trim-expr-str (if (syntax-position expr) - (send defs get-text - (sub1 (syntax-position expr)) - (+ -1 (syntax-position expr) (syntax-span expr))) - "??") - 15))] - ["??"]))) - frames)) + (for/list ([frame (in-list frames)]) + (define expr (mark-source frame)) + (cond + ; should succeed unless the user closes a secondary tab during debugging + [(and expr (filename->defs (syntax-source expr))) + => + (lambda (defs) + (trim-expr-str (if (syntax-position expr) + (send defs get-text + (sub1 (syntax-position expr)) + (+ -1 (syntax-position expr) (syntax-span expr))) + "??") + 15))] + ["??"]))) (send stack-frames begin-edit-sequence) (send stack-frames lock #f) (unless already-stopped?