mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-07-02 15:40:38 +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:
parent
75f96e825c
commit
379a9a64c6
1 changed files with 213 additions and 224 deletions
|
@ -26,7 +26,6 @@
|
||||||
#:export (pretty-print
|
#:export (pretty-print
|
||||||
truncated-print))
|
truncated-print))
|
||||||
|
|
||||||
|
|
||||||
(define* (call-with-truncating-output-string proc success failure #:key
|
(define* (call-with-truncating-output-string proc success failure #:key
|
||||||
(initial-column 0)
|
(initial-column 0)
|
||||||
(max-column 79)
|
(max-column 79)
|
||||||
|
@ -51,15 +50,30 @@
|
||||||
(lambda (_)
|
(lambda (_)
|
||||||
(failure (string-concatenate-reverse strs)))))
|
(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
|
;; Copyright (c) 1991, Marc Feeley
|
||||||
;; Author: Marc Feeley (feeley@iro.umontreal.ca)
|
;; Author: Marc Feeley (feeley@iro.umontreal.ca)
|
||||||
;; Distribution restrictions: none
|
;; Distribution restrictions: none
|
||||||
|
|
||||||
(define (generic-write
|
(define* (pretty-print obj #:optional port*
|
||||||
obj display? width max-expr-width per-line-prefix 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 obj port)
|
||||||
(define (wr-read-macro prefix x)
|
(define (wr-read-macro prefix x)
|
||||||
(put-string port prefix)
|
(put-string port prefix)
|
||||||
|
@ -82,7 +96,6 @@
|
||||||
(_
|
(_
|
||||||
((if display? display write) obj port))))
|
((if display? display write) obj port))))
|
||||||
|
|
||||||
(define (pp obj)
|
|
||||||
; define formatting style (change these to suit your style)
|
; define formatting style (change these to suit your style)
|
||||||
(define indent-general 2)
|
(define indent-general 2)
|
||||||
(define max-call-head-width 5)
|
(define max-call-head-width 5)
|
||||||
|
@ -122,7 +135,7 @@
|
||||||
(lambda (full-str) (put-string port full-str))
|
(lambda (full-str) (put-string port full-str))
|
||||||
(lambda (partial-str) (pp-pair obj))
|
(lambda (partial-str) (pp-pair obj))
|
||||||
#:initial-column (port-column port)
|
#:initial-column (port-column port)
|
||||||
#:max-column width
|
#:max-column (- width (string-length per-line-prefix))
|
||||||
#:allow-newline? #f))))
|
#:allow-newline? #f))))
|
||||||
|
|
||||||
(define (pp-expr expr)
|
(define (pp-expr expr)
|
||||||
|
@ -285,39 +298,15 @@
|
||||||
(define (pp-expr-list l)
|
(define (pp-expr-list l)
|
||||||
(pp-list l pp-expr))
|
(pp-list l pp-expr))
|
||||||
|
|
||||||
(pr obj pp-expr))
|
|
||||||
|
|
||||||
(put-string port per-line-prefix)
|
(put-string port per-line-prefix)
|
||||||
(pp obj)
|
(pr obj pp-expr)
|
||||||
(newline)
|
(newline)
|
||||||
;; Return `unspecified'
|
;; Return `unspecified'
|
||||||
(if #f #f))
|
(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*
|
(define* (truncated-print x #:optional port*
|
||||||
#:key
|
#:key
|
||||||
(port (or port* (current-output-port)))
|
(port (or port* (current-output-port)))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue