make pretty-print-newline work on any output port

The documentation says that it should work on any output port,
although there's special treatment of ports that originate
from `pretty-print` itself.

Closes #1579.
This commit is contained in:
Matthew Flatt 2017-01-29 19:27:23 -07:00
parent 572b96a6ef
commit 6c9dbea31f
2 changed files with 15 additions and 2 deletions

View File

@ -525,6 +525,13 @@
(pp v))
(test "(a 1)\n" get-output-string o))
;; ----------------------------------------
;; check that `pretty-print-newline` works on any output port
(let ([o (open-output-bytes)])
(pretty-print-newline o 17)
(test "\n" get-output-string o))
;; ----------------------------------------
(report-errs)

View File

@ -373,8 +373,14 @@
(define orig-write (port-write-handler (open-output-string)))
(define (pretty-print-newline pport width)
(let-values ([(l col p) (port-next-location pport)])
((printing-port-print-line pport) #t (or col 0) width)))
(cond
[(printing-port? pport)
(let-values ([(l col p) (port-next-location pport)])
((printing-port-print-line pport) #t (or col 0) width))]
[(output-port? pport)
(newline pport)]
[else
(raise-argument-error 'pretty-print-newline "output-port?" pport)]))
(define (tentative-pretty-print-port-transfer a-pport pport)
(let ([content ((get a-pport print-port-info-get-content))])