diff --git a/scribble-lib/scribble/racket.rkt b/scribble-lib/scribble/racket.rkt index fd8ab4a52a..aeef695ca4 100644 --- a/scribble-lib/scribble/racket.rkt +++ b/scribble-lib/scribble/racket.rkt @@ -673,11 +673,30 @@ (unless (and expr? (zero? quote-depth)) (let ([vec (syntax-e c)]) (out "#" p-color) + ;; A vector literal looks like "#( x y z )". + ;; At this point we want to advance src-col past "#". + ;; However, after this we will need to advance src-loc to + ;; account for "(" and spaces to reach the first element. + ;; The "(" component is handled by unconditionally adding 1 below. + ;; For simplicity, we will handle the spaces component right now + ;; along with advancing src-col past "#", + ;; even though it's technically not the right place to do it. (if (zero? (vector-length vec)) - (set! src-col (+ src-col (- (syntax-span c) 2))) - (set! src-col (+ src-col (- (syntax-column (vector-ref vec 0)) - (syntax-column c) - 1))))))) + ;; assume no srcloc means "#()" + (set! src-col + (+ src-col + (- (or (syntax-span c) 3) 2))) + ;; assume no srcloc means "#(x ...)"; + ;; first element appears at the third character + (set! src-col + (+ src-col + (cond + [(and (syntax-column (vector-ref vec 0)) + (syntax-column c)) + (- (syntax-column (vector-ref vec 0)) + (syntax-column c) + 1)] + [else 1]))))))) (when (struct? (syntax-e c)) (unless (and expr? (zero? quote-depth)) (out "#s" p-color) diff --git a/scribble-test/tests/scribble/docs/text.scrbl b/scribble-test/tests/scribble/docs/text.scrbl index 051cfbbf07..14cc373c1b 100644 --- a/scribble-test/tests/scribble/docs/text.scrbl +++ b/scribble-test/tests/scribble/docs/text.scrbl @@ -24,6 +24,22 @@ Here's some Racket code: (x x) ] +We should be able to use @racket[racketblock] without having source location. + +@(require (for-syntax racket/base)) + +@(define-syntax (test stx) + (with-syntax ([(xs ...) '(1 2 3 4)]) + #'@racketblock[#(xs ...) + (xs ...) + '(xs ...)])) + +@(test) + +Spaces inside lists should be preserved. + +@racketblock[( a b c)] + @subsection{Another Subsection} @defmodule[racket/base] diff --git a/scribble-test/tests/scribble/docs/text.txt b/scribble-test/tests/scribble/docs/text.txt index 5d481d97ac..5e4a6b19f0 100644 --- a/scribble-test/tests/scribble/docs/text.txt +++ b/scribble-test/tests/scribble/docs/text.txt @@ -18,6 +18,16 @@ Here’s some Racket code:                (x x))) (x x) +We should be able to use racketblock without having source location. + + #(1 2 3 4) + (1 2 3 4) + '(1 2 3 4) + +Spaces inside lists should be preserved. + + ( a   b   c) + 1.2. Another Subsection  (require racket/base) package: base