mirror of
https://git.savannah.gnu.org/git/guix.git
synced 2025-02-07 11:29:59 +01:00
style: For 'let' and similar forms, emit one binding per line.
Previously, 'let' bindings could be rendered like this: (let ((x 1) (y 2) (z 3)) ...) With this change, each bindings goes in its own line. Partly fixes <https://issues.guix.gnu.org/56297>. Reported by Maxime Devos <maximedevos@telenet.be>. * guix/scripts/style.scm (pretty-print-with-comments)[list-of-lists?]: New procedure. Use it. * tests/style.scm: Add tests with 'let' and 'substitute-keyword-arguments'.
This commit is contained in:
parent
3348e485b7
commit
8d9291bd2c
2 changed files with 31 additions and 1 deletions
|
@ -272,6 +272,16 @@ included in the output.
|
||||||
Lists longer than LONG-LIST are written as one element per line. Comments are
|
Lists longer than LONG-LIST are written as one element per line. Comments are
|
||||||
passed through FORMAT-COMMENT before being emitted; a useful value for
|
passed through FORMAT-COMMENT before being emitted; a useful value for
|
||||||
FORMAT-COMMENT is 'canonicalize-comment'."
|
FORMAT-COMMENT is 'canonicalize-comment'."
|
||||||
|
(define (list-of-lists? head tail)
|
||||||
|
;; Return true if HEAD and TAIL denote a list of lists--e.g., a list of
|
||||||
|
;; 'let' bindings.
|
||||||
|
(match head
|
||||||
|
((thing _ ...) ;proper list
|
||||||
|
(and (not (memq thing
|
||||||
|
'(quote quasiquote unquote unquote-splicing)))
|
||||||
|
(pair? tail)))
|
||||||
|
(_ #f)))
|
||||||
|
|
||||||
(let loop ((indent indent)
|
(let loop ((indent indent)
|
||||||
(column indent)
|
(column indent)
|
||||||
(delimited? #t) ;true if comes after a delimiter
|
(delimited? #t) ;true if comes after a delimiter
|
||||||
|
@ -436,7 +446,8 @@ FORMAT-COMMENT is 'canonicalize-comment'."
|
||||||
(column (if overflow?
|
(column (if overflow?
|
||||||
(+ indent 1)
|
(+ indent 1)
|
||||||
(+ column (if delimited? 1 2))))
|
(+ column (if delimited? 1 2))))
|
||||||
(newline? (newline-form? head context))
|
(newline? (or (newline-form? head context)
|
||||||
|
(list-of-lists? head tail))) ;'let' bindings
|
||||||
(context (cons head context)))
|
(context (cons head context)))
|
||||||
(if overflow?
|
(if overflow?
|
||||||
(begin
|
(begin
|
||||||
|
|
|
@ -504,6 +504,25 @@ mnopqrstuvwxyz.\")"
|
||||||
#:make-flags #~'(\"ANSWER=42\")
|
#:make-flags #~'(\"ANSWER=42\")
|
||||||
#:tests? #f)))")
|
#:tests? #f)))")
|
||||||
|
|
||||||
|
(test-pretty-print "\
|
||||||
|
(let ((x 1)
|
||||||
|
(y 2)
|
||||||
|
(z (let* ((a 3)
|
||||||
|
(b 4))
|
||||||
|
(+ a b))))
|
||||||
|
(list x y z))")
|
||||||
|
|
||||||
|
(test-pretty-print "\
|
||||||
|
(substitute-keyword-arguments (package-arguments x)
|
||||||
|
((#:phases phases)
|
||||||
|
`(modify-phases ,phases
|
||||||
|
(add-before 'build 'do-things
|
||||||
|
(lambda _
|
||||||
|
#t))))
|
||||||
|
((#:configure-flags flags)
|
||||||
|
`(cons \"--without-any-problem\"
|
||||||
|
,flags)))")
|
||||||
|
|
||||||
(test-equal "pretty-print-with-comments, canonicalize-comment"
|
(test-equal "pretty-print-with-comments, canonicalize-comment"
|
||||||
"\
|
"\
|
||||||
(list abc
|
(list abc
|
||||||
|
|
Loading…
Add table
Reference in a new issue