@@ -387,6 +387,27 @@ (define (canonicalize-comment comment indent)
line "\n")
(comment-margin? comment)))))
+(define %not-newline
+ (char-set-complement (char-set #\newline)))
+
+(define (print-multi-line-comment str indent port)
+ "Print to PORT STR as a multi-line comment, with INDENT spaces preceding
+each line except the first one (they're assumed to be already there)."
+
+ ;; While 'read-with-comments' only returns one-line comments, user-provided
+ ;; comments might span multiple lines, which is why this is necessary.
+ (let loop ((lst (string-tokenize str %not-newline)))
+ (match lst
+ (() #t)
+ ((last)
+ (display last port)
+ (newline port))
+ ((head tail ...)
+ (display head port)
+ (newline port)
+ (display (make-string indent #\space) port)
+ (loop tail)))))
+
(define* (pretty-print-with-comments port obj
#:key
(format-comment
@@ -486,8 +507,9 @@ (define (special-form? head)
(unless (= column indent)
(newline port)
(display (make-string indent #\space) port))
- (display (comment->string (format-comment comment indent))
- port)))
+ (print-multi-line-comment (comment->string
+ (format-comment comment indent))
+ indent port)))
(display (make-string indent #\space) port)
indent)
((? vertical-space? space)
@@ -341,4 +341,18 @@ (define-module (foo bar)
#:format-vertical-space
canonicalize-vertical-space)))))
+(test-equal "pretty-print-with-comments, multi-line comment"
+ "\
+(list abc
+ ;; This comment spans
+ ;; two lines.
+ def)"
+ (call-with-output-string
+ (lambda (port)
+ (pretty-print-with-comments port
+ `(list abc ,(comment "\
+;; This comment spans\n
+;; two lines.\n")
+ def)))))
+
(test-end)