1 ;;;; printer stuff which has to be defined early (e.g. DEFMACROs)
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!IMPL")
17 ;;;; level and length abbreviations
19 (defvar *current-level* 0
21 "The current level we are printing at, to be compared against *PRINT-LEVEL*.
22 See the macro DESCEND-INTO for a handy interface to depth abbreviation.")
24 (defmacro descend-into ((stream) &body body)
26 "Automatically handle *PRINT-LEVEL* abbreviation. If we are too deep, then
27 a # is printed to STREAM and BODY is ignored."
28 (let ((flet-name (gensym)))
29 `(flet ((,flet-name ()
31 (cond ((and (null *print-readably*)
33 (>= *current-level* *print-level*))
34 (write-char #\# ,stream))
36 (let ((*current-level* (1+ *current-level*)))
39 (defmacro punt-if-too-long (index stream)
41 "Punt if INDEX is equal or larger then *PRINT-LENGTH* (and *PRINT-READABLY*
42 is NIL) by outputting \"...\" and returning from the block named NIL."
43 `(when (and (not *print-readably*)
45 (>= ,index *print-length*))
46 (write-string "..." ,stream)