mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2024-11-07 07:26:13 -05:00
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.
This commit is contained in:
parent
74e96c4cb1
commit
7931ac810b
2 changed files with 14 additions and 2 deletions
|
@ -420,11 +420,18 @@ (define %natural-whitespace-string-forms
|
||||||
|
|
||||||
(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 @@ (define-syntax-rule (test-pretty-print/sequence str args ...)
|
||||||
(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.\")"
|
||||||
|
|
Loading…
Reference in a new issue