annotate lisp/emacs-lisp/cust-print.el @ 15132:c89db56c289b

(CONFIG_H) [WIN95]: Use config.nt.
author Geoff Voelker <voelker@cs.washington.edu>
date Fri, 03 May 1996 18:20:11 +0000
parents baefeadae7a3
children 693b53fde264
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2230
6314334d7c2b Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2229
diff changeset
1 ;;; cust-print.el --- handles print-level and print-circle.
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2
845
213978acbc1e entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 811
diff changeset
3 ;; Copyright (C) 1992 Free Software Foundation, Inc.
213978acbc1e entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 811
diff changeset
4
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 655
diff changeset
5 ;; Author: Daniel LaLiberte <liberte@cs.uiuc.edu>
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 655
diff changeset
6 ;; Adapted-By: ESR
2247
2c7997f249eb Add or correct keywords
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2230
diff changeset
7 ;; Keywords: extensions
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
8
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
9 ;; LCD Archive Entry:
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
10 ;; cust-print|Daniel LaLiberte|liberte@cs.uiuc.edu
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
11 ;; |Handle print-level, print-circle and more.
6779
baefeadae7a3 Jumping up to new revision.
Daniel LaLiberte <liberte@gnu.org>
parents: 6687
diff changeset
12 ;; |$Date: 1994/04/05 21:05:09 $|$Revision: 1.14 $|
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
13
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
14 ;; This file is part of GNU Emacs.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
15
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
16 ;; GNU Emacs is free software; you can redistribute it and/or modify
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
17 ;; it under the terms of the GNU General Public License as published by
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 655
diff changeset
18 ;; the Free Software Foundation; either version 2, or (at your option)
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
19 ;; any later version.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
20
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
21 ;; GNU Emacs is distributed in the hope that it will be useful,
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
24 ;; GNU General Public License for more details.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
25
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
26 ;; You should have received a copy of the GNU General Public License
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
27 ;; along with GNU Emacs; see the file COPYING. If not, write to
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
28 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
29
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
30 ;;; ===============================
6779
baefeadae7a3 Jumping up to new revision.
Daniel LaLiberte <liberte@gnu.org>
parents: 6687
diff changeset
31 ;;; $Header: $
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
32 ;;; $Log: cust-print.el,v $
6779
baefeadae7a3 Jumping up to new revision.
Daniel LaLiberte <liberte@gnu.org>
parents: 6687
diff changeset
33 ;;; Revision 1.14 1994/04/05 21:05:09 liberte
baefeadae7a3 Jumping up to new revision.
Daniel LaLiberte <liberte@gnu.org>
parents: 6687
diff changeset
34 ;;; Change install- and uninstall- to -install and -uninstall.
baefeadae7a3 Jumping up to new revision.
Daniel LaLiberte <liberte@gnu.org>
parents: 6687
diff changeset
35 ;;;
6687
30c38858c0d0 Change install- and uninstall- to -install and -uninstall.
Daniel LaLiberte <liberte@gnu.org>
parents: 6511
diff changeset
36 ;;; Revision 1.13 1994/03/24 20:26:05 liberte
30c38858c0d0 Change install- and uninstall- to -install and -uninstall.
Daniel LaLiberte <liberte@gnu.org>
parents: 6511
diff changeset
37 ;;; Change "internal" to "original" throughout.
30c38858c0d0 Change install- and uninstall- to -install and -uninstall.
Daniel LaLiberte <liberte@gnu.org>
parents: 6511
diff changeset
38 ;;; (add-custom-printer, delete-custom-printer) replace customizers.
30c38858c0d0 Change install- and uninstall- to -install and -uninstall.
Daniel LaLiberte <liberte@gnu.org>
parents: 6511
diff changeset
39 ;;; (with-custom-print) new
30c38858c0d0 Change install- and uninstall- to -install and -uninstall.
Daniel LaLiberte <liberte@gnu.org>
parents: 6511
diff changeset
40 ;;; (custom-prin1-to-string) Made it more robust.
30c38858c0d0 Change install- and uninstall- to -install and -uninstall.
Daniel LaLiberte <liberte@gnu.org>
parents: 6511
diff changeset
41 ;;;
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
42 ;;; Revision 1.4 1994/03/23 20:34:29 liberte
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
43 ;;; * Change "emacs" to "original" - I just can't decide.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
44 ;;;
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
45 ;;; Revision 1.3 1994/02/21 21:25:36 liberte
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
46 ;;; * Make custom-prin1-to-string more robust when errors occur.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
47 ;;; * Change "internal" to "emacs".
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
48 ;;;
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
49 ;;; Revision 1.2 1993/11/22 22:36:36 liberte
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
50 ;;; * Simplified and generalized printer customization.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
51 ;;; custom-printers is an alist of (PREDICATE . PRINTER) pairs
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
52 ;;; for any data types. The PRINTER function should print to
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
53 ;;; `standard-output' add-custom-printer and delete-custom-printer
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
54 ;;; change custom-printers.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
55 ;;;
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
56 ;;; * Installation function now called install-custom-print. The
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
57 ;;; old name is still around for now.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
58 ;;;
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
59 ;;; * New macro with-custom-print (added earlier) - executes like
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
60 ;;; progn but with custom-print activated temporarily.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
61 ;;;
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
62 ;;; * Cleaned up comments for replacements of standardard printers.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
63 ;;;
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
64 ;;; * Changed custom-prin1-to-string to use a temporary buffer.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
65 ;;;
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
66 ;;; * Option custom-print-vectors (added earlier) - controls whether
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
67 ;;; vectors should be printed according to print-length and
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
68 ;;; print-length. Emacs doesnt do this, but cust-print would
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
69 ;;; otherwise do it only if custom printing is required.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
70 ;;;
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
71 ;;; * Uninterned symbols are treated as non-read-equivalent.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
72 ;;;
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
73
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
74
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 655
diff changeset
75 ;;; Commentary:
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 655
diff changeset
76
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
77 ;; This package provides a general print handler for prin1 and princ
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
78 ;; that supports print-level and print-circle, and by the way,
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
79 ;; print-length since the standard routines are being replaced. Also,
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
80 ;; to print custom types constructed from lists and vectors, use
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
81 ;; custom-print-list and custom-print-vector. See the documentation
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
82 ;; strings of these variables for more details.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
83
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
84 ;; If the results of your expressions contain circular references to
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
85 ;; other parts of the same structure, the standard Emacs print
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
86 ;; subroutines may fail to print with an untrappable error,
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
87 ;; "Apparently circular structure being printed". If you only use cdr
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
88 ;; circular lists (where cdrs of lists point back; what is the right
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
89 ;; term here?), you can limit the length of printing with
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
90 ;; print-length. But car circular lists and circular vectors generate
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
91 ;; the above mentioned error in Emacs version 18. Version
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
92 ;; 19 supports print-level, but it is often useful to get a better
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
93 ;; print representation of circular and shared structures; the print-circle
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
94 ;; option may be used to print more concise representations.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
95
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
96 ;; There are three main ways to use this package. First, you may
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
97 ;; replace prin1, princ, and some subroutines that use them by calling
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
98 ;; install-custom-print so that any use of these functions in
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
99 ;; Lisp code will be affected; you can later reset with
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
100 ;; uninstall-custom-print. Second, you may temporarily install
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
101 ;; these functions with the macro with-custom-print. Third, you
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
102 ;; could call the custom routines directly, thus only affecting the
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
103 ;; printing that requires them.
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
104
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
105 ;; Note that subroutines which call print subroutines directly will
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
106 ;; not use the custom print functions. In particular, the evaluation
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
107 ;; functions like eval-region call the print subroutines directly.
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
108 ;; Therefore, if you evaluate (aref circ-list 0), where circ-list is a
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
109 ;; circular list rather than an array, aref calls error directly which
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
110 ;; will jump to the top level instead of printing the circular list.
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
111
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
112 ;; Uninterned symbols are recognized when print-circle is non-nil,
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
113 ;; but they are not printed specially here. Use the cl-packages package
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
114 ;; to print according to print-gensym.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
115
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
116 ;; Obviously the right way to implement this custom-print facility is
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
117 ;; in C or with hooks into the standard printer. Please volunteer
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
118 ;; since I don't have the time or need. More CL-like printing
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
119 ;; capabilities could be added in the future.
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
120
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
121 ;; Implementation design: we want to use the same list and vector
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
122 ;; processing algorithm for all versions of prin1 and princ, since how
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
123 ;; the processing is done depends on print-length, print-level, and
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
124 ;; print-circle. For circle printing, a preprocessing step is
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
125 ;; required before the final printing. Thanks to Jamie Zawinski
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
126 ;; for motivation and algorithms.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
127
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
128
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
129 ;;; Code:
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
130 ;;=========================================================
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
131
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
132 ;; If using cl-packages:
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
133
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
134 '(defpackage "cust-print"
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
135 (:nicknames "CP" "custom-print")
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
136 (:use "el")
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
137 (:export
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
138 print-level
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
139 print-circle
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
140
6687
30c38858c0d0 Change install- and uninstall- to -install and -uninstall.
Daniel LaLiberte <liberte@gnu.org>
parents: 6511
diff changeset
141 custom-print-install
30c38858c0d0 Change install- and uninstall- to -install and -uninstall.
Daniel LaLiberte <liberte@gnu.org>
parents: 6511
diff changeset
142 custom-print-uninstall
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
143 custom-print-installed-p
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
144 with-custom-print
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
145
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
146 custom-prin1
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
147 custom-princ
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
148 custom-prin1-to-string
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
149 custom-print
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
150 custom-format
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
151 custom-message
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
152 custom-error
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
153
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
154 custom-printers
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
155 add-custom-printer
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
156 ))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
157
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
158 '(in-package cust-print)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
159
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
160 (require 'backquote)
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
161
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
162 ;; Emacs 18 doesnt have defalias.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
163 ;; Provide def for byte compiler.
6779
baefeadae7a3 Jumping up to new revision.
Daniel LaLiberte <liberte@gnu.org>
parents: 6687
diff changeset
164 (eval-and-compile
baefeadae7a3 Jumping up to new revision.
Daniel LaLiberte <liberte@gnu.org>
parents: 6687
diff changeset
165 (or (fboundp 'defalias) (fset 'defalias 'fset)))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
166
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
167
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
168 ;; Variables:
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
169 ;;=========================================================
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
170
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
171 ;;(defvar print-length nil
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
172 ;; "*Controls how many elements of a list, at each level, are printed.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
173 ;;This is defined by emacs.")
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
174
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
175 (defvar print-level nil
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
176 "*Controls how many levels deep a nested data object will print.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
177
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
178 If nil, printing proceeds recursively and may lead to
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
179 max-lisp-eval-depth being exceeded or an error may occur:
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
180 `Apparently circular structure being printed.'
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
181 Also see `print-length' and `print-circle'.
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
182
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
183 If non-nil, components at levels equal to or greater than `print-level'
1366
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
184 are printed simply as `#'. The object to be printed is at level 0,
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
185 and if the object is a list or vector, its top-level components are at
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
186 level 1.")
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
187
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
188
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
189 (defvar print-circle nil
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
190 "*Controls the printing of recursive structures.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
191
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
192 If nil, printing proceeds recursively and may lead to
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
193 `max-lisp-eval-depth' being exceeded or an error may occur:
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
194 \"Apparently circular structure being printed.\" Also see
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
195 `print-length' and `print-level'.
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
196
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
197 If non-nil, shared substructures anywhere in the structure are printed
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 2571
diff changeset
198 with `#N=' before the first occurrence (in the order of the print
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 2571
diff changeset
199 representation) and `#N#' in place of each subsequent occurrence,
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
200 where N is a positive decimal integer.
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
201
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
202 There is no way to read this representation in standard Emacs,
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
203 but if you need to do so, try the cl-read.el package.")
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
204
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
205
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
206 (defvar custom-print-vectors nil
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
207 "*Non-nil if printing of vectors should obey print-level and print-length.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
208
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
209 For Emacs 18, setting print-level, or adding custom print list or
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
210 vector handling will make this happen anyway. Emacs 19 obeys
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
211 print-level, but not for vectors.")
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
212
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
213
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
214 ;; Custom printers
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
215 ;;==========================================================
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
216
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
217 (defconst custom-printers nil
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
218 ;; e.g. '((symbolp . pkg::print-symbol))
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
219 "An alist for custom printing of any type.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
220 Pairs are of the form (PREDICATE . PRINTER). If PREDICATE is true
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
221 for an object, then PRINTER is called with the object.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
222 PRINTER should print to `standard-output' using cust-print-original-princ
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
223 if the standard printer is sufficient, or cust-print-prin for complex things.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
224 The PRINTER should return the object being printed.
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
225
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
226 Don't modify this variable directly. Use `add-custom-printer' and
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
227 `delete-custom-printer'")
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
228 ;; Should cust-print-original-princ and cust-print-prin be exported symbols?
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
229 ;; Or should the standard printers functions be replaced by
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
230 ;; CP ones in elisp so that CP internal functions need not be called?
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
231
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
232 (defun add-custom-printer (pred printer)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
233 "Add a pair of PREDICATE and PRINTER to `custom-printers'.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
234 Any pair that has the same PREDICATE is first removed."
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
235 (setq custom-printers (cons (cons pred printer)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
236 (delq (assq pred custom-printers)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
237 custom-printers)))
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
238 ;; Rather than updating here, we could wait until cust-print-top-level is called.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
239 (cust-print-update-custom-printers))
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
240
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
241 (defun delete-custom-printer (pred)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
242 "Delete the custom printer associated with PREDICATE."
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
243 (setq custom-printers (delq (assq pred custom-printers)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
244 custom-printers))
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
245 (cust-print-update-custom-printers))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
246
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
247
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
248 (defun cust-print-use-custom-printer (object)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
249 ;; Default function returns nil.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
250 nil)
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
251
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
252 (defun cust-print-update-custom-printers ()
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
253 ;; Modify the definition of cust-print-use-custom-printer
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
254 (defalias 'cust-print-use-custom-printer
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
255 ;; We dont really want to require the byte-compiler.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
256 ;; (byte-compile
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
257 (` (lambda (object)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
258 (cond
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
259 (,@ (mapcar (function
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
260 (lambda (pair)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
261 (` (((, (car pair)) object)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
262 ((, (cdr pair)) object)))))
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
263 custom-printers))
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
264 ;; Otherwise return nil.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
265 (t nil)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
266 )))
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
267 ;; )
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
268 ))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
269
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
270
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
271 ;; Saving and restoring emacs printing routines.
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
272 ;;====================================================
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
273
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
274 (defun cust-print-set-function-cell (symbol-pair)
2571
b65cf676a09b All fsets changed to defaliases.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2247
diff changeset
275 (defalias (car symbol-pair)
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
276 (symbol-function (car (cdr symbol-pair)))))
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
277
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
278 (defun cust-print-original-princ (object &optional stream)) ; dummy def
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
279
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
280 ;; Save emacs routines.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
281 (if (not (fboundp 'cust-print-original-prin1))
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
282 (mapcar 'cust-print-set-function-cell
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
283 '((cust-print-original-prin1 prin1)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
284 (cust-print-original-princ princ)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
285 (cust-print-original-print print)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
286 (cust-print-original-prin1-to-string prin1-to-string)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
287 (cust-print-original-format format)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
288 (cust-print-original-message message)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
289 (cust-print-original-error error))))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
290
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
291
6687
30c38858c0d0 Change install- and uninstall- to -install and -uninstall.
Daniel LaLiberte <liberte@gnu.org>
parents: 6511
diff changeset
292 (defun custom-print-install ()
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
293 "Replace print functions with general, customizable, Lisp versions.
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
294 The emacs subroutines are saved away, and you can reinstall them
6687
30c38858c0d0 Change install- and uninstall- to -install and -uninstall.
Daniel LaLiberte <liberte@gnu.org>
parents: 6511
diff changeset
295 by running `custom-print-uninstall'."
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
296 (interactive)
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
297 (mapcar 'cust-print-set-function-cell
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
298 '((prin1 custom-prin1)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
299 (princ custom-princ)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
300 (print custom-print)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
301 (prin1-to-string custom-prin1-to-string)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
302 (format custom-format)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
303 (message custom-message)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
304 (error custom-error)
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
305 ))
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
306 t)
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
307
6687
30c38858c0d0 Change install- and uninstall- to -install and -uninstall.
Daniel LaLiberte <liberte@gnu.org>
parents: 6511
diff changeset
308 (defun custom-print-uninstall ()
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
309 "Reset print functions to their emacs subroutines."
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
310 (interactive)
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
311 (mapcar 'cust-print-set-function-cell
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
312 '((prin1 cust-print-original-prin1)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
313 (princ cust-print-original-princ)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
314 (print cust-print-original-print)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
315 (prin1-to-string cust-print-original-prin1-to-string)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
316 (format cust-print-original-format)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
317 (message cust-print-original-message)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
318 (error cust-print-original-error)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
319 ))
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
320 t)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
321
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
322 (defalias 'custom-print-funcs-installed-p 'custom-print-installed-p)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
323 (defun custom-print-installed-p ()
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
324 "Return t if custom-print is currently installed, nil otherwise."
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
325 (eq (symbol-function 'custom-prin1) (symbol-function 'prin1)))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
326
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
327 (put 'with-custom-print-funcs 'edebug-form-spec '(body))
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
328 (put 'with-custom-print 'edebug-form-spec '(body))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
329
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
330 (defalias 'with-custom-print-funcs 'with-custom-print)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
331 (defmacro with-custom-print (&rest body)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
332 "Temporarily install the custom print package while executing BODY."
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
333 (` (unwind-protect
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
334 (progn
6687
30c38858c0d0 Change install- and uninstall- to -install and -uninstall.
Daniel LaLiberte <liberte@gnu.org>
parents: 6511
diff changeset
335 (custom-print-install)
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
336 (,@ body))
6687
30c38858c0d0 Change install- and uninstall- to -install and -uninstall.
Daniel LaLiberte <liberte@gnu.org>
parents: 6511
diff changeset
337 (custom-print-uninstall))))
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
338
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
339
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
340 ;; Lisp replacements for prin1 and princ, and for some subrs that use them
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
341 ;;===============================================================
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
342 ;; - so far only the printing and formatting subrs.
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
343
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
344 (defun custom-prin1 (object &optional stream)
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
345 "Output the printed representation of OBJECT, any Lisp object.
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
346 Quoting characters are printed when needed to make output that `read'
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
347 can handle, whenever this is possible.
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
348 Output stream is STREAM, or value of `standard-output' (which see).
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
349
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
350 This is the custom-print replacement for the standard `prin1'. It
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
351 uses the appropriate printer depending on the values of `print-level'
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
352 and `print-circle' (which see)."
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
353 (cust-print-top-level object stream 'cust-print-original-prin1))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
354
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
355
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
356 (defun custom-princ (object &optional stream)
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
357 "Output the printed representation of OBJECT, any Lisp object.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
358 No quoting characters are used; no delimiters are printed around
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
359 the contents of strings.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
360 Output stream is STREAM, or value of `standard-output' (which see).
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
361
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
362 This is the custom-print replacement for the standard `princ'."
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
363 (cust-print-top-level object stream 'cust-print-original-princ))
1366
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
364
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
365
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
366 (defun custom-prin1-to-string (object)
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
367 "Return a string containing the printed representation of OBJECT,
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
368 any Lisp object. Quoting characters are used when needed to make output
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
369 that `read' can handle, whenever this is possible.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
370
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
371 This is the custom-print replacement for the standard `prin1-to-string'."
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
372 (let ((buf (get-buffer-create " *custom-print-temp*")))
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
373 ;; We must erase the buffer before printing in case an error
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
374 ;; occured during the last prin1-to-string and we are in debugger.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
375 (save-excursion
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
376 (set-buffer buf)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
377 (erase-buffer))
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
378 ;; We must be in the current-buffer when the print occurs.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
379 (custom-prin1 object buf)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
380 (save-excursion
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
381 (set-buffer buf)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
382 (buffer-string)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
383 ;; We could erase the buffer again, but why bother?
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
384 )))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
385
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
386
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
387 (defun custom-print (object &optional stream)
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
388 "Output the printed representation of OBJECT, with newlines around it.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
389 Quoting characters are printed when needed to make output that `read'
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
390 can handle, whenever this is possible.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
391 Output stream is STREAM, or value of `standard-output' (which see).
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
392
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
393 This is the custom-print replacement for the standard `print'."
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
394 (cust-print-original-princ "\n" stream)
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
395 (custom-prin1 object stream)
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
396 (cust-print-original-princ "\n" stream))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
397
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
398
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
399 (defun custom-format (fmt &rest args)
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
400 "Format a string out of a control-string and arguments.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
401 The first argument is a control string. It, and subsequent arguments
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
402 substituted into it, become the value, which is a string.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
403 It may contain %s or %d or %c to substitute successive following arguments.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
404 %s means print an argument as a string, %d means print as number in decimal,
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
405 %c means print a number as a single character.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
406 The argument used by %s must be a string or a symbol;
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
407 the argument used by %d, %b, %o, %x or %c must be a number.
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
408
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
409 This is the custom-print replacement for the standard `format'. It
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
410 calls the emacs `format' after first making strings for list,
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
411 vector, or symbol args. The format specification for such args should
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
412 be `%s' in any case, so a string argument will also work. The string
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
413 is generated with `custom-prin1-to-string', which quotes quotable
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
414 characters."
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
415 (apply 'cust-print-original-format fmt
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
416 (mapcar (function (lambda (arg)
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
417 (if (or (listp arg) (vectorp arg) (symbolp arg))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
418 (custom-prin1-to-string arg)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
419 arg)))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
420 args)))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
421
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
422
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
423 (defun custom-message (fmt &rest args)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
424 "Print a one-line message at the bottom of the screen.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
425 The first argument is a control string.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
426 It may contain %s or %d or %c to print successive following arguments.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
427 %s means print an argument as a string, %d means print as number in decimal,
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
428 %c means print a number as a single character.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
429 The argument used by %s must be a string or a symbol;
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
430 the argument used by %d or %c must be a number.
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
431
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
432 This is the custom-print replacement for the standard `message'.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
433 See `custom-format' for the details."
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
434 ;; It doesn't work to princ the result of custom-format as in:
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
435 ;; (cust-print-original-princ (apply 'custom-format fmt args))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
436 ;; because the echo area requires special handling
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
437 ;; to avoid duplicating the output.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
438 ;; cust-print-original-message does it right.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
439 (apply 'cust-print-original-message fmt
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
440 (mapcar (function (lambda (arg)
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
441 (if (or (listp arg) (vectorp arg) (symbolp arg))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
442 (custom-prin1-to-string arg)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
443 arg)))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
444 args)))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
445
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
446
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
447 (defun custom-error (fmt &rest args)
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
448 "Signal an error, making error message by passing all args to `format'.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
449
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
450 This is the custom-print replacement for the standard `error'.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
451 See `custom-format' for the details."
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
452 (signal 'error (list (apply 'custom-format fmt args))))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
453
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
454
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
455
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
456 ;; Support for custom prin1 and princ
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
457 ;;=========================================
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
458
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
459 ;; Defs to quiet byte-compiler.
1366
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
460 (defvar circle-table)
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
461 (defvar cust-print-current-level)
1366
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
462
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
463 (defun cust-print-original-printer (object)) ; One of the standard printers.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
464 (defun cust-print-low-level-prin (object)) ; Used internally.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
465 (defun cust-print-prin (object)) ; Call this to print recursively.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
466
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
467 (defun cust-print-top-level (object stream emacs-printer)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
468 ;; Set up for printing.
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
469 (let ((standard-output (or stream standard-output))
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
470 ;; circle-table will be non-nil if anything is circular.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
471 (circle-table (and print-circle
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
472 (cust-print-preprocess-circle-tree object)))
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
473 (cust-print-current-level (or print-level -1)))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
474
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
475 (defalias 'cust-print-original-printer emacs-printer)
2571
b65cf676a09b All fsets changed to defaliases.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2247
diff changeset
476 (defalias 'cust-print-low-level-prin
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
477 (cond
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
478 ((or custom-printers
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
479 circle-table
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
480 print-level ; comment out for version 19
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
481 ;; Emacs doesn't use print-level or print-length
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
482 ;; for vectors, but custom-print can.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
483 (if custom-print-vectors
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
484 (or print-level print-length)))
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
485 'cust-print-print-object)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
486 (t 'cust-print-original-printer)))
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
487 (defalias 'cust-print-prin
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
488 (if circle-table 'cust-print-print-circular 'cust-print-low-level-prin))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
489
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
490 (cust-print-prin object)
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
491 object))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
492
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
493
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
494 (defun cust-print-print-object (object)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
495 ;; Test object type and print accordingly.
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
496 ;; Could be called as either cust-print-low-level-prin or cust-print-prin.
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
497 (cond
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
498 ((null object) (cust-print-original-printer object))
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
499 ((cust-print-use-custom-printer object) object)
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
500 ((consp object) (cust-print-list object))
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
501 ((vectorp object) (cust-print-vector object))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
502 ;; All other types, just print.
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
503 (t (cust-print-original-printer object))))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
504
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
505
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
506 (defun cust-print-print-circular (object)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
507 ;; Printer for `prin1' and `princ' that handles circular structures.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
508 ;; If OBJECT appears multiply, and has not yet been printed,
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
509 ;; prefix with label; if it has been printed, use `#N#' instead.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
510 ;; Otherwise, print normally.
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
511 (let ((tag (assq object circle-table)))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
512 (if tag
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
513 (let ((id (cdr tag)))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
514 (if (> id 0)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
515 (progn
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
516 ;; Already printed, so just print id.
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
517 (cust-print-original-princ "#")
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
518 (cust-print-original-princ id)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
519 (cust-print-original-princ "#"))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
520 ;; Not printed yet, so label with id and print object.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
521 (setcdr tag (- id)) ; mark it as printed
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
522 (cust-print-original-princ "#")
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
523 (cust-print-original-princ (- id))
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
524 (cust-print-original-princ "=")
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
525 (cust-print-low-level-prin object)
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
526 ))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
527 ;; Not repeated in structure.
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
528 (cust-print-low-level-prin object))))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
529
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
530
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
531 ;;================================================
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
532 ;; List and vector processing for print functions.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
533
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
534 (defun cust-print-list (list)
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
535 ;; Print a list using print-length, print-level, and print-circle.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
536 (if (= cust-print-current-level 0)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
537 (cust-print-original-princ "#")
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
538 (let ((cust-print-current-level (1- cust-print-current-level)))
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
539 (cust-print-original-princ "(")
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
540 (let ((length (or print-length 0)))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
541
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
542 ;; Print the first element always (even if length = 0).
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
543 (cust-print-prin (car list))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
544 (setq list (cdr list))
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
545 (if list (cust-print-original-princ " "))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
546 (setq length (1- length))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
547
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
548 ;; Print the rest of the elements.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
549 (while (and list (/= 0 length))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
550 (if (and (listp list)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
551 (not (assq list circle-table)))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
552 (progn
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
553 (cust-print-prin (car list))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
554 (setq list (cdr list)))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
555
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
556 ;; cdr is not a list, or it is in circle-table.
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
557 (cust-print-original-princ ". ")
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
558 (cust-print-prin list)
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
559 (setq list nil))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
560
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
561 (setq length (1- length))
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
562 (if list (cust-print-original-princ " ")))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
563
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
564 (if (and list (= length 0)) (cust-print-original-princ "..."))
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
565 (cust-print-original-princ ")"))))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
566 list)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
567
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
568
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
569 (defun cust-print-vector (vector)
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
570 ;; Print a vector according to print-length, print-level, and print-circle.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
571 (if (= cust-print-current-level 0)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
572 (cust-print-original-princ "#")
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
573 (let ((cust-print-current-level (1- cust-print-current-level))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
574 (i 0)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
575 (len (length vector)))
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
576 (cust-print-original-princ "[")
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
577
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
578 (if print-length
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
579 (setq len (min print-length len)))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
580 ;; Print the elements
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
581 (while (< i len)
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
582 (cust-print-prin (aref vector i))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
583 (setq i (1+ i))
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
584 (if (< i (length vector)) (cust-print-original-princ " ")))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
585
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
586 (if (< i (length vector)) (cust-print-original-princ "..."))
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
587 (cust-print-original-princ "]")
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
588 ))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
589 vector)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
590
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
591
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
592
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
593 ;; Circular structure preprocessing
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
594 ;;==================================
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
595
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
596 (defun cust-print-preprocess-circle-tree (object)
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
597 ;; Fill up the table.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
598 (let (;; Table of tags for each object in an object to be printed.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
599 ;; A tag is of the form:
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
600 ;; ( <object> <nil-t-or-id-number> )
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
601 ;; The id-number is generated after the entire table has been computed.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
602 ;; During walk through, the real circle-table lives in the cdr so we
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
603 ;; can use setcdr to add new elements instead of having to setq the
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
604 ;; variable sometimes (poor man's locf).
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
605 (circle-table (list nil)))
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
606 (cust-print-walk-circle-tree object)
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
607
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
608 ;; Reverse table so it is in the order that the objects will be printed.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
609 ;; This pass could be avoided if we always added to the end of the
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
610 ;; table with setcdr in walk-circle-tree.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
611 (setcdr circle-table (nreverse (cdr circle-table)))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
612
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
613 ;; Walk through the table, assigning id-numbers to those
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
614 ;; objects which will be printed using #N= syntax. Delete those
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
615 ;; objects which will be printed only once (to speed up assq later).
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
616 (let ((rest circle-table)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
617 (id -1))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
618 (while (cdr rest)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
619 (let ((tag (car (cdr rest))))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
620 (cond ((cdr tag)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
621 (setcdr tag id)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
622 (setq id (1- id))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
623 (setq rest (cdr rest)))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
624 ;; Else delete this object.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
625 (t (setcdr rest (cdr (cdr rest))))))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
626 ))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
627 ;; Drop the car.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
628 (cdr circle-table)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
629 ))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
630
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
631
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
632
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
633 (defun cust-print-walk-circle-tree (object)
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
634 (let (read-equivalent-p tag)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
635 (while object
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
636 (setq read-equivalent-p
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
637 (or (numberp object)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
638 (and (symbolp object)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
639 ;; Check if it is uninterned.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
640 (eq object (intern-soft (symbol-name object)))))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
641 tag (and (not read-equivalent-p)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
642 (assq object (cdr circle-table))))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
643 (cond (tag
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
644 ;; Seen this object already, so note that.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
645 (setcdr tag t))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
646
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
647 ((not read-equivalent-p)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
648 ;; Add a tag for this object.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
649 (setcdr circle-table
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
650 (cons (list object)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
651 (cdr circle-table)))))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
652 (setq object
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
653 (cond
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
654 (tag ;; No need to descend since we have already.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
655 nil)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
656
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
657 ((consp object)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
658 ;; Walk the car of the list recursively.
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
659 (cust-print-walk-circle-tree (car object))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
660 ;; But walk the cdr with the above while loop
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
661 ;; to avoid problems with max-lisp-eval-depth.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
662 ;; And it should be faster than recursion.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
663 (cdr object))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
664
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
665 ((vectorp object)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
666 ;; Walk the vector.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
667 (let ((i (length object))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
668 (j 0))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
669 (while (< j i)
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
670 (cust-print-walk-circle-tree (aref object j))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
671 (setq j (1+ j))))))))))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
672
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
673
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
674 ;; Example.
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
675 ;;=======================================
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
676
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
677 '(progn
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
678 (progn
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
679 ;; Create some circular structures.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
680 (setq circ-sym (let ((x (make-symbol "FOO"))) (list x x)))
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
681 (setq circ-list (list 'a 'b (vector 1 2 3 4) 'd 'e 'f))
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
682 (setcar (nthcdr 3 circ-list) circ-list)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
683 (aset (nth 2 circ-list) 2 circ-list)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
684 (setq dotted-circ-list (list 'a 'b 'c))
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
685 (setcdr (cdr (cdr dotted-circ-list)) dotted-circ-list)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
686 (setq circ-vector (vector 1 2 3 4 (list 'a 'b 'c 'd) 6 7))
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
687 (aset circ-vector 5 (make-symbol "-gensym-"))
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
688 (setcar (cdr (aref circ-vector 4)) (aref circ-vector 5))
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
689 nil)
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
690
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
691 (install-custom-print)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
692 ;; (setq print-circle t)
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
693
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
694 (let ((print-circle t))
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
695 (or (equal (prin1-to-string circ-list) "#1=(a b [1 2 #1# 4] #1# e f)")
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
696 (error "circular object with array printing")))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
697
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
698 (let ((print-circle t))
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
699 (or (equal (prin1-to-string dotted-circ-list) "#1=(a b c . #1#)")
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
700 (error "circular object with array printing")))
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
701
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
702 (let* ((print-circle t)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
703 (x (list 'p 'q))
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
704 (y (list (list 'a 'b) x 'foo x)))
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
705 (setcdr (cdr (cdr (cdr y))) (cdr y))
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
706 (or (equal (prin1-to-string y) "((a b) . #1=(#2=(p q) foo #2# . #1#))"
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
707 )
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
708 (error "circular list example from CL manual")))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
709
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
710 (let ((print-circle nil))
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
711 ;; cl-packages.el is required to print uninterned symbols like #:FOO.
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
712 ;; (require 'cl-packages)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
713 (or (equal (prin1-to-string circ-sym) "(#:FOO #:FOO)")
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
714 (error "uninterned symbols in list")))
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
715 (let ((print-circle t))
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
716 (or (equal (prin1-to-string circ-sym) "(#1=FOO #1#)")
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
717 (error "circular uninterned symbols in list")))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
718
6511
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
719 (uninstall-custom-print)
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
720 )
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
721
fb1c6b7aba39 Change "internal" to "original" throughout.
Daniel LaLiberte <liberte@gnu.org>
parents: 3591
diff changeset
722 (provide 'cust-print)
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
723
811
e694e0879463 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 807
diff changeset
724 ;;; cust-print.el ends here
6779
baefeadae7a3 Jumping up to new revision.
Daniel LaLiberte <liberte@gnu.org>
parents: 6687
diff changeset
725