guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

10/10: read-print: Correctly handle comments that follow a list head.


From: guix-commits
Subject: 10/10: read-print: Correctly handle comments that follow a list head.
Date: Tue, 7 Mar 2023 08:58:22 -0500 (EST)

civodul pushed a commit to branch master
in repository guix.

commit 0a37921d851b94aef6900214098dc5bd62b46e26
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Tue Mar 7 11:31:12 2023 +0100

    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.
---
 guix/read-print.scm  | 9 ++++++++-
 tests/read-print.scm | 9 +++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)

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
diff --git a/tests/read-print.scm b/tests/read-print.scm
index 79a4101be6..952b3e6585 100644
--- a/tests/read-print.scm
+++ b/tests/read-print.scm
@@ -210,6 +210,15 @@ mnopqrstuvwxyz.\")"
  \"abcdefghijklmnopqrstuvwxyz\")"
                    #:max-width 33)
 
+(test-pretty-print "\
+(list ;margin comment
+      a b c)")
+
+(test-pretty-print "\
+(list
+ ;; This is a line comment immediately following the list head.
+ #:test-flags #~(list \"-m\" \"not external and not samples\"))")
+
 (test-pretty-print "\
 (modify-phases %standard-phases
   (replace 'build



reply via email to

[Prev in Thread] Current Thread [Next in Thread]