diff options
author | Ludovic Courtès <ludo@gnu.org> | 2023-03-07 11:31:12 +0100 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2023-03-07 11:39:50 +0100 |
commit | 0a37921d851b94aef6900214098dc5bd62b46e26 (patch) | |
tree | e1a34ff234cf7a6637fb91e4fbc0c348113c8328 /guix | |
parent | 11f6bdc547bb80a8c692ce87074058dcd9b0dc8c (diff) |
read-print: Correctly handle comments that follow a list head.
Fixes <https://issues.guix.gnu.org/61013>.
Reported by Maxim Cournoyer <maxim.cournoyer@gmail.com>.
* guix/read-print.scm (pretty-print-with-comments)[starts-with-line-comment?]:
New procedure.
Use it when printing a list.
* tests/read-print.scm: Add two tests.
Diffstat (limited to 'guix')
-rw-r--r-- | guix/read-print.scm | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/guix/read-print.scm b/guix/read-print.scm index 46b722eeed..fdc85c2693 100644 --- a/guix/read-print.scm +++ b/guix/read-print.scm @@ -529,6 +529,12 @@ FORMAT-VERTICAL-SPACE; a useful value of 'canonicalize-vertical-space'." (pair? tail))) (_ #f))) + (define (starts-with-line-comment? lst) + ;; Return true if LST starts with a line comment. + (match lst + ((x . _) (and (comment? x) (not (comment-margin? x)))) + (_ #f))) + (let loop ((indent indent) (column indent) (delimited? #t) ;true if comes after a delimiter @@ -710,7 +716,8 @@ FORMAT-VERTICAL-SPACE; a useful value of 'canonicalize-vertical-space'." (+ indent 1) (+ column (if delimited? 1 2)))) (newline? (or (newline-form? head context) - (list-of-lists? head tail))) ;'let' bindings + (list-of-lists? head tail) ;'let' bindings + (starts-with-line-comment? tail))) (context (cons head context))) (if overflow? (begin |