annotate lisp/emacs-lisp/cust-print.el @ 4280:fcc66d1d9289

(x-selection-timeout): Use 20000 as default.
author Richard M. Stallman <rms@gnu.org>
date Sun, 25 Jul 1993 22:32:07 +0000
parents 507f64624555
children fb1c6b7aba39
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 ;; Version: 1.0
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 655
diff changeset
7 ;; Adapted-By: ESR
2247
2c7997f249eb Add or correct keywords
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2230
diff changeset
8 ;; Keywords: extensions
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
9
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
11
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
12 ;; 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
13 ;; 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
14 ;; 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
15 ;; any later version.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
16
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
17 ;; 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
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
20 ;; GNU General Public License for more details.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
21
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
22 ;; 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
23 ;; 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
24 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
25
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 655
diff changeset
26 ;;; Commentary:
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 655
diff changeset
27
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
28 ;; This package provides a general print handler for prin1 and princ
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
29 ;; that supports print-level and print-circle, and by the way,
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
30 ;; print-length since the standard routines are being replaced. Also,
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
31 ;; to print custom types constructed from lists and vectors, use
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
32 ;; custom-print-list and custom-print-vector. See the documentation
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
33 ;; strings of these variables for more details.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
34
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
35 ;; If the results of your expressions contain circular references to
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
36 ;; other parts of the same structure, the standard Emacs print
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
37 ;; subroutines may fail to print with an untrappable error,
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
38 ;; "Apparently circular structure being printed". If you only use cdr
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
39 ;; 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
40 ;; term here?), you can limit the length of printing with
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
41 ;; print-length. But car circular lists and circular vectors generate
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
42 ;; the above mentioned untrappable error in Emacs version 18. Version
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
43 ;; 19 will support print-level, but it is often useful to get a better
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
44 ;; print representation of circular structures; the print-circle
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
45 ;; option may be used to print more concise representations.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
46
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
47 ;; There are two main ways to use this package. First, you may
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
48 ;; replace prin1, princ, and some subroutines that use them by calling
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
49 ;; install-custom-print-funcs so that any use of these functions in
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
50 ;; lisp code will be affected. Second, you could call the custom
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
51 ;; routines directly, thus only affecting the printing that requires
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
52 ;; them.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
53
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
54 ;; Note that subroutines which call print subroutines directly will not
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
55 ;; use the custom print functions. In particular, the evaluation
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
56 ;; functions like eval-region call the print subroutines directly.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
57 ;; Therefore, evaluating (aref circ-list 0), which calls error
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
58 ;; directly (because circ-list is not an array), will jump to the top
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
59 ;; level instead of printing the circular list.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
60
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
61 ;; Obviously the right way to implement this custom-print facility
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
62 ;; is in C. Please volunteer since I don't have the time or need.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
63
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
64 ;; Implementation design: we want to use the same list and vector
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
65 ;; processing algorithm for all versions of prin1 and princ, since how
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
66 ;; the processing is done depends on print-length, print-level, and
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
67 ;; print-circle. For circle printing, a preprocessing step is
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
68 ;; required before the final printing. Thanks to Jamie Zawinski
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
69 ;; for motivation and algorithms.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
70
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
71 ;;=========================================================
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
72 ;; export list:
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
73
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
74 ;; print-level
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
75 ;; print-circle
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
76
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
77 ;; custom-print-list
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
78 ;; custom-print-vector
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
79 ;; add-custom-print-list
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
80 ;; add-custom-print-vector
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
81
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
82 ;; install-custom-print-funcs
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
83 ;; uninstall-custom-print-funcs
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
84
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
85 ;; custom-prin1
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
86 ;; custom-princ
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
87 ;; custom-prin1-to-string
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
88 ;; custom-print
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
89 ;; custom-format
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
90 ;; custom-message
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
91 ;; custom-error
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
92
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 655
diff changeset
93 ;;; Code:
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
94
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
95 (provide 'custom-print)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
96
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
97 ;;(defvar print-length nil
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
98 ;; "*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
99 ;;This is defined by emacs.")
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
100
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
101 (defvar print-level nil
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
102 "*Controls how many levels deep a nested data object will print.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
103
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
104 If nil, printing proceeds recursively and may lead to
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
105 max-lisp-eval-depth being exceeded or an untrappable error may occur:
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
106 `Apparently circular structure being printed.'
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
107 Also see `print-length' and `print-circle'.
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
108
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
109 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
110 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
111 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
112 level 1.")
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
113
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
114
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
115 (defvar print-circle nil
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
116 "*Controls the printing of recursive structures.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
117
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
118 If nil, printing proceeds recursively and may lead to
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
119 `max-lisp-eval-depth' being exceeded or an untrappable error may occur:
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
120 \"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
121 `print-length' and `print-level'.
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
122
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
123 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
124 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
125 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
126 where N is a positive decimal integer.
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
127
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
128 Currently, there is no way to read this representation in Emacs.")
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
129
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
130
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
131 (defconst custom-print-list
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
132 nil
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
133 ;; e.g. '((floatp . float-to-string))
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
134 "An alist for custom printing of lists.
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
135 Pairs are of the form (PRED . CONVERTER). If PREDICATE is true
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
136 for an object, then CONVERTER is called with the object and should
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
137 return a string to be printed with `princ'.
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
138 Also see `custom-print-vector'.")
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
139
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
140 (defconst custom-print-vector
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
141 nil
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
142 "An alist for custom printing of vectors.
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
143 Pairs are of the form (PRED . CONVERTER). If PREDICATE is true
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
144 for an object, then CONVERTER is called with the object and should
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
145 return a string to be printed with `princ'.
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
146 Also see `custom-print-list'.")
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
147
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
148
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
149 (defun add-custom-print-list (pred converter)
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
150 "Add a pair of PREDICATE and CONVERTER to `custom-print-list'.
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
151 Any pair that has the same PREDICATE is first removed."
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
152 (setq custom-print-list (cons (cons pred converter)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
153 (delq (assq pred custom-print-list)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
154 custom-print-list))))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
155 ;; e.g. (add-custom-print-list 'floatp 'float-to-string)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
156
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
157
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
158 (defun add-custom-print-vector (pred converter)
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
159 "Add a pair of PREDICATE and CONVERTER to `custom-print-vector'.
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
160 Any pair that has the same PREDICATE is first removed."
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
161 (setq custom-print-vector (cons (cons pred converter)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
162 (delq (assq pred custom-print-vector)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
163 custom-print-vector))))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
164
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
165
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
166 ;;====================================================
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
167 ;; Saving and restoring internal printing routines.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
168
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
169 (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
170 (defalias (car symbol-pair)
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
171 (symbol-function (car (cdr symbol-pair)))))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
172
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
173
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
174 (if (not (fboundp 'cust-print-internal-prin1))
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
175 (mapcar 'cust-print-set-function-cell
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
176 '((cust-print-internal-prin1 prin1)
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
177 (cust-print-internal-princ princ)
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
178 (cust-print-internal-print print)
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
179 (cust-print-internal-prin1-to-string prin1-to-string)
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
180 (cust-print-internal-format format)
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
181 (cust-print-internal-message message)
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
182 (cust-print-internal-error error))))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
183
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
184
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
185 (defun install-custom-print-funcs ()
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
186 "Replace print functions with general, customizable, Lisp versions.
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
187 The internal subroutines are saved away, and you can reinstall them
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
188 by running `uninstall-custom-print-funcs'."
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
189 (interactive)
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
190 (mapcar 'cust-print-set-function-cell
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
191 '((prin1 custom-prin1)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
192 (princ custom-princ)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
193 (print custom-print)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
194 (prin1-to-string custom-prin1-to-string)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
195 (format custom-format)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
196 (message custom-message)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
197 (error custom-error)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
198 )))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
199
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
200 (defun uninstall-custom-print-funcs ()
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
201 "Reset print functions to their internal subroutines."
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
202 (interactive)
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
203 (mapcar 'cust-print-set-function-cell
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
204 '((prin1 cust-print-internal-prin1)
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
205 (princ cust-print-internal-princ)
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
206 (print cust-print-internal-print)
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
207 (prin1-to-string cust-print-internal-prin1-to-string)
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
208 (format cust-print-internal-format)
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
209 (message cust-print-internal-message)
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
210 (error cust-print-internal-error)
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
211 )))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
212
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
213
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
214 ;;===============================================================
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
215 ;; Lisp replacements for prin1 and princ and for subrs that use prin1
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
216 ;; (or princ) -- so far only the printing and formatting subrs.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
217
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
218 (defun custom-prin1 (object &optional stream)
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
219 "Replacement for standard `prin1'.
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
220 Uses the appropriate printer depending on the values of `print-level'
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
221 and `print-circle' (which see).
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
222
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
223 Output the printed representation of OBJECT, any Lisp object.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
224 Quoting characters are printed when needed to make output that `read'
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
225 can handle, whenever this is possible.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
226 Output stream is STREAM, or value of `standard-output' (which see)."
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
227 (cust-print-top-level object stream 'cust-print-internal-prin1))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
228
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
229
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
230 (defun custom-princ (object &optional stream)
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
231 "Same as `custom-prin1' except no quoting."
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
232 (cust-print-top-level object stream 'cust-print-internal-princ))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
233
1366
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
234 (defvar custom-prin1-chars)
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
235
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
236 (defun custom-prin1-to-string-func (c)
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
237 "Stream function for `custom-prin1-to-string'."
1366
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
238 (setq custom-prin1-chars (cons c custom-prin1-chars)))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
239
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
240 (defun custom-prin1-to-string (object)
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
241 "Replacement for standard `prin1-to-string'."
1366
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
242 (let ((custom-prin1-chars nil))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
243 (custom-prin1 object 'custom-prin1-to-string-func)
1366
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
244 (concat (nreverse custom-prin1-chars))))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
245
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 (defun custom-print (object &optional stream)
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
248 "Replacement for standard `print'."
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
249 (cust-print-internal-princ "\n")
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
250 (custom-prin1 object stream)
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
251 (cust-print-internal-princ "\n"))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
252
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
253
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
254 (defun custom-format (fmt &rest args)
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
255 "Replacement for standard `format'.
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
256
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
257 Calls format after first making strings for list or vector args.
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
258 The format specification for such args should be `%s' in any case, so a
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
259 string argument will also work. The string is generated with
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
260 `custom-prin1-to-string', which quotes quotable characters."
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
261 (apply 'cust-print-internal-format fmt
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
262 (mapcar (function (lambda (arg)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
263 (if (or (listp arg) (vectorp arg))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
264 (custom-prin1-to-string arg)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
265 arg)))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
266 args)))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
267
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
268
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
269
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
270 (defun custom-message (fmt &rest args)
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
271 "Replacement for standard `message' that works like `custom-format'."
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 2571
diff changeset
272 ;; It doesn't work to princ the result of custom-format
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
273 ;; because the echo area requires special handling
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
274 ;; to avoid duplicating the output. cust-print-internal-message does it right.
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
275 ;; (cust-print-internal-princ (apply 'custom-format fmt args))
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
276 (apply 'cust-print-internal-message fmt
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
277 (mapcar (function (lambda (arg)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
278 (if (or (listp arg) (vectorp arg))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
279 (custom-prin1-to-string arg)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
280 arg)))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
281 args)))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
282
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
283
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
284 (defun custom-error (fmt &rest args)
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
285 "Replacement for standard `error' that uses `custom-format'"
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
286 (signal 'error (list (apply 'custom-format fmt args))))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
287
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
288
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
289 ;;=========================================
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
290 ;; Support for custom prin1 and princ
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
291
1366
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
292 (defvar circle-table)
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
293 (defvar circle-tree)
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
294 (defvar circle-level)
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
295
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
296 (defun cust-print-top-level (object stream internal-printer)
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
297 "Set up for printing."
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
298 (let ((standard-output (or stream standard-output))
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
299 (circle-table (and print-circle (cust-print-preprocess-circle-tree object)))
1366
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
300 (circle-level (or print-level -1))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
301 )
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
302
2571
b65cf676a09b All fsets changed to defaliases.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2247
diff changeset
303 (defalias 'cust-print-internal-printer internal-printer)
b65cf676a09b All fsets changed to defaliases.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2247
diff changeset
304 (defalias 'cust-print-low-level-prin
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
305 (cond
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
306 ((or custom-print-list
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
307 custom-print-vector
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
308 print-level ; comment out for version 19
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
309 )
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
310 'cust-print-custom-object)
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
311 (circle-table
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
312 'cust-print-object)
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
313 (t 'cust-print-internal-printer)))
2571
b65cf676a09b All fsets changed to defaliases.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2247
diff changeset
314 (defalias 'cust-print-prin (if circle-table 'cust-print-circular 'cust-print-low-level-prin))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
315
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
316 (cust-print-prin object)
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
317 object))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
318
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
319
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
320 ;; Test object type and print accordingly.
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
321 (defun cust-print-object (object)
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
322 ;; 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
323 (cond
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
324 ((null object) (cust-print-internal-printer object))
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
325 ((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
326 ((vectorp object) (cust-print-vector object))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
327 ;; All other types, just print.
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
328 (t (cust-print-internal-printer object))))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
329
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
330
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
331 ;; Test object type and print accordingly.
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
332 (defun cust-print-custom-object (object)
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
333 ;; 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
334 (cond
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
335 ((null object) (cust-print-internal-printer object))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
336
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
337 ((consp object)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
338 (or (and custom-print-list
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
339 (cust-print-custom-object1 object custom-print-list))
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
340 (cust-print-list object)))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
341
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
342 ((vectorp object)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
343 (or (and custom-print-vector
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
344 (cust-print-custom-object1 object custom-print-vector))
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
345 (cust-print-vector object)))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
346
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
347 ;; All other types, just print.
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
348 (t (cust-print-internal-printer object))))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
349
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
350
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
351 ;; Helper for cust-print-custom-object.
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
352 ;; Print the custom OBJECT using the custom type ALIST.
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
353 ;; For the first predicate that matches the object, the corresponding
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
354 ;; converter is evaluated with the object and the string that results is
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 2571
diff changeset
355 ;; printed with princ. Return nil if no predicate matches the object.
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
356 (defun cust-print-custom-object1 (object alist)
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
357 (while (and alist (not (funcall (car (car alist)) object)))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
358 (setq alist (cdr alist)))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
359 ;; If alist is not null, then something matched.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
360 (if alist
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
361 (cust-print-internal-princ
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
362 (funcall (cdr (car alist)) object) ; returns string
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
363 )))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
364
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
365
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
366 (defun cust-print-circular (object)
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
367 "Printer for `prin1' and `princ' that handles circular structures.
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
368 If OBJECT appears multiply, and has not yet been printed,
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
369 prefix with label; if it has been printed, use `#N#' instead.
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
370 Otherwise, print normally."
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
371 (let ((tag (assq object circle-table)))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
372 (if tag
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
373 (let ((id (cdr tag)))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
374 (if (> id 0)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
375 (progn
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
376 ;; Already printed, so just print id.
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
377 (cust-print-internal-princ "#")
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
378 (cust-print-internal-princ id)
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
379 (cust-print-internal-princ "#"))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
380 ;; Not printed yet, so label with id and print object.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
381 (setcdr tag (- id)) ; mark it as printed
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
382 (cust-print-internal-princ "#")
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
383 (cust-print-internal-princ (- id))
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
384 (cust-print-internal-princ "=")
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
385 (cust-print-low-level-prin object)
655
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 ;; Not repeated in structure.
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
388 (cust-print-low-level-prin object))))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
389
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
390
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
391 ;;================================================
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
392 ;; List and vector processing for print functions.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
393
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
394 ;; Print a list using print-length, print-level, and print-circle.
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
395 (defun cust-print-list (list)
1366
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
396 (if (= circle-level 0)
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
397 (cust-print-internal-princ "#")
1366
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
398 (let ((circle-level (1- circle-level)))
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
399 (cust-print-internal-princ "(")
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
400 (let ((length (or print-length 0)))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
401
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
402 ;; 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
403 (cust-print-prin (car list))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
404 (setq list (cdr list))
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
405 (if list (cust-print-internal-princ " "))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
406 (setq length (1- length))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
407
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
408 ;; Print the rest of the elements.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
409 (while (and list (/= 0 length))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
410 (if (and (listp list)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
411 (not (assq list circle-table)))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
412 (progn
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
413 (cust-print-prin (car list))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
414 (setq list (cdr list)))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
415
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
416 ;; cdr is not a list, or it is in circle-table.
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
417 (cust-print-internal-princ ". ")
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
418 (cust-print-prin list)
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
419 (setq list nil))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
420
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
421 (setq length (1- length))
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
422 (if list (cust-print-internal-princ " ")))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
423
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
424 (if (and list (= length 0)) (cust-print-internal-princ "..."))
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
425 (cust-print-internal-princ ")"))))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
426 list)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
427
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
428
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
429 ;; Print a vector according to print-length, print-level, and print-circle.
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
430 (defun cust-print-vector (vector)
1366
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
431 (if (= circle-level 0)
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
432 (cust-print-internal-princ "#")
1366
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
433 (let ((circle-level (1- circle-level))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
434 (i 0)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
435 (len (length vector)))
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
436 (cust-print-internal-princ "[")
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
437
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
438 (if print-length
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
439 (setq len (min print-length len)))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
440 ;; Print the elements
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
441 (while (< i len)
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
442 (cust-print-prin (aref vector i))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
443 (setq i (1+ i))
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
444 (if (< i (length vector)) (cust-print-internal-princ " ")))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
445
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
446 (if (< i (length vector)) (cust-print-internal-princ "..."))
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
447 (cust-print-internal-princ "]")
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
448 ))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
449 vector)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
450
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
451
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
452 ;;==================================
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
453 ;; Circular structure preprocessing
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
454
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
455 (defun cust-print-preprocess-circle-tree (object)
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
456 ;; Fill up the table.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
457 (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
458 ;; A tag is of the form:
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
459 ;; ( <object> <nil-t-or-id-number> )
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
460 ;; 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
461 ;; 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
462 ;; 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
463 ;; variable sometimes (poor man's locf).
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
464 (circle-table (list nil)))
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
465 (cust-print-walk-circle-tree object)
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
466
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
467 ;; 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
468 ;; 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
469 ;; table with setcdr in walk-circle-tree.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
470 (setcdr circle-table (nreverse (cdr circle-table)))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
471
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
472 ;; Walk through the table, assigning id-numbers to those
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
473 ;; objects which will be printed using #N= syntax. Delete those
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
474 ;; 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
475 (let ((rest circle-table)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
476 (id -1))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
477 (while (cdr rest)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
478 (let ((tag (car (cdr rest))))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
479 (cond ((cdr tag)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
480 (setcdr tag id)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
481 (setq id (1- id))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
482 (setq rest (cdr rest)))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
483 ;; Else delete this object.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
484 (t (setcdr rest (cdr (cdr rest))))))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
485 ))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
486 ;; Drop the car.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
487 (cdr circle-table)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
488 ))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
489
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
490
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
491
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
492 (defun cust-print-walk-circle-tree (object)
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
493 (let (read-equivalent-p tag)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
494 (while object
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
495 (setq read-equivalent-p (or (numberp object) (symbolp object))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
496 tag (and (not read-equivalent-p)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
497 (assq object (cdr circle-table))))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
498 (cond (tag
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
499 ;; Seen this object already, so note that.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
500 (setcdr tag t))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
501
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
502 ((not read-equivalent-p)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
503 ;; Add a tag for this object.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
504 (setcdr circle-table
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
505 (cons (list object)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
506 (cdr circle-table)))))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
507 (setq object
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
508 (cond
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
509 (tag ;; No need to descend since we have already.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
510 nil)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
511
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
512 ((consp object)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
513 ;; 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
514 (cust-print-walk-circle-tree (car object))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
515 ;; But walk the cdr with the above while loop
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
516 ;; to avoid problems with max-lisp-eval-depth.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
517 ;; And it should be faster than recursion.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
518 (cdr object))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
519
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
520 ((vectorp object)
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
521 ;; Walk the vector.
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
522 (let ((i (length object))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
523 (j 0))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
524 (while (< j i)
1359
96c43cee31f1 CP:: changed to cust-print- in all names.
Richard M. Stallman <rms@gnu.org>
parents: 1356
diff changeset
525 (cust-print-walk-circle-tree (aref object j))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
526 (setq j (1+ j))))))))))
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
527
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
528
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
1366
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
532 ;; Example.
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
533
1366
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
534 ;;;; Create some circular structures.
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
535 ;;(setq circ-sym (let ((x (make-symbol "FOO"))) (list x x)))
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
536 ;;(setq circ-list (list 'a 'b (vector 1 2 3 4) 'd 'e 'f))
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
537 ;;(setcar (nthcdr 3 circ-list) circ-list)
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
538 ;;(aset (nth 2 circ-list) 2 circ-list)
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
539 ;;(setq dotted-circ-list (list 'a 'b 'c))
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
540 ;;(setcdr (cdr (cdr dotted-circ-list)) dotted-circ-list)
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
541 ;;(setq circ-vector (vector 1 2 3 4 (list 'a 'b 'c 'd) 6 7))
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
542 ;;(aset circ-vector 5 (make-symbol "-gensym-"))
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
543 ;;(setcar (cdr (aref circ-vector 4)) (aref circ-vector 5))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
544
1366
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
545 ;;(install-custom-print-funcs)
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
546 ;;;; (setq print-circle t)
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
547
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
548 ;;(let ((print-circle t))
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
549 ;; (or (equal (prin1-to-string circ-list) "#1=(a b [1 2 #1# 4] #1# e f)")
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
550 ;; (error "circular object with array printing")))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
551
1366
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
552 ;;(let ((print-circle t))
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
553 ;; (or (equal (prin1-to-string dotted-circ-list) "#1=(a b c . #1#)")
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
554 ;; (error "circular object with array printing")))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
555
1366
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
556 ;;(let* ((print-circle t)
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
557 ;; (x (list 'p 'q))
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
558 ;; (y (list (list 'a 'b) x 'foo x)))
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
559 ;; (setcdr (cdr (cdr (cdr y))) (cdr y))
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
560 ;; (or (equal (prin1-to-string y) "((a b) . #1=(#2=(p q) foo #2# . #1#))"
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
561 ;; )
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
562 ;; (error "circular list example from CL manual")))
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
563
1366
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
564 ;;;; There's no special handling of uninterned symbols in custom-print.
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
565 ;;(let ((print-circle nil))
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
566 ;; (or (equal (prin1-to-string circ-sym) "(#:FOO #:FOO)")
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
567 ;; (error "uninterned symbols in list")))
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
568 ;;(let ((print-circle t))
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
569 ;; (or (equal (prin1-to-string circ-sym) "(#1=FOO #1#)")
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
570 ;; (error "circular uninterned symbols in list")))
ebf903dc2d70 (custom-prin1-chars): Var defined, and renamed from prin1-chars.
Richard M. Stallman <rms@gnu.org>
parents: 1359
diff changeset
571 ;;(uninstall-custom-print-funcs)
655
02591d9e7ad3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
572
811
e694e0879463 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 807
diff changeset
573 ;;; cust-print.el ends here