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
parent
74e96c4cb1
commit
7931ac810b
|
@ -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)))))
|
||||||
|
|
||||||
|
|
|
@ -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.\")"
|
||||||
|
|
Reference in New Issue