0.6.7.22: removed CVS dollar-Header-dollar tags from sources
[sbcl.git] / src / code / early-print.lisp
1 ;;;; printer stuff which has to be defined early (e.g. DEFMACROs)
2
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
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.
11
12 (in-package "SB!IMPL")
13 \f
14 ;;;; level and length abbreviations
15
16 (defvar *current-level* 0
17   #!+sb-doc
18   "The current level we are printing at, to be compared against *PRINT-LEVEL*.
19    See the macro DESCEND-INTO for a handy interface to depth abbreviation.")
20
21 (defmacro descend-into ((stream) &body body)
22   #!+sb-doc
23   "Automatically handle *PRINT-LEVEL* abbreviation. If we are too deep, then
24    a # is printed to STREAM and BODY is ignored."
25   (let ((flet-name (gensym)))
26     `(flet ((,flet-name ()
27               ,@body))
28        (cond ((and (null *print-readably*)
29                    *print-level*
30                    (>= *current-level* *print-level*))
31               (write-char #\# ,stream))
32              (t
33               (let ((*current-level* (1+ *current-level*)))
34                 (,flet-name)))))))
35
36 (defmacro punt-if-too-long (index stream)
37   #!+sb-doc
38   "Punt if INDEX is equal or larger then *PRINT-LENGTH* (and *PRINT-READABLY*
39    is NIL) by outputting \"...\" and returning from the block named NIL."
40   `(when (and (not *print-readably*)
41               *print-length*
42               (>= ,index *print-length*))
43      (write-string "..." ,stream)
44      (return)))