[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
01/05: read-print: 'pretty-print-with-comments' keeps newlines on long s
From: |
guix-commits |
Subject: |
01/05: read-print: 'pretty-print-with-comments' keeps newlines on long strings. |
Date: |
Mon, 24 Apr 2023 06:25:14 -0400 (EDT) |
civodul pushed a commit to branch master
in repository guix.
commit 7931ac810b8feaadcbbfa3a31786087da2d5ee73
Author: Ludovic Courtès <ludovic.courtes@inria.fr>
AuthorDate: Mon Apr 24 10:10:00 2023 +0200
read-print: 'pretty-print-with-comments' keeps newlines on long strings.
* guix/read-print.scm (printed-string)[preserve-newlines?]: New
procedure.
Use it to preserve newlines on long strings.
* tests/read-print.scm: Add test.
---
guix/read-print.scm | 11 +++++++++--
tests/read-print.scm | 5 +++++
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/guix/read-print.scm b/guix/read-print.scm
index 515eb7669c..d834105dce 100644
--- a/guix/read-print.scm
+++ b/guix/read-print.scm
@@ -420,11 +420,18 @@ particular newlines, is left as is."
(define (printed-string str context)
"Return the read syntax for STR depending on CONTEXT."
+ (define (preserve-newlines? str)
+ (and (> (string-length str) 40)
+ (string-index str #\newline)))
+
(match context
(()
- (object->string str))
+ (if (preserve-newlines? str)
+ (escaped-string str)
+ (object->string str)))
((head . _)
- (if (memq head %natural-whitespace-string-forms)
+ (if (or (memq head %natural-whitespace-string-forms)
+ (preserve-newlines? str))
(escaped-string str)
(object->string str)))))
diff --git a/tests/read-print.scm b/tests/read-print.scm
index f4627e076a..c2b236b172 100644
--- a/tests/read-print.scm
+++ b/tests/read-print.scm
@@ -194,6 +194,11 @@ expressions."
(test-pretty-print "\
(string-append \"a\\tb\" \"\\n\")")
+(test-pretty-print "\
+(display \"This is a very long string.
+It contains line breaks, which are preserved,
+because it's a long string.\")")
+
(test-pretty-print "\
(description \"abcdefghijkl
mnopqrstuvwxyz.\")"