1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-30 06:50:31 +02:00

Inline generic-write into pretty-print

* module/ice-9/pretty-print.scm (pretty-print): Inline generic-write
into its only caller.
This commit is contained in:
Andy Wingo 2023-06-02 21:58:08 +02:00
parent 75f96e825c
commit 379a9a64c6

View file

@ -26,7 +26,6 @@
#:export (pretty-print
truncated-print))
(define* (call-with-truncating-output-string proc success failure #:key
(initial-column 0)
(max-column 79)
@ -51,15 +50,30 @@
(lambda (_)
(failure (string-concatenate-reverse strs)))))
;; From SLIB.
;;"genwrite.scm" generic write used by pretty-print and truncated-print.
;; Parts of pretty-print derived from "genwrite.scm", from SLIB.
;; Copyright (c) 1991, Marc Feeley
;; Author: Marc Feeley (feeley@iro.umontreal.ca)
;; Distribution restrictions: none
(define (generic-write
obj display? width max-expr-width per-line-prefix port)
(define* (pretty-print obj #:optional port*
#:key
(port (or port* (current-output-port)))
(width 79)
(max-expr-width 50)
(display? #f)
(per-line-prefix ""))
"Pretty-print OBJ on PORT, which is a keyword argument defaulting to
the current output port. Formatting can be controlled by a number of
keyword arguments: Each line in the output is preceded by the string
PER-LINE-PREFIX, which is empty by default. The output lines will be
at most WIDTH characters wide; the default is 79. If DISPLAY? is
true, display rather than write representation will be used.
Instead of with a keyword argument, you can also specify the output
port directly after OBJ, like (pretty-print OBJ PORT)."
(define (wr obj port)
(define (wr-read-macro prefix x)
(put-string port prefix)
@ -82,7 +96,6 @@
(_
((if display? display write) obj port))))
(define (pp obj)
; define formatting style (change these to suit your style)
(define indent-general 2)
(define max-call-head-width 5)
@ -122,7 +135,7 @@
(lambda (full-str) (put-string port full-str))
(lambda (partial-str) (pp-pair obj))
#:initial-column (port-column port)
#:max-column width
#:max-column (- width (string-length per-line-prefix))
#:allow-newline? #f))))
(define (pp-expr expr)
@ -285,39 +298,15 @@
(define (pp-expr-list l)
(pp-list l pp-expr))
(pr obj pp-expr))
(put-string port per-line-prefix)
(pp obj)
(pr obj pp-expr)
(newline)
;; Return `unspecified'
(if #f #f))
(define* (pretty-print obj #:optional port*
#:key
(port (or port* (current-output-port)))
(width 79)
(max-expr-width 50)
(display? #f)
(per-line-prefix ""))
"Pretty-print OBJ on PORT, which is a keyword argument defaulting to
the current output port. Formatting can be controlled by a number of
keyword arguments: Each line in the output is preceded by the string
PER-LINE-PREFIX, which is empty by default. The output lines will be
at most WIDTH characters wide; the default is 79. If DISPLAY? is
true, display rather than write representation will be used.
Instead of with a keyword argument, you can also specify the output
port directly after OBJ, like (pretty-print OBJ PORT)."
(generic-write obj display?
(- width (string-length per-line-prefix))
max-expr-width
per-line-prefix
port))
;; `truncated-print' was written in 2009 by Andy Wingo, and is not from
;; genwrite.scm.
(define* (truncated-print x #:optional port*
#:key
(port (or port* (current-output-port)))