me
/
guix
Archived
1
0
Fork 0

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.
master
Ludovic Courtès 2023-04-24 10:10:00 +02:00 committed by Ludovic Courtès
parent 74e96c4cb1
commit 7931ac810b
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
2 changed files with 14 additions and 2 deletions

View File

@ -420,11 +420,18 @@ particular newlines, is left as is."
(define (printed-string str context) (define (printed-string str context)
"Return the read syntax for STR depending on 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 (match context
(() (()
(object->string str)) (if (preserve-newlines? str)
(escaped-string str)
(object->string str)))
((head . _) ((head . _)
(if (memq head %natural-whitespace-string-forms) (if (or (memq head %natural-whitespace-string-forms)
(preserve-newlines? str))
(escaped-string str) (escaped-string str)
(object->string str))))) (object->string str)))))

View File

@ -194,6 +194,11 @@ expressions."
(test-pretty-print "\ (test-pretty-print "\
(string-append \"a\\tb\" \"\\n\")") (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 "\ (test-pretty-print "\
(description \"abcdefghijkl (description \"abcdefghijkl
mnopqrstuvwxyz.\")" mnopqrstuvwxyz.\")"