1 ;;;; Common Lisp pretty printer
3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
12 (in-package "SB!PRETTY")
16 ;;; There are three different units for measuring character positions:
17 ;;; COLUMN - offset (if characters) from the start of the current line
18 ;;; INDEX - index into the output buffer
19 ;;; POSN - some position in the stream of characters cycling through
22 '(and fixnum unsigned-byte
))
23 ;;; The INDEX type is picked up from the kernel package.
27 (defconstant initial-buffer-size
128)
29 (defconstant default-line-length
80)
31 (defstruct (pretty-stream (:include sb
!kernel
:ansi-stream
35 (:constructor make-pretty-stream
(target))
37 ;; Where the output is going to finally go.
38 (target (missing-arg) :type stream
)
39 ;; Line length we should format to. Cached here so we don't have to keep
40 ;; extracting it from the target stream.
41 (line-length (or *print-right-margin
*
42 (sb!impl
::line-length target
)
45 ;; A simple string holding all the text that has been output but not yet
47 (buffer (make-string initial-buffer-size
) :type
(simple-array character
(*)))
48 ;; The index into BUFFER where more text should be put.
49 (buffer-fill-pointer 0 :type index
)
50 ;; Whenever we output stuff from the buffer, we shift the remaining noise
51 ;; over. This makes it difficult to keep references to locations in
52 ;; the buffer. Therefore, we have to keep track of the total amount of
53 ;; stuff that has been shifted out of the buffer.
54 (buffer-offset 0 :type posn
)
55 ;; The column the first character in the buffer will appear in. Normally
56 ;; zero, but if we end up with a very long line with no breaks in it we
57 ;; might have to output part of it. Then this will no longer be zero.
58 (buffer-start-column (or (sb!impl
::charpos target
) 0) :type column
)
59 ;; The line number we are currently on. Used for *PRINT-LINES*
60 ;; abbreviations and to tell when sections have been split across
62 (line-number 0 :type index
)
63 ;; the value of *PRINT-LINES* captured at object creation time. We
64 ;; use this, instead of the dynamic *PRINT-LINES*, to avoid
66 ;; (let ((*print-lines* 50))
67 ;; (pprint-logical-block ..
69 ;; (let ((*print-lines* 8))
70 ;; (print (aref possiblybigthings i) prettystream)))))
71 ;; terminating the output of the entire logical blockafter 8 lines.
72 (print-lines *print-lines
* :type
(or index null
) :read-only t
)
73 ;; Stack of logical blocks in effect at the buffer start.
74 (blocks (list (make-logical-block)) :type list
)
75 ;; Buffer holding the per-line prefix active at the buffer start.
76 ;; Indentation is included in this. The length of this is stored
77 ;; in the logical block stack.
78 (prefix (make-string initial-buffer-size
) :type simple-string
)
79 ;; Buffer holding the total remaining suffix active at the buffer start.
80 ;; The characters are right-justified in the buffer to make it easier
81 ;; to output the buffer. The length is stored in the logical block
83 (suffix (make-string initial-buffer-size
) :type simple-string
)
84 ;; Queue of pending operations. When empty, HEAD=TAIL=NIL. Otherwise,
85 ;; TAIL holds the first (oldest) cons and HEAD holds the last (newest)
86 ;; cons. Adding things to the queue is basically (setf (cdr head) (list
87 ;; new)) and removing them is basically (pop tail) [except that care must
88 ;; be taken to handle the empty queue case correctly.]
89 (queue-tail nil
:type list
)
90 (queue-head nil
:type list
)
91 ;; Block-start queue entries in effect at the queue head.
92 (pending-blocks nil
:type list
))
93 (def!method print-object
((pstream pretty-stream
) stream
)
94 ;; FIXME: CMU CL had #+NIL'ed out this code and done a hand-written
95 ;; FORMAT hack instead. Make sure that this code actually works instead
96 ;; of falling into infinite regress or something.
97 (print-unreadable-object (pstream stream
:type t
:identity t
)))
99 #!-sb-fluid
(declaim (inline index-posn posn-index posn-column
))
100 (defun index-posn (index stream
)
101 (declare (type index index
) (type pretty-stream stream
)
103 (+ index
(pretty-stream-buffer-offset stream
)))
104 (defun posn-index (posn stream
)
105 (declare (type posn posn
) (type pretty-stream stream
)
107 (- posn
(pretty-stream-buffer-offset stream
)))
108 (defun posn-column (posn stream
)
109 (declare (type posn posn
) (type pretty-stream stream
)
111 (index-column (posn-index posn stream
) stream
))
113 ;;; Is it OK to do pretty printing on this stream at this time?
114 (defun print-pretty-on-stream-p (stream)
115 (and (pretty-stream-p stream
)
118 ;;;; stream interface routines
120 (defun pretty-out (stream char
)
121 (declare (type pretty-stream stream
)
122 (type character char
))
123 (cond ((char= char
#\newline
)
124 (enqueue-newline stream
:literal
))
126 (ensure-space-in-buffer stream
1)
127 (let ((fill-pointer (pretty-stream-buffer-fill-pointer stream
)))
128 (setf (schar (pretty-stream-buffer stream
) fill-pointer
) char
)
129 (setf (pretty-stream-buffer-fill-pointer stream
)
130 (1+ fill-pointer
))))))
132 (defun pretty-sout (stream string start end
)
133 (declare (type pretty-stream stream
)
134 (type simple-string string
)
136 (type (or index null
) end
))
137 (let* ((end (or end
(length string
))))
138 (unless (= start end
)
139 (sb!impl
::string-dispatch
(simple-base-string
141 (simple-array character
(*)))
143 ;; For POSITION transform
144 (declare (optimize (speed 2)))
145 (let ((newline (position #\newline string
:start start
:end end
)))
148 (pretty-sout stream string start newline
)
149 (enqueue-newline stream
:literal
)
150 (pretty-sout stream string
(1+ newline
) end
))
152 (let ((chars (- end start
)))
154 (let* ((available (ensure-space-in-buffer stream chars
))
155 (count (min available chars
))
156 (fill-pointer (pretty-stream-buffer-fill-pointer
158 (new-fill-ptr (+ fill-pointer count
)))
159 (if (typep string
'simple-base-string
)
160 ;; FIXME: Reimplementing REPLACE, since it
161 ;; can't be inlined and we don't have a
162 ;; generic "simple-array -> simple-array"
164 (loop for i from fill-pointer below new-fill-ptr
166 with target
= (pretty-stream-buffer stream
)
167 do
(setf (aref target i
)
169 (replace (pretty-stream-buffer stream
)
171 :start1 fill-pointer
:end1 new-fill-ptr
173 (setf (pretty-stream-buffer-fill-pointer stream
)
178 (incf start count
)))))))))))
180 (defun pretty-misc (stream op
&optional arg1 arg2
)
181 (declare (ignore stream op arg1 arg2
)))
185 (defstruct (logical-block (:copier nil
))
186 ;; The column this logical block started in.
187 (start-column 0 :type column
)
188 ;; The column the current section started in.
189 (section-column 0 :type column
)
190 ;; The length of the per-line prefix. We can't move the indentation
192 (per-line-prefix-end 0 :type index
)
193 ;; The overall length of the prefix, including any indentation.
194 (prefix-length 0 :type index
)
195 ;; The overall length of the suffix.
196 (suffix-length 0 :type index
)
198 (section-start-line 0 :type index
))
200 (defun really-start-logical-block (stream column prefix suffix
)
201 (let* ((blocks (pretty-stream-blocks stream
))
202 (prev-block (car blocks
))
203 (per-line-end (logical-block-per-line-prefix-end prev-block
))
204 (prefix-length (logical-block-prefix-length prev-block
))
205 (suffix-length (logical-block-suffix-length prev-block
))
206 (block (make-logical-block
208 :section-column column
209 :per-line-prefix-end per-line-end
210 :prefix-length prefix-length
211 :suffix-length suffix-length
212 :section-start-line
(pretty-stream-line-number stream
))))
213 (setf (pretty-stream-blocks stream
) (cons block blocks
))
214 (set-indentation stream column
)
216 (setf (logical-block-per-line-prefix-end block
) column
)
217 (replace (pretty-stream-prefix stream
) prefix
218 :start1
(- column
(length prefix
)) :end1 column
))
220 (let* ((total-suffix (pretty-stream-suffix stream
))
221 (total-suffix-len (length total-suffix
))
222 (additional (length suffix
))
223 (new-suffix-len (+ suffix-length additional
)))
224 (when (> new-suffix-len total-suffix-len
)
225 (let ((new-total-suffix-len
226 (max (* total-suffix-len
2)
228 (floor (* additional
5) 4)))))
230 (replace (make-string new-total-suffix-len
) total-suffix
231 :start1
(- new-total-suffix-len suffix-length
)
232 :start2
(- total-suffix-len suffix-length
)))
233 (setf total-suffix-len new-total-suffix-len
)
234 (setf (pretty-stream-suffix stream
) total-suffix
)))
235 (replace total-suffix suffix
236 :start1
(- total-suffix-len new-suffix-len
)
237 :end1
(- total-suffix-len suffix-length
))
238 (setf (logical-block-suffix-length block
) new-suffix-len
))))
241 (defun set-indentation (stream column
)
242 (let* ((prefix (pretty-stream-prefix stream
))
243 (prefix-len (length prefix
))
244 (block (car (pretty-stream-blocks stream
)))
245 (current (logical-block-prefix-length block
))
246 (minimum (logical-block-per-line-prefix-end block
))
247 (column (max minimum column
)))
248 (when (> column prefix-len
)
250 (replace (make-string (max (* prefix-len
2)
252 (floor (* (- column prefix-len
) 5)
256 (setf (pretty-stream-prefix stream
) prefix
))
257 (when (> column current
)
258 (fill prefix
#\space
:start current
:end column
))
259 (setf (logical-block-prefix-length block
) column
)))
261 (defun really-end-logical-block (stream)
262 (let* ((old (pop (pretty-stream-blocks stream
)))
263 (old-indent (logical-block-prefix-length old
))
264 (new (car (pretty-stream-blocks stream
)))
265 (new-indent (logical-block-prefix-length new
)))
266 (when (> new-indent old-indent
)
267 (fill (pretty-stream-prefix stream
) #\space
268 :start old-indent
:end new-indent
)))
271 ;;;; the pending operation queue
273 (defstruct (queued-op (:constructor nil
)
277 (defmacro enqueue
(stream type
&rest args
)
278 (let ((constructor (symbolicate "MAKE-" type
)))
279 (once-only ((stream stream
)
280 (entry `(,constructor
:posn
282 (pretty-stream-buffer-fill-pointer
287 (head `(pretty-stream-queue-head ,stream
)))
290 (setf (cdr ,head
) ,op
)
291 (setf (pretty-stream-queue-tail ,stream
) ,op
))
292 (setf (pretty-stream-queue-head ,stream
) ,op
)
295 (defstruct (section-start (:include queued-op
)
298 (depth 0 :type index
)
299 (section-end nil
:type
(or null newline block-end
)))
301 (defstruct (newline (:include section-start
)
304 :type
(member :linear
:fill
:miser
:literal
:mandatory
)))
306 (defun enqueue-newline (stream kind
)
307 (let* ((depth (length (pretty-stream-pending-blocks stream
)))
308 (newline (enqueue stream newline
:kind kind
:depth depth
)))
309 (dolist (entry (pretty-stream-queue-tail stream
))
310 (when (and (not (eq newline entry
))
311 (section-start-p entry
)
312 (null (section-start-section-end entry
))
313 (<= depth
(section-start-depth entry
)))
314 (setf (section-start-section-end entry
) newline
))))
315 (maybe-output stream
(or (eq kind
:literal
) (eq kind
:mandatory
))))
317 (defstruct (indentation (:include queued-op
)
319 (kind (missing-arg) :type
(member :block
:current
))
320 (amount 0 :type fixnum
))
322 (defun enqueue-indent (stream kind amount
)
323 (enqueue stream indentation
:kind kind
:amount amount
))
325 (defstruct (block-start (:include section-start
)
327 (block-end nil
:type
(or null block-end
))
328 (prefix nil
:type
(or null simple-string
))
329 (suffix nil
:type
(or null simple-string
)))
331 (defun start-logical-block (stream prefix per-line-p suffix
)
332 ;; (In the PPRINT-LOGICAL-BLOCK form which calls us,
333 ;; :PREFIX and :PER-LINE-PREFIX have hairy defaulting behavior,
334 ;; and might end up being NIL.)
335 (declare (type (or null string
) prefix
))
336 ;; (But the defaulting behavior of PPRINT-LOGICAL-BLOCK :SUFFIX is
337 ;; trivial, so it should always be a string.)
338 (declare (type string suffix
))
340 (unless (typep prefix
'simple-string
)
341 (setq prefix
(coerce prefix
'(simple-array character
(*)))))
342 (pretty-sout stream prefix
0 (length prefix
)))
343 (unless (typep suffix
'simple-string
)
344 (setq suffix
(coerce suffix
'(simple-array character
(*)))))
345 (let* ((pending-blocks (pretty-stream-pending-blocks stream
))
346 (start (enqueue stream block-start
347 :prefix
(and per-line-p prefix
)
349 :depth
(length pending-blocks
))))
350 (setf (pretty-stream-pending-blocks stream
)
351 (cons start pending-blocks
))))
353 (defstruct (block-end (:include queued-op
)
355 (suffix nil
:type
(or null simple-string
)))
357 (defun end-logical-block (stream)
358 (let* ((start (pop (pretty-stream-pending-blocks stream
)))
359 (suffix (block-start-suffix start
))
360 (end (enqueue stream block-end
:suffix suffix
)))
362 (pretty-sout stream suffix
0 (length suffix
)))
363 (setf (block-start-block-end start
) end
)))
365 (defstruct (tab (:include queued-op
)
367 (sectionp nil
:type
(member t nil
))
368 (relativep nil
:type
(member t nil
))
369 (colnum 0 :type column
)
370 (colinc 0 :type column
))
372 (defun enqueue-tab (stream kind colnum colinc
)
373 (multiple-value-bind (sectionp relativep
)
375 (:line
(values nil nil
))
376 (:line-relative
(values nil t
))
377 (:section
(values t nil
))
378 (:section-relative
(values t t
)))
379 (enqueue stream tab
:sectionp sectionp
:relativep relativep
380 :colnum colnum
:colinc colinc
)))
384 (defun compute-tab-size (tab section-start column
)
385 (let* ((origin (if (tab-sectionp tab
) section-start
0))
386 (colnum (tab-colnum tab
))
387 (colinc (tab-colinc tab
))
388 (position (- column origin
)))
389 (cond ((tab-relativep tab
)
390 (unless (<= colinc
1)
391 (let ((newposn (+ position colnum
)))
392 (let ((rem (rem newposn colinc
)))
394 (incf colnum
(- colinc rem
))))))
401 (rem (- position colnum
) colinc
))))))
403 (defun index-column (index stream
)
404 (let ((column (pretty-stream-buffer-start-column stream
))
405 (section-start (logical-block-section-column
406 (first (pretty-stream-blocks stream
))))
407 (end-posn (index-posn index stream
)))
408 (dolist (op (pretty-stream-queue-tail stream
))
409 (when (>= (queued-op-posn op
) end-posn
)
417 (posn-index (tab-posn op
)
419 ((or newline block-start
)
421 (+ column
(posn-index (queued-op-posn op
)
425 (defun expand-tabs (stream through
)
426 (let ((insertions nil
)
428 (column (pretty-stream-buffer-start-column stream
))
429 (section-start (logical-block-section-column
430 (first (pretty-stream-blocks stream
)))))
431 (dolist (op (pretty-stream-queue-tail stream
))
434 (let* ((index (posn-index (tab-posn op
) stream
))
435 (tabsize (compute-tab-size op
438 (unless (zerop tabsize
)
439 (push (cons index tabsize
) insertions
)
440 (incf additional tabsize
)
441 (incf column tabsize
))))
442 ((or newline block-start
)
444 (+ column
(posn-index (queued-op-posn op
) stream
)))))
445 (when (eq op through
)
448 (let* ((fill-ptr (pretty-stream-buffer-fill-pointer stream
))
449 (new-fill-ptr (+ fill-ptr additional
))
450 (buffer (pretty-stream-buffer stream
))
452 (length (length buffer
))
454 (when (> new-fill-ptr length
)
455 (let ((new-length (max (* length
2)
457 (floor (* additional
5) 4)))))
458 (setf new-buffer
(make-string new-length
))
459 (setf (pretty-stream-buffer stream
) new-buffer
)))
460 (setf (pretty-stream-buffer-fill-pointer stream
) new-fill-ptr
)
461 (decf (pretty-stream-buffer-offset stream
) additional
)
462 (dolist (insertion insertions
)
463 (let* ((srcpos (car insertion
))
464 (amount (cdr insertion
))
465 (dstpos (+ srcpos additional
)))
466 (replace new-buffer buffer
:start1 dstpos
:start2 srcpos
:end2 end
)
467 (fill new-buffer
#\space
:start
(- dstpos amount
) :end dstpos
)
468 (decf additional amount
)
470 (unless (eq new-buffer buffer
)
471 (replace new-buffer buffer
:end1 end
:end2 end
))))))
473 ;;;; stuff to do the actual outputting
475 (defun ensure-space-in-buffer (stream want
)
476 (declare (type pretty-stream stream
)
478 (let* ((buffer (pretty-stream-buffer stream
))
479 (length (length buffer
))
480 (fill-ptr (pretty-stream-buffer-fill-pointer stream
))
481 (available (- length fill-ptr
)))
482 (cond ((plusp available
)
484 ((> fill-ptr
(pretty-stream-line-length stream
))
485 (unless (maybe-output stream nil
)
486 (output-partial-line stream
))
487 (ensure-space-in-buffer stream want
))
489 (let* ((new-length (max (* length
2)
491 (floor (* want
5) 4))))
492 (new-buffer (make-string new-length
)))
493 (setf (pretty-stream-buffer stream
) new-buffer
)
494 (replace new-buffer buffer
:end1 fill-ptr
)
495 (- new-length fill-ptr
))))))
497 (defun maybe-output (stream force-newlines-p
)
498 (declare (type pretty-stream stream
))
499 (let ((tail (pretty-stream-queue-tail stream
))
500 (output-anything nil
))
503 (setf (pretty-stream-queue-head stream
) nil
)
505 (let ((next (pop tail
)))
508 (when (ecase (newline-kind next
)
509 ((:literal
:mandatory
:linear
) t
)
510 (:miser
(misering-p stream
))
512 (or (misering-p stream
)
513 (> (pretty-stream-line-number stream
)
514 (logical-block-section-start-line
515 (first (pretty-stream-blocks stream
))))
516 (ecase (fits-on-line-p stream
517 (newline-section-end next
)
523 (setf output-anything t
)
524 (output-line stream next
)))
526 (unless (misering-p stream
)
527 (set-indentation stream
528 (+ (ecase (indentation-kind next
)
530 (logical-block-start-column
531 (car (pretty-stream-blocks stream
))))
534 (indentation-posn next
)
536 (indentation-amount next
)))))
538 (ecase (fits-on-line-p stream
(block-start-section-end next
)
541 ;; Just nuke the whole logical block and make it look
542 ;; like one nice long literal.
543 (let ((end (block-start-block-end next
)))
544 (expand-tabs stream end
)
545 (setf tail
(cdr (member end tail
)))))
547 (really-start-logical-block
549 (posn-column (block-start-posn next
) stream
)
550 (block-start-prefix next
)
551 (block-start-suffix next
)))
555 (really-end-logical-block stream
))
557 (expand-tabs stream next
))))
558 (setf (pretty-stream-queue-tail stream
) tail
))
561 (defun misering-p (stream)
562 (declare (type pretty-stream stream
))
563 (and *print-miser-width
*
564 (<= (- (pretty-stream-line-length stream
)
565 (logical-block-start-column (car (pretty-stream-blocks stream
))))
566 *print-miser-width
*)))
568 (defun fits-on-line-p (stream until force-newlines-p
)
569 (let ((available (pretty-stream-line-length stream
)))
570 (when (and (not *print-readably
*)
571 (pretty-stream-print-lines stream
)
572 (= (pretty-stream-print-lines stream
)
573 (pretty-stream-line-number stream
)))
574 (decf available
3) ; for the `` ..''
575 (decf available
(logical-block-suffix-length
576 (car (pretty-stream-blocks stream
)))))
578 (<= (posn-column (queued-op-posn until
) stream
) available
))
579 (force-newlines-p nil
)
580 ((> (index-column (pretty-stream-buffer-fill-pointer stream
) stream
)
586 (defun output-line (stream until
)
587 (declare (type pretty-stream stream
)
588 (type newline until
))
589 (let* ((target (pretty-stream-target stream
))
590 (buffer (pretty-stream-buffer stream
))
591 (kind (newline-kind until
))
592 (literal-p (eq kind
:literal
))
593 (amount-to-consume (posn-index (newline-posn until
) stream
))
597 (let ((last-non-blank
598 (position #\space buffer
:end amount-to-consume
599 :from-end t
:test
#'char
/=)))
603 (write-string buffer target
:end amount-to-print
)
604 (let ((line-number (pretty-stream-line-number stream
)))
606 (when (and (not *print-readably
*)
607 (pretty-stream-print-lines stream
)
608 (>= line-number
(pretty-stream-print-lines stream
)))
609 (write-string " .." target
)
610 (let ((suffix-length (logical-block-suffix-length
611 (car (pretty-stream-blocks stream
)))))
612 (unless (zerop suffix-length
)
613 (let* ((suffix (pretty-stream-suffix stream
))
614 (len (length suffix
)))
615 (write-string suffix target
616 :start
(- len suffix-length
)
618 (throw 'line-limit-abbreviation-happened t
))
619 (setf (pretty-stream-line-number stream
) line-number
)
620 (write-char #\newline target
)
621 (setf (pretty-stream-buffer-start-column stream
) 0)
622 (let* ((fill-ptr (pretty-stream-buffer-fill-pointer stream
))
623 (block (first (pretty-stream-blocks stream
)))
626 (logical-block-per-line-prefix-end block
)
627 (logical-block-prefix-length block
)))
628 (shift (- amount-to-consume prefix-len
))
629 (new-fill-ptr (- fill-ptr shift
))
631 (buffer-length (length buffer
)))
632 (when (> new-fill-ptr buffer-length
)
634 (make-string (max (* buffer-length
2)
636 (floor (* (- new-fill-ptr buffer-length
)
639 (setf (pretty-stream-buffer stream
) new-buffer
))
640 (replace new-buffer buffer
641 :start1 prefix-len
:start2 amount-to-consume
:end2 fill-ptr
)
642 (replace new-buffer
(pretty-stream-prefix stream
)
644 (setf (pretty-stream-buffer-fill-pointer stream
) new-fill-ptr
)
645 (incf (pretty-stream-buffer-offset stream
) shift
)
647 (setf (logical-block-section-column block
) prefix-len
)
648 (setf (logical-block-section-start-line block
) line-number
))))))
650 (defun output-partial-line (stream)
651 (let* ((fill-ptr (pretty-stream-buffer-fill-pointer stream
))
652 (tail (pretty-stream-queue-tail stream
))
655 (posn-index (queued-op-posn (car tail
)) stream
)
657 (new-fill-ptr (- fill-ptr count
))
658 (buffer (pretty-stream-buffer stream
)))
660 (error "Output-partial-line called when nothing can be output."))
661 (write-string buffer
(pretty-stream-target stream
)
663 (incf (pretty-stream-buffer-start-column stream
) count
)
664 (replace buffer buffer
:end1 new-fill-ptr
:start2 count
:end2 fill-ptr
)
665 (setf (pretty-stream-buffer-fill-pointer stream
) new-fill-ptr
)
666 (incf (pretty-stream-buffer-offset stream
) count
)))
668 (defun force-pretty-output (stream)
669 (maybe-output stream nil
)
670 (expand-tabs stream nil
)
671 (write-string (pretty-stream-buffer stream
)
672 (pretty-stream-target stream
)
673 :end
(pretty-stream-buffer-fill-pointer stream
)))
675 ;;;; user interface to the pretty printer
677 (defun pprint-newline (kind &optional stream
)
679 "Output a conditional newline to STREAM (which defaults to
680 *STANDARD-OUTPUT*) if it is a pretty-printing stream, and do
681 nothing if not. KIND can be one of:
682 :LINEAR - A line break is inserted if and only if the immediatly
683 containing section cannot be printed on one line.
684 :MISER - Same as LINEAR, but only if ``miser-style'' is in effect.
685 (See *PRINT-MISER-WIDTH*.)
686 :FILL - A line break is inserted if and only if either:
687 (a) the following section cannot be printed on the end of the
689 (b) the preceding section was not printed on a single line, or
690 (c) the immediately containing section cannot be printed on one
691 line and miser-style is in effect.
692 :MANDATORY - A line break is always inserted.
693 When a line break is inserted by any type of conditional newline, any
694 blanks that immediately precede the conditional newline are ommitted
695 from the output and indentation is introduced at the beginning of the
696 next line. (See PPRINT-INDENT.)"
697 (declare (type (member :linear
:miser
:fill
:mandatory
) kind
)
698 (type (or stream
(member t nil
)) stream
)
700 (let ((stream (case stream
702 ((nil) *standard-output
*)
704 (when (print-pretty-on-stream-p stream
)
705 (enqueue-newline stream kind
)))
708 (defun pprint-indent (relative-to n
&optional stream
)
710 "Specify the indentation to use in the current logical block if
711 STREAM \(which defaults to *STANDARD-OUTPUT*) is a pretty-printing
712 stream and do nothing if not. (See PPRINT-LOGICAL-BLOCK.) N is the
713 indentation to use (in ems, the width of an ``m'') and RELATIVE-TO can
716 :BLOCK - Indent relative to the column the current logical block
719 :CURRENT - Indent relative to the current column.
721 The new indentation value does not take effect until the following
723 (declare (type (member :block
:current
) relative-to
)
725 (type (or stream
(member t nil
)) stream
)
727 (let ((stream (case stream
729 ((nil) *standard-output
*)
731 (when (print-pretty-on-stream-p stream
)
732 (enqueue-indent stream relative-to
(truncate n
))))
735 (defun pprint-tab (kind colnum colinc
&optional stream
)
737 "If STREAM (which defaults to *STANDARD-OUTPUT*) is a pretty-printing
738 stream, perform tabbing based on KIND, otherwise do nothing. KIND can
740 :LINE - Tab to column COLNUM. If already past COLNUM tab to the next
742 :SECTION - Same as :LINE, but count from the start of the current
743 section, not the start of the line.
744 :LINE-RELATIVE - Output COLNUM spaces, then tab to the next multiple of
746 :SECTION-RELATIVE - Same as :LINE-RELATIVE, but count from the start
747 of the current section, not the start of the line."
748 (declare (type (member :line
:section
:line-relative
:section-relative
) kind
)
749 (type unsigned-byte colnum colinc
)
750 (type (or stream
(member t nil
)) stream
)
752 (let ((stream (case stream
754 ((nil) *standard-output
*)
756 (when (print-pretty-on-stream-p stream
)
757 (enqueue-tab stream kind colnum colinc
)))
760 (defun pprint-fill (stream list
&optional
(colon? t
) atsign?
)
762 "Output LIST to STREAM putting :FILL conditional newlines between each
763 element. If COLON? is NIL (defaults to T), then no parens are printed
764 around the output. ATSIGN? is ignored (but allowed so that PPRINT-FILL
765 can be used with the ~/.../ format directive."
766 (declare (ignore atsign?
))
767 (pprint-logical-block (stream list
768 :prefix
(if colon?
"(" "")
769 :suffix
(if colon?
")" ""))
770 (pprint-exit-if-list-exhausted)
772 (output-object (pprint-pop) stream
)
773 (pprint-exit-if-list-exhausted)
774 (write-char #\space stream
)
775 (pprint-newline :fill stream
))))
777 (defun pprint-linear (stream list
&optional
(colon? t
) atsign?
)
779 "Output LIST to STREAM putting :LINEAR conditional newlines between each
780 element. If COLON? is NIL (defaults to T), then no parens are printed
781 around the output. ATSIGN? is ignored (but allowed so that PPRINT-LINEAR
782 can be used with the ~/.../ format directive."
783 (declare (ignore atsign?
))
784 (pprint-logical-block (stream list
785 :prefix
(if colon?
"(" "")
786 :suffix
(if colon?
")" ""))
787 (pprint-exit-if-list-exhausted)
789 (output-object (pprint-pop) stream
)
790 (pprint-exit-if-list-exhausted)
791 (write-char #\space stream
)
792 (pprint-newline :linear stream
))))
794 (defun pprint-tabular (stream list
&optional
(colon? t
) atsign? tabsize
)
796 "Output LIST to STREAM tabbing to the next column that is an even multiple
797 of TABSIZE (which defaults to 16) between each element. :FILL style
798 conditional newlines are also output between each element. If COLON? is
799 NIL (defaults to T), then no parens are printed around the output.
800 ATSIGN? is ignored (but allowed so that PPRINT-TABULAR can be used with
801 the ~/.../ format directive."
802 (declare (ignore atsign?
))
803 (pprint-logical-block (stream list
804 :prefix
(if colon?
"(" "")
805 :suffix
(if colon?
")" ""))
806 (pprint-exit-if-list-exhausted)
808 (output-object (pprint-pop) stream
)
809 (pprint-exit-if-list-exhausted)
810 (write-char #\space stream
)
811 (pprint-tab :section-relative
0 (or tabsize
16) stream
)
812 (pprint-newline :fill stream
))))
814 ;;;; pprint-dispatch tables
816 (defvar *initial-pprint-dispatch
*)
817 (defvar *building-initial-table
* nil
)
819 (defstruct (pprint-dispatch-entry (:copier nil
))
820 ;; the type specifier for this entry
821 (type (missing-arg) :type t
)
822 ;; a function to test to see whether an object is of this time.
823 ;; Pretty must just (LAMBDA (OBJ) (TYPEP OBJECT TYPE)) except that
824 ;; we handle the CONS type specially so that (CONS (MEMBER FOO))
825 ;; works. We don't bother computing this for entries in the CONS
826 ;; hash table, because we don't need it.
827 (test-fn nil
:type
(or function null
))
828 ;; the priority for this guy
829 (priority 0 :type real
)
830 ;; T iff one of the original entries.
831 (initial-p *building-initial-table
* :type
(member t nil
))
832 ;; and the associated function
833 (fun (missing-arg) :type callable
))
834 (def!method print-object
((entry pprint-dispatch-entry
) stream
)
835 (print-unreadable-object (entry stream
:type t
)
836 (format stream
"type=~S, priority=~S~@[ [initial]~]"
837 (pprint-dispatch-entry-type entry
)
838 (pprint-dispatch-entry-priority entry
)
839 (pprint-dispatch-entry-initial-p entry
))))
841 (defun cons-type-specifier-p (spec)
843 (eq (car spec
) 'cons
)
846 (let ((car (cadr spec
)))
848 (let ((carcar (car car
)))
849 (or (eq carcar
'member
)
852 (null (cddr car
))))))
854 (defun entry< (e1 e2
)
855 (declare (type pprint-dispatch-entry e1 e2
))
856 (if (pprint-dispatch-entry-initial-p e1
)
857 (if (pprint-dispatch-entry-initial-p e2
)
858 (< (pprint-dispatch-entry-priority e1
)
859 (pprint-dispatch-entry-priority e2
))
861 (if (pprint-dispatch-entry-initial-p e2
)
863 (< (pprint-dispatch-entry-priority e1
)
864 (pprint-dispatch-entry-priority e2
)))))
866 (macrolet ((frob (name x
)
867 `(cons ',x
(named-lambda ,(symbolicate "PPRINT-DISPATCH-" name
) (object)
869 (defvar *precompiled-pprint-dispatch-funs
*
870 (list (frob array
(typep object
'array
))
871 (frob sharp-function
(and (consp object
)
872 (symbolp (car object
))
873 (fboundp (car object
))))
874 (frob cons
(typep object
'cons
)))))
876 (defun compute-test-fn (type)
877 (let ((was-cons nil
))
878 (labels ((compute-test-expr (type object
)
884 (&optional
(car nil car-p
) (cdr nil cdr-p
))
886 `(and (consp ,object
)
888 `(,(compute-test-expr
889 car
`(car ,object
))))
891 `(,(compute-test-expr
892 cdr
`(cdr ,object
)))))))
894 (destructuring-bind (type) (cdr type
)
895 `(not ,(compute-test-expr type object
))))
897 `(and ,@(mapcar (lambda (type)
898 (compute-test-expr type object
))
901 `(or ,@(mapcar (lambda (type)
902 (compute-test-expr type object
))
905 `(typep ,object
',type
)))
906 `(typep ,object
',type
))))
907 (let ((expr (compute-test-expr type
'object
)))
908 (cond ((cdr (assoc expr
*precompiled-pprint-dispatch-funs
*
911 (let ((name (symbolicate "PPRINT-DISPATCH-"
914 (write-to-string type
918 (compile nil
`(named-lambda ,name
(object)
921 (defun copy-pprint-dispatch (&optional
(table *print-pprint-dispatch
*))
922 (declare (type (or pprint-dispatch-table null
) table
))
923 (let* ((orig (or table
*initial-pprint-dispatch
*))
924 (new (make-pprint-dispatch-table
925 :entries
(copy-list (pprint-dispatch-table-entries orig
))))
926 (new-cons-entries (pprint-dispatch-table-cons-entries new
)))
927 (maphash (lambda (key value
)
928 (setf (gethash key new-cons-entries
) value
))
929 (pprint-dispatch-table-cons-entries orig
))
932 (defun pprint-dispatch (object &optional
(table *print-pprint-dispatch
*))
933 (declare (type (or pprint-dispatch-table null
) table
))
934 (let* ((table (or table
*initial-pprint-dispatch
*))
937 (gethash (car object
)
938 (pprint-dispatch-table-cons-entries table
))))
940 (dolist (entry (pprint-dispatch-table-entries table
) cons-entry
)
941 (when (and cons-entry
942 (entry< entry cons-entry
))
944 (when (funcall (pprint-dispatch-entry-test-fn entry
) object
)
947 (values (pprint-dispatch-entry-fun entry
) t
)
948 (values (lambda (stream object
)
949 (output-ugly-object object stream
))
952 (defun set-pprint-dispatch (type function
&optional
953 (priority 0) (table *print-pprint-dispatch
*))
954 (declare (type (or null callable
) function
)
956 (type pprint-dispatch-table table
))
957 (/show0
"entering SET-PPRINT-DISPATCH, TYPE=...")
960 (if (cons-type-specifier-p type
)
961 (setf (gethash (second (second type
))
962 (pprint-dispatch-table-cons-entries table
))
963 (make-pprint-dispatch-entry :type type
966 (let ((list (delete type
(pprint-dispatch-table-entries table
)
967 :key
#'pprint-dispatch-entry-type
969 (entry (make-pprint-dispatch-entry
971 :test-fn
(compute-test-fn type
)
975 (next list
(cdr next
)))
978 (setf (cdr prev
) (list entry
))
979 (setf list
(list entry
))))
980 (when (entry< (car next
) entry
)
982 (setf (cdr prev
) (cons entry next
))
983 (setf list
(cons entry next
)))
985 (setf (pprint-dispatch-table-entries table
) list
)))
986 (if (cons-type-specifier-p type
)
987 (remhash (second (second type
))
988 (pprint-dispatch-table-cons-entries table
))
989 (setf (pprint-dispatch-table-entries table
)
990 (delete type
(pprint-dispatch-table-entries table
)
991 :key
#'pprint-dispatch-entry-type
993 (/show0
"about to return NIL from SET-PPRINT-DISPATCH")
996 ;;;; standard pretty-printing routines
998 (defun pprint-array (stream array
)
999 (cond ((or (and (null *print-array
*) (null *print-readably
*))
1001 (bit-vector-p array
))
1002 (output-ugly-object array stream
))
1003 ((and *print-readably
*
1004 (not (array-readably-printable-p array
)))
1005 (let ((*print-readably
* nil
))
1006 (error 'print-not-readable
:object array
)))
1008 (pprint-vector stream array
))
1010 (pprint-multi-dim-array stream array
))))
1012 (defun pprint-vector (stream vector
)
1013 (pprint-logical-block (stream nil
:prefix
"#(" :suffix
")")
1014 (dotimes (i (length vector
))
1016 (format stream
" ~:_"))
1018 (output-object (aref vector i
) stream
))))
1020 (defun pprint-multi-dim-array (stream array
)
1021 (funcall (formatter "#~DA") stream
(array-rank array
))
1022 (with-array-data ((data array
) (start) (end))
1023 (declare (ignore end
))
1024 (labels ((output-guts (stream index dimensions
)
1025 (if (null dimensions
)
1026 (output-object (aref data index
) stream
)
1027 (pprint-logical-block
1028 (stream nil
:prefix
"(" :suffix
")")
1029 (let ((dim (car dimensions
)))
1031 (let* ((dims (cdr dimensions
))
1033 (step (reduce #'* dims
))
1037 (output-guts stream index dims
)
1038 (when (= (incf count
) dim
)
1040 (write-char #\space stream
)
1041 (pprint-newline (if dims
:linear
:fill
)
1043 (incf index step
)))))))))
1044 (output-guts stream start
(array-dimensions array
)))))
1046 (defun pprint-lambda-list (stream lambda-list
&rest noise
)
1047 (declare (ignore noise
))
1048 (when (and (consp lambda-list
)
1049 (member (car lambda-list
) *backq-tokens
*))
1050 ;; if this thing looks like a backquoty thing, then we don't want
1051 ;; to destructure it, we want to output it straight away. [ this
1052 ;; is the exception to the normal processing: if we did this
1053 ;; generally we would find lambda lists such as (FUNCTION FOO)
1054 ;; being printed as #'FOO ] -- CSR, 2003-12-07
1055 (output-object lambda-list stream
)
1056 (return-from pprint-lambda-list nil
))
1057 (pprint-logical-block (stream lambda-list
:prefix
"(" :suffix
")")
1058 (let ((state :required
)
1061 (pprint-exit-if-list-exhausted)
1063 (write-char #\space stream
))
1064 (let ((arg (pprint-pop)))
1068 (setf state
:optional
)
1069 (pprint-newline :linear stream
))
1071 (setf state
:required
)
1072 (pprint-newline :linear stream
))
1075 (pprint-newline :linear stream
))
1077 (setf state
:optional
)
1078 (pprint-newline :linear stream
))
1080 (pprint-newline :fill stream
))))
1083 (pprint-lambda-list stream arg
))
1085 (pprint-logical-block
1086 (stream arg
:prefix
"(" :suffix
")")
1087 (pprint-exit-if-list-exhausted)
1089 (pprint-logical-block
1090 (stream (pprint-pop) :prefix
"(" :suffix
")")
1091 (pprint-exit-if-list-exhausted)
1092 (output-object (pprint-pop) stream
)
1093 (pprint-exit-if-list-exhausted)
1094 (write-char #\space stream
)
1095 (pprint-newline :fill stream
)
1096 (pprint-lambda-list stream
(pprint-pop))
1098 (pprint-exit-if-list-exhausted)
1099 (write-char #\space stream
)
1100 (pprint-newline :fill stream
)
1101 (output-object (pprint-pop) stream
)))
1102 (pprint-lambda-list stream
(pprint-pop)))
1104 (pprint-exit-if-list-exhausted)
1105 (write-char #\space stream
)
1106 (pprint-newline :linear stream
)
1107 (output-object (pprint-pop) stream
))))))
1108 (setf first nil
)))))
1110 (defun pprint-lambda (stream list
&rest noise
)
1111 (declare (ignore noise
))
1113 ;; KLUDGE: This format string, and other format strings which also
1114 ;; refer to SB!PRETTY, rely on the current SBCL not-quite-ANSI
1115 ;; behavior of FORMATTER in order to make code which survives the
1116 ;; transition when SB!PRETTY is renamed to SB-PRETTY after cold
1117 ;; init. (ANSI says that the FORMATTER functions should be
1118 ;; equivalent to the format string, but the SBCL FORMATTER
1119 ;; functions contain references to package objects, not package
1120 ;; names, so they keep right on going if the packages are renamed.)
1121 ;; If our FORMATTER behavior is ever made more compliant, the code
1122 ;; here will have to change. -- WHN 19991207
1123 "~:<~^~W~^~3I ~:_~/SB!PRETTY:PPRINT-LAMBDA-LIST/~1I~@{ ~_~W~}~:>")
1127 (defun pprint-block (stream list
&rest noise
)
1128 (declare (ignore noise
))
1129 (funcall (formatter "~:<~^~W~^~3I ~:_~W~1I~@{ ~_~W~}~:>") stream list
))
1131 (defun pprint-flet (stream list
&rest noise
)
1132 (declare (ignore noise
))
1133 (if (and (consp list
)
1137 "~:<~^~W~^ ~@_~:<~@{~:<~^~W~^~3I ~:_~/SB!PRETTY:PPRINT-LAMBDA-LIST/~1I~:@_~@{~W~^ ~_~}~:>~^ ~_~}~:>~1I~@:_~@{~W~^ ~_~}~:>")
1140 ;; for printing function names like (flet foo)
1141 (pprint-logical-block (stream list
:prefix
"(" :suffix
")")
1142 (pprint-exit-if-list-exhausted)
1143 (write (pprint-pop) :stream stream
)
1145 (pprint-exit-if-list-exhausted)
1146 (write-char #\space stream
)
1147 (write (pprint-pop) :stream stream
)))))
1149 (defun pprint-let (stream list
&rest noise
)
1150 (declare (ignore noise
))
1151 (funcall (formatter "~:<~^~W~^ ~@_~:<~@{~:<~^~W~@{ ~_~W~}~:>~^ ~_~}~:>~1I~:@_~@{~W~^ ~_~}~:>")
1155 (defun pprint-progn (stream list
&rest noise
)
1156 (declare (ignore noise
))
1157 (funcall (formatter "~:<~^~W~@{ ~_~W~}~:>") stream list
))
1159 (defun pprint-progv (stream list
&rest noise
)
1160 (declare (ignore noise
))
1161 (funcall (formatter "~:<~^~W~^~3I ~_~W~^ ~_~W~^~1I~@{ ~_~W~}~:>")
1164 (defun pprint-quote (stream list
&rest noise
)
1165 (declare (ignore noise
))
1166 (if (and (consp list
)
1171 (write-string "#'" stream
)
1172 (output-object (cadr list
) stream
))
1174 (write-char #\' stream
)
1175 (output-object (cadr list
) stream
))
1177 (pprint-fill stream list
)))
1178 (pprint-fill stream list
)))
1180 (defun pprint-setq (stream list
&rest noise
)
1181 (declare (ignore noise
))
1182 (pprint-logical-block (stream list
:prefix
"(" :suffix
")")
1183 (pprint-exit-if-list-exhausted)
1184 (output-object (pprint-pop) stream
)
1185 (pprint-exit-if-list-exhausted)
1186 (write-char #\space stream
)
1187 (pprint-newline :miser stream
)
1188 (if (and (consp (cdr list
)) (consp (cddr list
)))
1190 (pprint-indent :current
2 stream
)
1191 (output-object (pprint-pop) stream
)
1192 (pprint-exit-if-list-exhausted)
1193 (write-char #\space stream
)
1194 (pprint-newline :linear stream
)
1195 (pprint-indent :current -
2 stream
)
1196 (output-object (pprint-pop) stream
)
1197 (pprint-exit-if-list-exhausted)
1198 (write-char #\space stream
)
1199 (pprint-newline :linear stream
))
1201 (pprint-indent :current
0 stream
)
1202 (output-object (pprint-pop) stream
)
1203 (pprint-exit-if-list-exhausted)
1204 (write-char #\space stream
)
1205 (pprint-newline :linear stream
)
1206 (output-object (pprint-pop) stream
)))))
1208 ;;; FIXME: could become SB!XC:DEFMACRO wrapped in EVAL-WHEN (COMPILE EVAL)
1209 (defmacro pprint-tagbody-guts
(stream)
1211 (pprint-exit-if-list-exhausted)
1212 (write-char #\space
,stream
)
1213 (let ((form-or-tag (pprint-pop)))
1214 (pprint-indent :block
1215 (if (atom form-or-tag
) 0 1)
1217 (pprint-newline :linear
,stream
)
1218 (output-object form-or-tag
,stream
))))
1220 (defun pprint-tagbody (stream list
&rest noise
)
1221 (declare (ignore noise
))
1222 (pprint-logical-block (stream list
:prefix
"(" :suffix
")")
1223 (pprint-exit-if-list-exhausted)
1224 (output-object (pprint-pop) stream
)
1225 (pprint-tagbody-guts stream
)))
1227 (defun pprint-case (stream list
&rest noise
)
1228 (declare (ignore noise
))
1230 "~:<~^~W~^ ~3I~:_~W~1I~@{ ~_~:<~^~:/SB!PRETTY:PPRINT-FILL/~^~@{ ~_~W~}~:>~}~:>")
1234 (defun pprint-defun (stream list
&rest noise
)
1235 (declare (ignore noise
))
1237 "~:<~^~W~^ ~@_~:I~W~^ ~:_~/SB!PRETTY:PPRINT-LAMBDA-LIST/~1I~@{ ~_~W~}~:>")
1241 (defun pprint-destructuring-bind (stream list
&rest noise
)
1242 (declare (ignore noise
))
1244 "~:<~^~W~^~3I ~_~:/SB!PRETTY:PPRINT-LAMBDA-LIST/~^ ~_~W~^~1I~@{ ~_~W~}~:>")
1247 (defun pprint-do (stream list
&rest noise
)
1248 (declare (ignore noise
))
1249 (pprint-logical-block (stream list
:prefix
"(" :suffix
")")
1250 (pprint-exit-if-list-exhausted)
1251 (output-object (pprint-pop) stream
)
1252 (pprint-exit-if-list-exhausted)
1253 (write-char #\space stream
)
1254 (pprint-indent :current
0 stream
)
1255 (funcall (formatter "~:<~@{~:<~^~W~^ ~@_~:I~W~@{ ~_~W~}~:>~^~:@_~}~:>")
1258 (pprint-exit-if-list-exhausted)
1259 (write-char #\space stream
)
1260 (pprint-newline :linear stream
)
1261 (pprint-linear stream
(pprint-pop))
1262 (pprint-tagbody-guts stream
)))
1264 (defun pprint-dolist (stream list
&rest noise
)
1265 (declare (ignore noise
))
1266 (pprint-logical-block (stream list
:prefix
"(" :suffix
")")
1267 (pprint-exit-if-list-exhausted)
1268 (output-object (pprint-pop) stream
)
1269 (pprint-exit-if-list-exhausted)
1270 (pprint-indent :block
3 stream
)
1271 (write-char #\space stream
)
1272 (pprint-newline :fill stream
)
1273 (funcall (formatter "~:<~^~W~^ ~:_~:I~W~@{ ~_~W~}~:>")
1276 (pprint-tagbody-guts stream
)))
1278 (defun pprint-typecase (stream list
&rest noise
)
1279 (declare (ignore noise
))
1281 "~:<~^~W~^ ~3I~:_~W~1I~@{ ~_~:<~^~W~^~@{ ~_~W~}~:>~}~:>")
1285 (defun pprint-prog (stream list
&rest noise
)
1286 (declare (ignore noise
))
1287 (pprint-logical-block (stream list
:prefix
"(" :suffix
")")
1288 (pprint-exit-if-list-exhausted)
1289 (output-object (pprint-pop) stream
)
1290 (pprint-exit-if-list-exhausted)
1291 (write-char #\space stream
)
1292 (pprint-newline :miser stream
)
1293 (pprint-fill stream
(pprint-pop))
1294 (pprint-tagbody-guts stream
)))
1296 (defun pprint-fun-call (stream list
&rest noise
)
1297 (declare (ignore noise
))
1298 (funcall (formatter "~:<~^~W~^ ~:_~:I~@{~W~^ ~:_~}~:>")
1302 (defun pprint-data-list (stream list
&rest noise
)
1303 (declare (ignore noise
))
1304 (funcall (formatter "~:<~@{~W~^ ~:_~}~:>") stream list
))
1306 ;;;; the interface seen by regular (ugly) printer and initialization routines
1308 ;;; OUTPUT-PRETTY-OBJECT is called by OUTPUT-OBJECT when
1309 ;;; *PRINT-PRETTY* is true.
1310 (defun output-pretty-object (object stream
)
1311 (with-pretty-stream (stream)
1312 (funcall (pprint-dispatch object
) stream object
)))
1314 (defun !pprint-cold-init
()
1315 (/show0
"entering !PPRINT-COLD-INIT")
1316 (setf *initial-pprint-dispatch
* (make-pprint-dispatch-table))
1317 (let ((*print-pprint-dispatch
* *initial-pprint-dispatch
*)
1318 (*building-initial-table
* t
))
1319 ;; printers for regular types
1320 (/show0
"doing SET-PPRINT-DISPATCH for regular types")
1321 (set-pprint-dispatch 'array
#'pprint-array
)
1322 (set-pprint-dispatch '(cons (and symbol
(satisfies fboundp
)))
1323 #'pprint-fun-call -
1)
1324 (set-pprint-dispatch '(cons symbol
)
1325 #'pprint-data-list -
2)
1326 (set-pprint-dispatch 'cons
#'pprint-fill -
2)
1327 ;; cons cells with interesting things for the car
1328 (/show0
"doing SET-PPRINT-DISPATCH for CONS with interesting CAR")
1330 (dolist (magic-form '((lambda pprint-lambda
)
1333 (block pprint-block
)
1334 (catch pprint-block
)
1335 (eval-when pprint-block
)
1337 (function pprint-quote
)
1338 (labels pprint-flet
)
1341 (locally pprint-progn
)
1342 (macrolet pprint-flet
)
1343 (multiple-value-call pprint-block
)
1344 (multiple-value-prog1 pprint-block
)
1345 (progn pprint-progn
)
1346 (progv pprint-progv
)
1347 (quote pprint-quote
)
1348 (return-from pprint-block
)
1350 (symbol-macrolet pprint-let
)
1351 (tagbody pprint-tagbody
)
1352 (throw pprint-block
)
1353 (unwind-protect pprint-block
)
1358 (ctypecase pprint-typecase
)
1359 (defconstant pprint-block
)
1360 (define-modify-macro pprint-defun
)
1361 (define-setf-expander pprint-defun
)
1362 (defmacro pprint-defun
)
1363 (defparameter pprint-block
)
1364 (defsetf pprint-defun
)
1365 (defstruct pprint-block
)
1366 (deftype pprint-defun
)
1367 (defun pprint-defun)
1368 (defvar pprint-block
)
1369 (destructuring-bind pprint-destructuring-bind
)
1372 (do-all-symbols pprint-dolist
)
1373 (do-external-symbols pprint-dolist
)
1374 (do-symbols pprint-dolist
)
1375 (dolist pprint-dolist
)
1376 (dotimes pprint-dolist
)
1378 (etypecase pprint-typecase
)
1379 #+nil
(handler-bind ...
)
1380 #+nil
(handler-case ...
)
1382 (multiple-value-bind pprint-progv
)
1383 (multiple-value-setq pprint-block
)
1384 (pprint-logical-block pprint-block
)
1385 (print-unreadable-object pprint-block
)
1388 (prog1 pprint-block
)
1389 (prog2 pprint-progv
)
1392 #+nil
(restart-bind ...
)
1393 #+nil
(restart-case ...
)
1397 (typecase pprint-typecase
)
1398 (unless pprint-block
)
1400 (with-compilation-unit pprint-block
)
1401 #+nil
(with-condition-restarts ...
)
1402 (with-hash-table-iterator pprint-block
)
1403 (with-input-from-string pprint-block
)
1404 (with-open-file pprint-block
)
1405 (with-open-stream pprint-block
)
1406 (with-output-to-string pprint-block
)
1407 (with-package-iterator pprint-block
)
1408 (with-simple-restart pprint-block
)
1409 (with-standard-io-syntax pprint-progn
)))
1411 (set-pprint-dispatch `(cons (eql ,(first magic-form
)))
1412 (symbol-function (second magic-form
))))
1414 ;; other pretty-print init forms
1415 (/show0
"about to call !BACKQ-PP-COLD-INIT")
1416 (sb!impl
::!backq-pp-cold-init
)
1417 (/show0
"leaving !PPRINT-COLD-INIT"))
1419 (setf *print-pprint-dispatch
* (copy-pprint-dispatch nil
))
1420 (setf *print-pretty
* t
))