diff --git a/scribble-doc/scribblings/scribble/class-diagrams.rkt b/scribble-doc/scribblings/scribble/class-diagrams.rkt index 1ea63a5cdb..8b9af15db5 100644 --- a/scribble-doc/scribblings/scribble/class-diagrams.rkt +++ b/scribble-doc/scribblings/scribble/class-diagrams.rkt @@ -117,18 +117,19 @@ (blank 0 (+ class-box-margin class-box-margin))) (cond [(and methods fields) - (let* ([top-spacer (mk-blank)] - [bottom-spacer (mk-blank)] - [main (vl-append name - top-spacer - (if (null? fields) - (blank 0 4) - (apply vl-append fields)) - bottom-spacer - (if (null? methods) - (blank 0 4) - (apply vl-append methods)))]) - (add-hline (add-hline (frame (inset main class-box-margin)) top-spacer) bottom-spacer))] + (define top-spacer (mk-blank)) + (define bottom-spacer (mk-blank)) + (define main + (vl-append name + top-spacer + (if (null? fields) + (blank 0 4) + (apply vl-append fields)) + bottom-spacer + (if (null? methods) + (blank 0 4) + (apply vl-append methods)))) + (add-hline (add-hline (frame (inset main class-box-margin)) top-spacer) bottom-spacer)] [fields (define top-spacer (mk-blank)) (define main @@ -350,36 +351,37 @@ [count 1] #:connect-dots [connect-dots connect-dots] #:dot-delta [dot-delta 0]) - (let ([going-down? (let-values ([(_1 start-y) (find-cc main0 start-field)] - [(_2 finish-y) (find-cc main0 finish-name)]) - (< start-y finish-y))]) - (define-values (main1 dot1) - (add-dot-delta (λ () (add-dot-left main0 start-class start-field)) - 0 - (if going-down? - dot-delta - (- dot-delta)))) - (define-values (main2 dot2) - (add-dot-delta (λ () (add-dot-left/space main1 start-class start-field count)) - (- dot-delta) - (if going-down? - dot-delta - (- dot-delta)))) - (define-values (main3 dot3) - (add-dot-delta (λ () (add-dot-left main2 finish-class finish-name)) - 0 - (if going-down? - (- dot-delta) - dot-delta))) - (define-values (main4 dot4) (add-dot-delta (λ () (add-dot-junction main3 dot2 dot3)) 0 0)) - (define-values (main5 dot5) (add-dot-left main4 finish-class finish-name)) - (define-values (main6 dot6) - (add-dot-delta - (λ () (add-dot-left main5 finish-class finish-name)) - -1 ;; just enough to get the arrowhead going the right direction; not enough to see the line - 0)) - - (connect-dots #t (connect-dots #f main6 dot1 dot2 dot4 dot3) dot6 dot5))) + (define going-down? + (let-values ([(_1 start-y) (find-cc main0 start-field)] + [(_2 finish-y) (find-cc main0 finish-name)]) + (< start-y finish-y))) + (define-values (main1 dot1) + (add-dot-delta (λ () (add-dot-left main0 start-class start-field)) + 0 + (if going-down? + dot-delta + (- dot-delta)))) + (define-values (main2 dot2) + (add-dot-delta (λ () (add-dot-left/space main1 start-class start-field count)) + (- dot-delta) + (if going-down? + dot-delta + (- dot-delta)))) + (define-values (main3 dot3) + (add-dot-delta (λ () (add-dot-left main2 finish-class finish-name)) + 0 + (if going-down? + (- dot-delta) + dot-delta))) + (define-values (main4 dot4) (add-dot-delta (λ () (add-dot-junction main3 dot2 dot3)) 0 0)) + (define-values (main5 dot5) (add-dot-left main4 finish-class finish-name)) + (define-values (main6 dot6) + (add-dot-delta + (λ () (add-dot-left main5 finish-class finish-name)) + -1 ;; just enough to get the arrowhead going the right direction; not enough to see the line + 0)) + + (connect-dots #t (connect-dots #f main6 dot1 dot2 dot4 dot3) dot6 dot5)) (define (left-top-reference main0 start-class diff --git a/scribble-doc/scribblings/scribble/struct-hierarchy.rkt b/scribble-doc/scribblings/scribble/struct-hierarchy.rkt index b70dd3f5bd..32aeab081e 100644 --- a/scribble-doc/scribblings/scribble/struct-hierarchy.rkt +++ b/scribble-doc/scribblings/scribble/struct-hierarchy.rkt @@ -315,20 +315,15 @@ (inset (panorama w/delayed-connections) 0 0 1 0)) (define (double f p0 a b c d [count 1]) - (let ([arrows1 (launder (f (ghost p0) a b c d count #:dot-delta 1))] - [arrows2 (launder (f (ghost p0) a b c d count #:dot-delta -1))]) - (cc-superimpose p0 - arrows1 - arrows2))) + (define arrows1 (launder (f (ghost p0) a b c d count #:dot-delta 1))) + (define arrows2 (launder (f (ghost p0) a b c d count #:dot-delta -1))) + (cc-superimpose p0 arrows1 arrows2)) (define (triple f p0 a b c d [count 1]) - (let ([arrows (launder (f (ghost p0) a b c d count))] - [up-arrows (launder (f (ghost p0) a b c d count #:dot-delta 2))] - [down-arrows (launder (f (ghost p0) a b c d count #:dot-delta -2))]) - (cc-superimpose p0 - arrows - up-arrows - down-arrows))) + (define arrows (launder (f (ghost p0) a b c d count))) + (define up-arrows (launder (f (ghost p0) a b c d count #:dot-delta 2))) + (define down-arrows (launder (f (ghost p0) a b c d count #:dot-delta -2))) + (cc-superimpose p0 arrows up-arrows down-arrows)) (define (connect-circly-dots show-arrowhead? main dot1 . dots) (let loop ([prev-dot dot1] @@ -343,38 +338,34 @@ ;; this is a hack -- it will only work with right-right-reference (define (connect-two-circly-dots pict dot1 dot2 arrowhead?) - (let ([base - (let*-values ([(sx sy) (cc-find pict dot1)] - [(raw-ex ey) (cc-find pict dot2)] - [(ex) (if arrowhead? - (+ raw-ex 2) - raw-ex)]) - (cc-superimpose - (dc - (λ (dc dx dy) - (let ([pen (send dc get-pen)]) - (send dc set-pen - type-link-color ;(send pen get-color) - (if (is-a? dc post-script-dc%) - 4 - 2) - 'dot) - (send dc draw-line - (+ dx sx) (+ dy sy) - (+ dx ex) (+ dy ey)) - (send dc set-pen pen))) - (pict-width pict) - (pict-height pict)) - pict))]) + (define base + (let*-values ([(sx sy) (cc-find pict dot1)] + [(raw-ex ey) (cc-find pict dot2)] + [(ex) (if arrowhead? + (+ raw-ex 2) + raw-ex)]) + (cc-superimpose (dc (λ (dc dx dy) + (let ([pen (send dc get-pen)]) + (send dc set-pen + type-link-color ;(send pen get-color) + (if (is-a? dc post-script-dc%) 4 2) + 'dot) + (send dc draw-line (+ dx sx) (+ dy sy) (+ dx ex) (+ dy ey)) + (send dc set-pen pen))) + (pict-width pict) + (pict-height pict)) + pict))) (if arrowhead? (pin-arrow-line field-arrowhead-size base - dot1 (λ (ignored1 ignored2) - (let-values ([(x y) (cc-find pict dot2)]) - (values (+ x 2) y))) - dot2 cc-find + dot1 + (λ (ignored1 ignored2) + (let-values ([(x y) (cc-find pict dot2)]) + (values (+ x 2) y))) + dot2 + cc-find #:color type-link-color) - base))) + base)) (define (dotted-right-right-reference p0 a b c d [count 1]) (right-right-reference p0 a b c d count #:connect-dots connect-circly-dots)) diff --git a/scribble-doc/scribblings/scribble/utils.rkt b/scribble-doc/scribblings/scribble/utils.rkt index ba0e748b63..dc9feabc28 100644 --- a/scribble-doc/scribblings/scribble/utils.rkt +++ b/scribble-doc/scribblings/scribble/utils.rkt @@ -88,16 +88,15 @@ (cdr (apply append (map (lambda (x) (list #f x)) r))) r)]) (make-table plain - (map (lambda (x) - (let ([@expr (if x - (litchar/lines (car x)) - "")] - [sexpr (if x - (racket:to-paragraph ((norm-spacing 0) (cadr x))) - "")] - [reads-as (if x reads-as "")]) - (map as-flow (list spacer @expr reads-as sexpr)))) - r)))])))) + (for/list ([x (in-list r)]) + (let ([@expr (if x + (litchar/lines (car x)) + "")] + [sexpr (if x + (racket:to-paragraph ((norm-spacing 0) (cadr x))) + "")] + [reads-as (if x reads-as "")]) + (map as-flow (list spacer @expr reads-as sexpr))))))])))) ;; stuff for the scribble/text examples diff --git a/scribble-lib/scribble/blueboxes.rkt b/scribble-lib/scribble/blueboxes.rkt index 5cd8b47cd5..6b8f3ae126 100644 --- a/scribble-lib/scribble/blueboxes.rkt +++ b/scribble-lib/scribble/blueboxes.rkt @@ -75,7 +75,7 @@ (port-count-lines! port) (file-position port (+ (car offset+len) (or offset 0))) (for/list ([i (in-range (cdr offset+len))]) - (read-line port))))))) + (read-line port 'any))))))) (cond [(not (andmap string? lines)) #f] [(null? lines) #f] @@ -87,7 +87,7 @@ (define (fetch-blueboxes-method-tags sym #:blueboxes-cache [cache (make-blueboxes-cache #f)]) (populate-cache! cache) (define ht (blueboxes-cache-method->tags cache)) - (or (and ht (hash-ref ht sym (λ () '()))) '())) + (or (and ht (hash-ref ht sym '())) '())) (define (populate-cache! cache) (define cache-content (blueboxes-cache-info-or-paths cache)) @@ -100,13 +100,12 @@ (define (compute-methods-table lst) (define meth-ht (make-hash)) (for ([a-bluebox-info (in-list lst)]) - (match a-bluebox-info - [(bluebox-info blueboxes.rktd offset tag-ht mod-time) - (when tag-ht - (for ([(tag val) (in-hash tag-ht)]) - (when (method-tag? tag) - (define-values (class/intf meth) (get-class/interface-and-method tag)) - (hash-set! meth-ht meth (cons tag (hash-ref meth-ht meth (λ () '())))))))])) + (match-define (bluebox-info blueboxes.rktd offset tag-ht mod-time) a-bluebox-info) + (when tag-ht + (for ([(tag val) (in-hash tag-ht)]) + (when (method-tag? tag) + (define-values (class/intf meth) (get-class/interface-and-method tag)) + (hash-set! meth-ht meth (cons tag (hash-ref meth-ht meth (λ () '())))))))) meth-ht) (define (build-blueboxes-cache blueboxes-dirs) @@ -119,12 +118,11 @@ a-bluebox-info))) (define (check-and-update-bluebox-info! a-bluebox-info) - (match a-bluebox-info - [(bluebox-info blueboxes.rktd offset tag-ht mod-time) - (when (or (not mod-time) - (and (file-exists? blueboxes.rktd) - (not (mod-time . = . (file-or-directory-modify-seconds blueboxes.rktd))))) - (populate-bluebox-info! a-bluebox-info))])) + (match-define (bluebox-info blueboxes.rktd offset tag-ht mod-time) a-bluebox-info) + (when (or (not mod-time) + (and (file-exists? blueboxes.rktd) + (not (mod-time . = . (file-or-directory-modify-seconds blueboxes.rktd))))) + (populate-bluebox-info! a-bluebox-info))) (define (populate-bluebox-info! a-bluebox-info) (define blueboxes.rktd (bluebox-info-blueboxes.rktd a-bluebox-info)) @@ -133,7 +131,7 @@ (call-with-input-file blueboxes.rktd (λ (port) (port-count-lines! port) - (define first-line (read-line port)) + (define first-line (read-line port 'any)) (define pos (file-position port)) (define desed (with-handlers ([exn:fail? (λ (x) diff --git a/scribble-lib/scribble/lp/lang/common.rkt b/scribble-lib/scribble/lp/lang/common.rkt index 396655a97b..dbf41dd7f9 100644 --- a/scribble-lib/scribble/lp/lang/common.rkt +++ b/scribble-lib/scribble/lp/lang/common.rkt @@ -79,16 +79,15 @@ (strip-comments (cdr body))] [(eq? ad 'code:blank) (strip-comments (cdr body))] - [(and (or (eq? ad 'code:hilite) - (eq? ad 'code:quote)) - (let* ([d (cdr body)] - [dd (if (syntax? d) - (syntax-e d) - d)]) - (and (pair? dd) - (or (null? (cdr dd)) - (and (syntax? (cdr dd)) - (null? (syntax-e (cdr dd)))))))) + [(cond + [(or (eq? ad 'code:hilite) (eq? ad 'code:quote)) + (define d (cdr body)) + (define dd + (if (syntax? d) + (syntax-e d) + d)) + (and (pair? dd) (or (null? (cdr dd)) (and (syntax? (cdr dd)) (null? (syntax-e (cdr dd))))))] + [else #f]) (define d (cdr body)) (define r (strip-comments (car (if (syntax? d) (syntax-e d) d)))) diff --git a/scribble-lib/scribble/text-render.rkt b/scribble-lib/scribble/text-render.rkt index 21b7998043..00fc5d720d 100644 --- a/scribble-lib/scribble/text-render.rkt +++ b/scribble-lib/scribble/text-render.rkt @@ -37,18 +37,14 @@ (define/override (render-part d ht) (let ([number (collected-info-number (part-collected-info d ht))]) (unless (part-style? d 'hidden) - (let ([s (format-number number '() #t)]) - (unless (null? s) - (printf "~a~a" - (car s) - (if (part-title-content d) - " " - ""))) - (when (part-title-content d) - (render-content (part-title-content d) d ht)) - (when (or (pair? number) (part-title-content d)) - (newline) - (newline)))) + (define s (format-number number '() #t)) + (unless (null? s) + (printf "~a~a" (car s) (if (part-title-content d) " " ""))) + (when (part-title-content d) + (render-content (part-title-content d) d ht)) + (when (or (pair? number) (part-title-content d)) + (newline) + (newline))) (render-flow (part-blocks d) d ht #f) (let loop ([pos 1] [secs (part-parts d)] @@ -78,26 +74,33 @@ null (let* ([strs (map (lambda (flows styles) (map (lambda (d style) - (if (eq? d 'cont) - d - (let ([o (open-output-string)]) - (define padding - (or (findf cell-padding-property? (style-properties style)) - (cell-padding-property 0 0 0 0))) - (define (int n) (inexact->exact (floor n))) - (parameterize ([current-indent 0] - [current-output-port o]) - (render-block d part ht #f)) - (define strs (regexp-split - #rx"\n" - (regexp-replace #rx"\n$" (get-output-string o) ""))) - (append - (make-list (int (cell-padding-property-top padding)) "") - (for/list ([str (in-list strs)]) - (string-append (make-string (int (cell-padding-property-left padding)) #\space) - str - (make-string (int (cell-padding-property-right padding)) #\space))) - (make-list (int (cell-padding-property-bottom padding)) ""))))) + (cond + [(eq? d 'cont) d] + [else + (define o (open-output-string)) + (define padding + (or (findf cell-padding-property? (style-properties style)) + (cell-padding-property 0 0 0 0))) + (define (int n) + (inexact->exact (floor n))) + (parameterize ([current-indent 0] + [current-output-port o]) + (render-block d part ht #f)) + (define strs + (regexp-split + #rx"\n" + (regexp-replace #rx"\n$" (get-output-string o) ""))) + (append + (make-list (int (cell-padding-property-top padding)) "") + (for/list ([str (in-list strs)]) + (string-append + (make-string (int (cell-padding-property-left padding)) + #\space) + str + (make-string (int (cell-padding-property-right padding)) + #\space))) + (make-list (int (cell-padding-property-bottom padding)) + ""))])) flows styles)) flowss diff --git a/scribble-lib/scriblib/gui-eval.rkt b/scribble-lib/scriblib/gui-eval.rkt index 1bd6567aaf..afbd28380e 100644 --- a/scribble-lib/scriblib/gui-eval.rkt +++ b/scribble-lib/scriblib/gui-eval.rkt @@ -78,21 +78,22 @@ log-file) (newline log-file) (flush-output log-file) - (let ([result (with-handlers ([exn:fail? (lambda (exn) (make-gui-exn (exn-message exn)))]) - ;; put the call to fixup-picts in the handlers - ;; so that errors in the user-supplied predicates & - ;; conversion functions show up in the rendered output - (fixup-picts (get-predicate?) - (get-render) - (get-get-width) - (get-get-height) - (eh ev catching-exns? expr)))]) - (write (serialize result) log-file) - (newline log-file) - (flush-output log-file) - (if (gui-exn? result) - (raise (make-exn:fail (gui-exn-message result) (current-continuation-marks))) - result))))] + (define result + (with-handlers ([exn:fail? (lambda (exn) (make-gui-exn (exn-message exn)))]) + ;; put the call to fixup-picts in the handlers + ;; so that errors in the user-supplied predicates & + ;; conversion functions show up in the rendered output + (fixup-picts (get-predicate?) + (get-render) + (get-get-width) + (get-get-height) + (eh ev catching-exns? expr)))) + (write (serialize result) log-file) + (newline log-file) + (flush-output log-file) + (if (gui-exn? result) + (raise (make-exn:fail (gui-exn-message result) (current-continuation-marks))) + result)))] [else (define log-file (with-handlers ([exn:fail:filesystem? (lambda (exn) (open-input-string ""))]) @@ -103,26 +104,23 @@ (if catching-exns? (raise exn) (void)))]) - (let ([v (read log-file)]) - (if (eof-object? v) - (error "expression not in log file") - (let ([v (deserialize v)]) - (if (equal? v - (if (syntax? expr) - (syntax->datum expr) - expr)) - (let ([v (read log-file)]) - (if (eof-object? v) - (error "expression result missing in log file") - (let ([v (deserialize v)]) - (if (gui-exn? v) - (raise (make-exn:fail (gui-exn-message v) - (current-continuation-marks))) - v)))) - (error 'mreval - "expression does not match log file: ~e versus: ~e" - expr - v))))))))])) + (define v (read log-file)) + (if (eof-object? v) + (error "expression not in log file") + (let ([v (deserialize v)]) + (if (equal? v + (if (syntax? expr) + (syntax->datum expr) + expr)) + (let ([v (read log-file)]) + (if (eof-object? v) + (error "expression result missing in log file") + (let ([v (deserialize v)]) + (if (gui-exn? v) + (raise (make-exn:fail (gui-exn-message v) + (current-continuation-marks))) + v)))) + (error 'mreval "expression does not match log file: ~e versus: ~e" expr v)))))))])) (define image-counter 0) @@ -139,13 +137,13 @@ (send pss set-mode 'file) (send pss set-file (path-replace-suffix fn #".pdf")) (parameterize ([(gui-eval 'current-ps-setup) pss]) - (let ([xb (box 0)] - [yb (box 0)]) - (send pss get-scaling xb yb) - (new (gui-eval 'pdf-dc%) - [interactive #f] - [width (* (unbox xb) (get-width v))] - [height (* (unbox yb) (get-height v))]))))]) + (define xb (box 0)) + (define yb (box 0)) + (send pss get-scaling xb yb) + (new (gui-eval 'pdf-dc%) + [interactive #f] + [width (* (unbox xb) (get-width v))] + [height (* (unbox yb) (get-height v))])))]) (send dc start-doc "Image") (send dc start-page) (render v dc 0 0) diff --git a/scribble-test/tests/scribble/reader.rkt b/scribble-test/tests/scribble/reader.rkt index ed0627b692..ca7afa903a 100644 --- a/scribble-test/tests/scribble/reader.rkt +++ b/scribble-test/tests/scribble/reader.rkt @@ -847,9 +847,9 @@ END-OF-TESTS (values (read-all x inside-reader #t) (read-all y read))) (define (x . (mk-eval-test syntax-reader) . y) - (define r (void)) - (for ([x (read-all x (lambda (i) (syntax-reader 'test i)))]) - (set! r (call-with-values (lambda () (eval x ns)) list))) + (define r + (for/fold ([r (void)]) ([x (read-all x (lambda (i) (syntax-reader 'test i)))]) + (call-with-values (lambda () (eval x ns)) list))) (values r (read-all y read))) (define (x . (mk-syntax-test syntax-reader) . y) @@ -949,12 +949,12 @@ END-OF-TESTS (regexp-match #px"^(.*\\S)\\s+(-\\S+->)\\s+(\\S.*)$" t))) (unless (and m (= 4 (length m))) (error 'bad-test "~a" t)) - (let-values ([(x y) ((string->tester (caddr m)) (cadr m) (cadddr m))]) - (test #:failure-message (format "bad result in\n ~a\n results:\n ~s != ~s" - (regexp-replace* #rx"\n" t "\n ") - x - y) - (matching? x y)))))) + (define-values (x y) ((string->tester (caddr m)) (cadr m) (cadddr m))) + (test #:failure-message (format "bad result in\n ~a\n results:\n ~s != ~s" + (regexp-replace* #rx"\n" t "\n ") + x + y) + (matching? x y))))) ;; Check static versus dynamic readtable for command (dynamic when "c" in the ;; name) and datum (dynamic when "d" in the name) parts: diff --git a/scribble-text-lib/scribble/text/output.rkt b/scribble-text-lib/scribble/text/output.rkt index d2480f4034..d72a65f439 100644 --- a/scribble-text-lib/scribble/text/output.rkt +++ b/scribble-text-lib/scribble/text/output.rkt @@ -57,11 +57,14 @@ 0)) ;; combines a prefix with a target column to get to (define (pfx+col pfx) - (and pfx (let ([col (getcol)]) - (cond [(number? pfx) (max pfx col)] - [(>= (string-length pfx) col) pfx] - [else (string-append - pfx (make-spaces (- col (string-length pfx))))])))) + (cond + [pfx + (define col (getcol)) + (cond + [(number? pfx) (max pfx col)] + [(>= (string-length pfx) col) pfx] + [else (string-append pfx (make-spaces (- col (string-length pfx))))])] + [else #f])) ;; adds two prefixes (define (pfx+ pfx1 pfx2) (and pfx1 pfx2