Scribble: prevent linebreaks after leading hyphens on identifiers
original commit: 7852408f8afa77b2e26917995a1f49b9868d3cd4
This commit is contained in:
parent
ab1fe071d1
commit
1624b95c70
|
@ -94,17 +94,32 @@
|
||||||
|
|
||||||
(define-struct (spaces element) (cnt))
|
(define-struct (spaces element) (cnt))
|
||||||
|
|
||||||
(define (literalize-spaces i)
|
;; We really don't want leading hypens (or minus signs) to
|
||||||
|
;; create a line break after the hyphen. For interior hyphens,
|
||||||
|
;; line breaking is usually fine.
|
||||||
|
(define (nonbreak-leading-hyphens s)
|
||||||
|
(let ([m (regexp-match-positions #rx"^-+" s)])
|
||||||
|
(if m
|
||||||
|
(if (= (cdar m) (string-length s))
|
||||||
|
(make-element 'no-break s)
|
||||||
|
(let ([len (add1 (cdar m))])
|
||||||
|
(make-element #f (list (make-element 'no-break (substring s 0 len))
|
||||||
|
(substring s len)))))
|
||||||
|
s)))
|
||||||
|
|
||||||
|
(define (literalize-spaces i [leading? #f])
|
||||||
(let ([m (regexp-match-positions #rx" +" i)])
|
(let ([m (regexp-match-positions #rx" +" i)])
|
||||||
(if m
|
(if m
|
||||||
(let ([cnt (- (cdar m) (caar m))])
|
(let ([cnt (- (cdar m) (caar m))])
|
||||||
(make-spaces #f
|
(make-spaces #f
|
||||||
(list
|
(list
|
||||||
(literalize-spaces (substring i 0 (caar m)))
|
(literalize-spaces (substring i 0 (caar m)) #t)
|
||||||
(hspace cnt)
|
(hspace cnt)
|
||||||
(literalize-spaces (substring i (cdar m))))
|
(literalize-spaces (substring i (cdar m))))
|
||||||
cnt))
|
cnt))
|
||||||
i)))
|
(if leading?
|
||||||
|
(nonbreak-leading-hyphens i)
|
||||||
|
i))))
|
||||||
|
|
||||||
|
|
||||||
(define line-breakable-space (make-element 'tt " "))
|
(define line-breakable-space (make-element 'tt " "))
|
||||||
|
@ -139,9 +154,9 @@
|
||||||
(list
|
(list
|
||||||
(case (car tag)
|
(case (car tag)
|
||||||
[(form)
|
[(form)
|
||||||
(make-link-element syntax-link-color (list s) tag)]
|
(make-link-element syntax-link-color (nonbreak-leading-hyphens s) tag)]
|
||||||
[else
|
[else
|
||||||
(make-link-element value-link-color (list s) tag)]))
|
(make-link-element value-link-color (nonbreak-leading-hyphens s) tag)]))
|
||||||
(list
|
(list
|
||||||
(make-element "badlink"
|
(make-element "badlink"
|
||||||
(make-element value-link-color s))))))
|
(make-element value-link-color s))))))
|
||||||
|
@ -225,8 +240,8 @@
|
||||||
(not (or it? is-var?)))
|
(not (or it? is-var?)))
|
||||||
(if (pair? (identifier-label-binding c))
|
(if (pair? (identifier-label-binding c))
|
||||||
(make-id-element c s)
|
(make-id-element c s)
|
||||||
s)
|
(nonbreak-leading-hyphens s))
|
||||||
(literalize-spaces s))
|
(literalize-spaces s #t))
|
||||||
(cond
|
(cond
|
||||||
[(positive? quote-depth) value-color]
|
[(positive? quote-depth) value-color]
|
||||||
[(let ([v (syntax-e c)])
|
[(let ([v (syntax-e c)])
|
||||||
|
|
Loading…
Reference in New Issue
Block a user