summaryrefslogtreecommitdiff
path: root/guix/read-print.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludovic.courtes@inria.fr>2023-04-24 10:10:00 +0200
committerLudovic Courtès <ludo@gnu.org>2023-04-24 10:27:13 +0200
commit7931ac810b8feaadcbbfa3a31786087da2d5ee73 (patch)
treeb9a45254cf47354eb8e48a43e26ba042ff645cb3 /guix/read-print.scm
parent74e96c4cb171b17949f638d8b452d047a8f2dc6f (diff)
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.
Diffstat (limited to 'guix/read-print.scm')
-rw-r--r--guix/read-print.scm11
1 files changed, 9 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)))))