read-print: Correctly support multiple same-named newline forms.

Previously (home-environment (services ...)) would not be considered a
"newline form".  This fixes it.

* guix/read-print.scm (newline-form?): Use 'vhash-foldq*' instead of
'vhash-assq' and iterate over candidates.
* tests/read-print.scm: Add test.
This commit is contained in:
Ludovic Courtès 2022-09-17 16:15:17 +02:00
parent 818220f1cc
commit 7a698da0d0
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
2 changed files with 8 additions and 4 deletions

@ -367,10 +367,9 @@ surrounding SYMBOL."
(define (newline-form? symbol context)
"Return true if parenthesized expressions starting with SYMBOL must be
followed by a newline."
(match (vhash-assq symbol %newline-forms)
(#f #f)
((_ . prefix)
(prefix? prefix context))))
(let ((matches (vhash-foldq* cons '() symbol %newline-forms)))
(find (cut prefix? <> context)
matches)))
(define (escaped-string str)
"Return STR with backslashes and double quotes escaped. Everything else, in

@ -294,6 +294,11 @@ mnopqrstuvwxyz.\")"
;; page break above
end)")
(test-pretty-print "\
(home-environment
(services
(list (service-type home-bash-service-type))))")
(test-pretty-print/sequence "\
;;; This is a top-level comment.