Skip to content

Commit 7577bed

Browse files
committed
improve rendering for curried procedures
When the header of a function with curried arguments needs to be broken across lines, the indentation for arguments in the second layer was misleading when there are arguments in the first layer.
1 parent fc3cac8 commit 7577bed

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

scribble-lib/scribble/private/manual-proc.rkt

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@
568568
(to-flow ((arg->elem #f) (car args) (next-args-depth (cdr args))))
569569
not-end)
570570
(list* 'cont 'cont not-end)))
571-
(let loop ([args (if one-ok? (cdr args) args)])
571+
(let loop ([args (if one-ok? (cdr args) args)] [prev-depth (if one-ok? (arg-depth (car args)) 0)])
572572
(cond
573573
[(null? args) null]
574574
[else
@@ -577,14 +577,30 @@
577577
(arg-special? (cadr args))
578578
(not (eq? '_...superclass-args...
579579
(arg-id (cadr args)))))))
580+
(define (combine-for-depth left opt arg end)
581+
(if ((arg-depth (car args)) . < . prev-depth)
582+
;; when a curried agument starts on a new line,
583+
;; don't intent like non-curried arguments
584+
(list* (to-flow (list spacer
585+
(if (arg-starts-optional? (car args))
586+
opt
587+
null)
588+
arg))
589+
'cont
590+
'cont
591+
end)
592+
(list* left
593+
(to-flow opt)
594+
(to-flow arg)
595+
end)))
580596
(cons
581-
(list*
597+
(combine-for-depth
582598
(if (eq? mode 'new)
583599
(flow-spacer/n 3)
584600
flow-spacer)
585601
(if (arg-starts-optional? (car args))
586-
(to-flow (make-element #f (list spacer (racketoptionalfont "["))))
587-
flow-spacer)
602+
(make-element #f (list spacer (racketoptionalfont "[")))
603+
spacer)
588604
(let ([a ((arg->elem #f) (car args) (next-args-depth (cdr args)))]
589605
[next (if dots-next?
590606
(make-element
@@ -593,21 +609,21 @@
593609
(cadr args)
594610
(next-args-depth (cddr args)))))
595611
"")])
596-
(to-flow
597-
(cond
598-
[(null? ((if dots-next? cddr cdr) args))
599-
(make-element
600-
#f
601-
(list a next (racketparenfont ")")))]
602-
[(equal? next "") a]
603-
[else
604-
(make-element #f (list a next))])))
612+
(cond
613+
[(null? ((if dots-next? cddr cdr) args))
614+
(make-element
615+
#f
616+
(list a next (racketparenfont ")")))]
617+
[(equal? next "") a]
618+
[else
619+
(make-element #f (list a next))]))
605620
(if (and (null? ((if dots-next? cddr cdr) args))
606621
(not result-next-line?))
607622
end
608623
not-end))
609624
(loop ((if dots-next? cddr cdr)
610-
args)))])))))])))))
625+
args)
626+
(max prev-depth (arg-depth (car args)))))])))))])))))
611627
(if result-next-line?
612628
(list (list (make-flow (top-align
613629
make-table-if-necessary

0 commit comments

Comments
 (0)