annotate src/print.c @ 341:84ec93d39015

Initial revision
author Jim Blandy <jimb@redhat.com>
date Fri, 19 Jul 1991 20:51:57 +0000
parents 52f53a69e5c4
children 7c6f74ef31a3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
329
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1 /* Lisp object printing and output streams.
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2 Copyright (C) 1985, 1986, 1988 Free Software Foundation, Inc.
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4 This file is part of GNU Emacs.
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
5
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
6 GNU Emacs is free software; you can redistribute it and/or modify
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
8 the Free Software Foundation; either version 1, or (at your option)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
9 any later version.
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11 GNU Emacs is distributed in the hope that it will be useful,
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14 GNU General Public License for more details.
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17 along with GNU Emacs; see the file COPYING. If not, write to
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
19
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
21 #include "config.h"
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
22 #include <stdio.h>
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
23 #undef NULL
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
24 #include "lisp.h"
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
25
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
26 #ifndef standalone
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
27 #include "buffer.h"
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
28 #include "screen.h"
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
29 #include "window.h"
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
30 #include "process.h"
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
31 #include "dispextern.h"
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
32 #include "termchar.h"
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
33 #endif /* not standalone */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35 Lisp_Object Vstandard_output, Qstandard_output;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
36
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37 #ifdef LISP_FLOAT_TYPE
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
38 Lisp_Object Vfloat_output_format, Qfloat_output_format;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39 #endif /* LISP_FLOAT_TYPE */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
40
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
41 /* Avoid actual stack overflow in print. */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42 int print_depth;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
44 /* Maximum length of list to print in full; noninteger means
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
45 effectively infinity */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47 Lisp_Object Vprint_length;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
48
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
49 /* Maximum depth of list to print in full; noninteger means
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
50 effectively infinity. */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
51
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
52 Lisp_Object Vprint_level;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
53
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
54 /* Nonzero means print newlines in strings as \n. */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
55
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
56 int print_escape_newlines;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
57
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
58 Lisp_Object Qprint_escape_newlines;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
59
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
60 /* Nonzero means print newline before next minibuffer message.
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
61 Defined in xdisp.c */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
62
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
63 extern int noninteractive_need_newline;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
64 #ifdef MAX_PRINT_CHARS
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
65 static int print_chars;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
66 static int max_print;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
67 #endif /* MAX_PRINT_CHARS */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
68
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
69 #if 0
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
70 /* Convert between chars and GLYPHs */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
71
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
72 int
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
73 glyphlen (glyphs)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
74 register GLYPH *glyphs;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
76 register int i = 0;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
77
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
78 while (glyphs[i])
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
79 i++;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
80 return i;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
81 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
82
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
83 void
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
84 str_to_glyph_cpy (str, glyphs)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
85 char *str;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
86 GLYPH *glyphs;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
87 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
88 register GLYPH *gp = glyphs;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
89 register char *cp = str;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
90
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
91 while (*cp)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
92 *gp++ = *cp++;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
93 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
94
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
95 void
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
96 str_to_glyph_ncpy (str, glyphs, n)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97 char *str;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
98 GLYPH *glyphs;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
99 register int n;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
100 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
101 register GLYPH *gp = glyphs;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
102 register char *cp = str;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
103
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
104 while (n-- > 0)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
105 *gp++ = *cp++;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
106 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
107
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
108 void
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
109 glyph_to_str_cpy (glyphs, str)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
110 GLYPH *glyphs;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
111 char *str;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
112 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
113 register GLYPH *gp = glyphs;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
114 register char *cp = str;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
115
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
116 while (*gp)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
117 *str++ = *gp++ & 0377;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
118 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
119 #endif
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
120
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
121 /* Low level output routines for charaters and strings */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
122
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
123 /* Lisp functions to do output using a stream
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
124 must have the stream in a variable called printcharfun
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
125 and must start with PRINTPREPARE and end with PRINTFINISH.
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
126 Use PRINTCHAR to output one character,
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
127 or call strout to output a block of characters.
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
128 Also, each one must have the declarations
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
129 struct buffer *old = current_buffer;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
130 int old_point = -1, start_point;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
131 Lisp_Object original;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
132 */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
133
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
134 #define PRINTPREPARE \
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
135 original = printcharfun; \
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
136 if (NULL (printcharfun)) printcharfun = Qt; \
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
137 if (XTYPE (printcharfun) == Lisp_Buffer) \
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
138 { if (XBUFFER (printcharfun) != current_buffer) Fset_buffer (printcharfun); \
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
139 printcharfun = Qnil;}\
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
140 if (XTYPE (printcharfun) == Lisp_Marker) \
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
141 { if (XMARKER (original)->buffer != current_buffer) \
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
142 set_buffer_internal (XMARKER (original)->buffer); \
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
143 old_point = point; \
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
144 SET_PT (marker_position (printcharfun)); \
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
145 start_point = point; \
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
146 printcharfun = Qnil;}
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
147
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
148 #define PRINTFINISH \
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
149 if (XTYPE (original) == Lisp_Marker) \
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
150 Fset_marker (original, make_number (point), Qnil); \
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
151 if (old_point >= 0) \
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
152 SET_PT ((old_point >= start_point ? point - start_point : 0) + old_point); \
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
153 if (old != current_buffer) \
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
154 set_buffer_internal (old)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
155
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
156 #define PRINTCHAR(ch) printchar (ch, printcharfun)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
157
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
158 /* Index of first unused element of message_buf */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
159 static int printbufidx;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
160
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
161 static void
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
162 printchar (ch, fun)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
163 unsigned char ch;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
164 Lisp_Object fun;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
165 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
166 Lisp_Object ch1;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
167
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
168 #ifdef MAX_PRINT_CHARS
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
169 if (max_print)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
170 print_chars++;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
171 #endif /* MAX_PRINT_CHARS */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
172 #ifndef standalone
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
173 if (EQ (fun, Qnil))
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
174 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
175 QUIT;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
176 insert (&ch, 1);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
177 return;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
178 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
179
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
180 if (EQ (fun, Qt))
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
181 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
182 if (noninteractive)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
183 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
184 putchar (ch);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
185 noninteractive_need_newline = 1;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
186 return;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
187 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
188
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
189 if (echo_area_glyphs != SCREEN_MESSAGE_BUF (selected_screen)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
190 || !message_buf_print)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
191 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
192 echo_area_glyphs = SCREEN_MESSAGE_BUF (selected_screen);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
193 printbufidx = 0;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
194 message_buf_print = 1;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
195 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
196
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
197 if (printbufidx < SCREEN_WIDTH (selected_screen) - 1)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
198 SCREEN_MESSAGE_BUF (selected_screen)[printbufidx++] = ch;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
199 SCREEN_MESSAGE_BUF (selected_screen)[printbufidx] = 0;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
200
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
201 return;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
202 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
203 #endif /* not standalone */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
204
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
205 XFASTINT (ch1) = ch;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
206 call1 (fun, ch1);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
207 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
208
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
209 static void
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
210 strout (ptr, size, printcharfun)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
211 char *ptr;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
212 int size;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
213 Lisp_Object printcharfun;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
214 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
215 int i = 0;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
216
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
217 if (EQ (printcharfun, Qnil))
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
218 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
219 insert (ptr, size >= 0 ? size : strlen (ptr));
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
220 #ifdef MAX_PRINT_CHARS
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
221 if (max_print)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
222 print_chars += size >= 0 ? size : strlen(ptr);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
223 #endif /* MAX_PRINT_CHARS */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
224 return;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
225 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
226 if (EQ (printcharfun, Qt))
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
227 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
228 i = size >= 0 ? size : strlen (ptr);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
229 #ifdef MAX_PRINT_CHARS
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
230 if (max_print)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
231 print_chars += i;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
232 #endif /* MAX_PRINT_CHARS */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
233
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
234 if (noninteractive)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
235 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
236 fwrite (ptr, 1, i, stdout);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
237 noninteractive_need_newline = 1;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
238 return;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
239 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
240
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
241 if (echo_area_glyphs != SCREEN_MESSAGE_BUF (selected_screen)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
242 || !message_buf_print)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
243 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
244 echo_area_glyphs = SCREEN_MESSAGE_BUF (selected_screen);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
245 printbufidx = 0;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
246 message_buf_print = 1;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
247 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
248
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
249 if (i > SCREEN_WIDTH (selected_screen) - printbufidx - 1)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
250 i = SCREEN_WIDTH (selected_screen) - printbufidx - 1;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
251 bcopy (ptr, &SCREEN_MESSAGE_BUF (selected_screen) [printbufidx], i);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
252 printbufidx += i;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
253 SCREEN_MESSAGE_BUF (selected_screen) [printbufidx] = 0;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
254
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
255 return;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
256 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
257
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
258 if (size >= 0)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
259 while (i < size)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
260 PRINTCHAR (ptr[i++]);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
261 else
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
262 while (ptr[i])
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
263 PRINTCHAR (ptr[i++]);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
264 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
265
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
266 /* Print the contents of a string STRING using PRINTCHARFUN.
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
267 It isn't safe to use strout, because printing one char can relocate. */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
268
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
269 print_string (string, printcharfun)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
270 Lisp_Object string;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
271 Lisp_Object printcharfun;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
272 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
273 if (EQ (printcharfun, Qnil) || EQ (printcharfun, Qt))
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
274 /* In predictable cases, strout is safe: output to buffer or screen. */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
275 strout (XSTRING (string)->data, XSTRING (string)->size, printcharfun);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
276 else
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
277 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
278 /* Otherwise, fetch the string address for each character. */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
279 int i;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
280 int size = XSTRING (string)->size;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
281 struct gcpro gcpro1;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
282 GCPRO1 (string);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
283 for (i = 0; i < size; i++)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
284 PRINTCHAR (XSTRING (string)->data[i]);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
285 UNGCPRO;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
286 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
287 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
288
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
289 DEFUN ("write-char", Fwrite_char, Swrite_char, 1, 2, 0,
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
290 "Output character CHAR to stream STREAM.\n\
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
291 STREAM defaults to the value of `standard-output' (which see).")
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
292 (ch, printcharfun)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
293 Lisp_Object ch, printcharfun;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
294 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
295 struct buffer *old = current_buffer;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
296 int old_point = -1;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
297 int start_point;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
298 Lisp_Object original;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
299
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
300 if (NULL (printcharfun))
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
301 printcharfun = Vstandard_output;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
302 CHECK_NUMBER (ch, 0);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
303 PRINTPREPARE;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
304 PRINTCHAR (XINT (ch));
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
305 PRINTFINISH;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
306 return ch;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
307 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
308
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
309 /* Used from outside of print.c to print a block of SIZE chars at DATA
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
310 on the default output stream.
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
311 Do not use this on the contents of a Lisp string. */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
312
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
313 write_string (data, size)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
314 char *data;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
315 int size;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
316 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
317 struct buffer *old = current_buffer;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
318 Lisp_Object printcharfun;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
319 int old_point = -1;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
320 int start_point;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
321 Lisp_Object original;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
322
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
323 printcharfun = Vstandard_output;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
324
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
325 PRINTPREPARE;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
326 strout (data, size, printcharfun);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
327 PRINTFINISH;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
328 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
329
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
330 /* Used from outside of print.c to print a block of SIZE chars at DATA
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
331 on a specified stream PRINTCHARFUN.
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
332 Do not use this on the contents of a Lisp string. */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
333
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
334 write_string_1 (data, size, printcharfun)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
335 char *data;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
336 int size;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
337 Lisp_Object printcharfun;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
338 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
339 struct buffer *old = current_buffer;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
340 int old_point = -1;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
341 int start_point;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
342 Lisp_Object original;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
343
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
344 PRINTPREPARE;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
345 strout (data, size, printcharfun);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
346 PRINTFINISH;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
347 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
348
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
349
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
350 #ifndef standalone
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
351
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
352 void
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
353 temp_output_buffer_setup (bufname)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
354 char *bufname;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
355 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
356 register struct buffer *old = current_buffer;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
357 register Lisp_Object buf;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
358
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
359 Fset_buffer (Fget_buffer_create (build_string (bufname)));
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
360
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
361 current_buffer->read_only = Qnil;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
362 Ferase_buffer ();
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
363
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
364 XSET (buf, Lisp_Buffer, current_buffer);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
365 specbind (Qstandard_output, buf);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
366
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
367 set_buffer_internal (old);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
368 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
369
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
370 Lisp_Object
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
371 internal_with_output_to_temp_buffer (bufname, function, args)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
372 char *bufname;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
373 Lisp_Object (*function) ();
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
374 Lisp_Object args;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
375 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
376 int count = specpdl_ptr - specpdl;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
377 Lisp_Object buf, val;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
378
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
379 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
380 temp_output_buffer_setup (bufname);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
381 buf = Vstandard_output;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
382
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
383 val = (*function) (args);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
384
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
385 temp_output_buffer_show (buf);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
386
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
387 return unbind_to (count, val);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
388 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
389
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
390 DEFUN ("with-output-to-temp-buffer", Fwith_output_to_temp_buffer, Swith_output_to_temp_buffer,
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
391 1, UNEVALLED, 0,
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
392 "Bind `standard-output' to buffer BUFNAME, eval BODY, then show that buffer.\n\
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
393 The buffer is cleared out initially, and marked as unmodified when done.\n\
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
394 All output done by BODY is inserted in that buffer by default.\n\
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
395 The buffer is displayed in another window, but not selected.\n\
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
396 The value of the last form in BODY is returned.\n\
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
397 If BODY does not finish normally, the buffer BUFNAME is not displayed.\n\n\
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
398 If variable `temp-buffer-show-hook' is non-nil, call it at the end\n\
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
399 to get the buffer displayed. It gets one argument, the buffer to display.")
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
400 (args)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
401 Lisp_Object args;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
402 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
403 struct gcpro gcpro1;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
404 Lisp_Object name;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
405 int count = specpdl_ptr - specpdl;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
406 Lisp_Object buf, val;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
407
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
408 GCPRO1(args);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
409 name = Feval (Fcar (args));
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
410 UNGCPRO;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
411
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
412 CHECK_STRING (name, 0);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
413 temp_output_buffer_setup (XSTRING (name)->data);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
414 buf = Vstandard_output;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
415
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
416 val = Fprogn (Fcdr (args));
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
417
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
418 temp_output_buffer_show (buf);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
419
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
420 return unbind_to (count, val);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
421 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
422 #endif /* not standalone */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
423
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
424 static void print ();
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
425
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
426 DEFUN ("terpri", Fterpri, Sterpri, 0, 1, 0,
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
427 "Output a newline to STREAM.\n\
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
428 If STREAM is omitted or nil, the value of `standard-output' is used.")
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
429 (printcharfun)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
430 Lisp_Object printcharfun;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
431 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
432 struct buffer *old = current_buffer;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
433 int old_point = -1;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
434 int start_point;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
435 Lisp_Object original;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
436
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
437 if (NULL (printcharfun))
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
438 printcharfun = Vstandard_output;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
439 PRINTPREPARE;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
440 PRINTCHAR ('\n');
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
441 PRINTFINISH;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
442 return Qt;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
443 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
444
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
445 DEFUN ("prin1", Fprin1, Sprin1, 1, 2, 0,
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
446 "Output the printed representation of OBJECT, any Lisp object.\n\
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
447 Quoting characters are printed when needed to make output that `read'\n\
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
448 can handle, whenever this is possible.\n\
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
449 Output stream is STREAM, or value of `standard-output' (which see).")
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
450 (obj, printcharfun)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
451 Lisp_Object obj, printcharfun;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
452 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
453 struct buffer *old = current_buffer;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
454 int old_point = -1;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
455 int start_point;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
456 Lisp_Object original;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
457
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
458 #ifdef MAX_PRINT_CHARS
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
459 max_print = 0;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
460 #endif /* MAX_PRINT_CHARS */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
461 if (NULL (printcharfun))
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
462 printcharfun = Vstandard_output;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
463 PRINTPREPARE;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
464 print_depth = 0;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
465 print (obj, printcharfun, 1);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
466 PRINTFINISH;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
467 return obj;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
468 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
469
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
470 /* a buffer which is used to hold output being built by prin1-to-string */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
471 Lisp_Object Vprin1_to_string_buffer;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
472
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
473 DEFUN ("prin1-to-string", Fprin1_to_string, Sprin1_to_string, 1, 2, 0,
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
474 "Return a string containing the printed representation of OBJECT,\n\
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
475 any Lisp object. Quoting characters are used when needed to make output\n\
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
476 that `read' can handle, whenever this is possible, unless the optional\n\
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
477 second argument NOESCAPE is non-nil.")
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
478 (obj, noescape)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
479 Lisp_Object obj, noescape;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
480 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
481 struct buffer *old = current_buffer;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
482 int old_point = -1;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
483 int start_point;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
484 Lisp_Object original, printcharfun;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
485 struct gcpro gcpro1;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
486
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
487 printcharfun = Vprin1_to_string_buffer;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
488 PRINTPREPARE;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
489 print_depth = 0;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
490 print (obj, printcharfun, NULL (noescape));
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
491 /* Make Vprin1_to_string_buffer be the default buffer after PRINTFINSH */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
492 PRINTFINISH;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
493 set_buffer_internal (XBUFFER (Vprin1_to_string_buffer));
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
494 obj = Fbuffer_string ();
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
495
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
496 GCPRO1 (obj);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
497 Ferase_buffer ();
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
498 set_buffer_internal (old);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
499 UNGCPRO;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
500
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
501 return obj;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
502 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
503
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
504 DEFUN ("princ", Fprinc, Sprinc, 1, 2, 0,
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
505 "Output the printed representation of OBJECT, any Lisp object.\n\
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
506 No quoting characters are used; no delimiters are printed around\n\
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
507 the contents of strings.\n\
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
508 Output stream is STREAM, or value of standard-output (which see).")
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
509 (obj, printcharfun)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
510 Lisp_Object obj, printcharfun;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
511 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
512 struct buffer *old = current_buffer;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
513 int old_point = -1;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
514 int start_point;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
515 Lisp_Object original;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
516
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
517 if (NULL (printcharfun))
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
518 printcharfun = Vstandard_output;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
519 PRINTPREPARE;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
520 print_depth = 0;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
521 print (obj, printcharfun, 0);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
522 PRINTFINISH;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
523 return obj;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
524 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
525
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
526 DEFUN ("print", Fprint, Sprint, 1, 2, 0,
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
527 "Output the printed representation of OBJECT, with newlines around it.\n\
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
528 Quoting characters are printed when needed to make output that `read'\n\
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
529 can handle, whenever this is possible.\n\
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
530 Output stream is STREAM, or value of `standard-output' (which see).")
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
531 (obj, printcharfun)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
532 Lisp_Object obj, printcharfun;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
533 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
534 struct buffer *old = current_buffer;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
535 int old_point = -1;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
536 int start_point;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
537 Lisp_Object original;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
538 struct gcpro gcpro1;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
539
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
540 #ifdef MAX_PRINT_CHARS
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
541 print_chars = 0;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
542 max_print = MAX_PRINT_CHARS;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
543 #endif /* MAX_PRINT_CHARS */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
544 if (NULL (printcharfun))
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
545 printcharfun = Vstandard_output;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
546 GCPRO1 (obj);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
547 PRINTPREPARE;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
548 print_depth = 0;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
549 PRINTCHAR ('\n');
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
550 print (obj, printcharfun, 1);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
551 PRINTCHAR ('\n');
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
552 PRINTFINISH;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
553 #ifdef MAX_PRINT_CHARS
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
554 max_print = 0;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
555 print_chars = 0;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
556 #endif /* MAX_PRINT_CHARS */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
557 UNGCPRO;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
558 return obj;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
559 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
560
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
561 /* The subroutine object for external-debugging-output is kept here
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
562 for the convenience of the debugger. */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
563 Lisp_Object Qexternal_debugging_output;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
564
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
565 DEFUN ("external-debugging-output",
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
566 Fexternal_debugging_output, Sexternal_debugging_output,
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
567 1, 1, 0, "Write CHARACTER to stderr.\n\
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
568 You can call print while debugging emacs, and pass it this function\n\
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
569 to make it write to the debugging output.\n")
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
570 (Lisp_Object character)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
571 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
572 CHECK_NUMBER (character, 0);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
573 putc (XINT (character), stderr);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
574
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
575 return character;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
576 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
577
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
578 #ifdef LISP_FLOAT_TYPE
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
579
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
580 void
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
581 float_to_string (buf, data)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
582 char *buf;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
583 /*
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
584 * This buffer should be at least as large as the max string size of the
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
585 * largest float, printed in the biggest notation. This is undoubtably
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
586 * 20d float_output_format, with the negative of the C-constant "HUGE"
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
587 * from <math.h>.
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
588 *
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
589 * On the vax the worst case is -1e38 in 20d format which takes 61 bytes.
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
590 *
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
591 * I assume that IEEE-754 format numbers can take 329 bytes for the worst
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
592 * case of -1e307 in 20d float_output_format. What is one to do (short of
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
593 * re-writing _doprnt to be more sane)?
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
594 * -wsr
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
595 */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
596 double data;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
597 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
598 register unsigned char *cp, c;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
599 register int width;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
600
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
601 if (NULL (Vfloat_output_format)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
602 || XTYPE (Vfloat_output_format) != Lisp_String)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
603 lose:
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
604 sprintf (buf, "%.20g", data);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
605 else /* oink oink */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
606 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
607 /* Check that the spec we have is fully valid.
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
608 This means not only valid for printf,
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
609 but meant for floats, and reasonable. */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
610 cp = XSTRING (Vfloat_output_format)->data;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
611
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
612 if (cp[0] != '%')
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
613 goto lose;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
614 if (cp[1] != '.')
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
615 goto lose;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
616
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
617 cp += 2;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
618 for (width = 0;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
619 ((c = *cp) >= '0' && c <= '9');
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
620 cp++)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
621 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
622 width *= 10;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
623 width += c - '0';
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
624 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
625
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
626 if (*cp != 'e' && *cp != 'f' && *cp != 'g')
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
627 goto lose;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
628
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
629 if (width < (*cp != 'e') || width > DBL_DIG)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
630 goto lose;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
631
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
632 if (cp[1] != 0)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
633 goto lose;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
634
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
635 sprintf (buf, XSTRING (Vfloat_output_format)->data, data);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
636 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
637 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
638 #endif /* LISP_FLOAT_TYPE */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
639
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
640 static void
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
641 print (obj, printcharfun, escapeflag)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
642 #ifndef RTPC_REGISTER_BUG
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
643 register Lisp_Object obj;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
644 #else
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
645 Lisp_Object obj;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
646 #endif
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
647 register Lisp_Object printcharfun;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
648 int escapeflag;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
649 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
650 char buf[30];
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
651
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
652 QUIT;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
653
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
654 print_depth++;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
655
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
656 if (print_depth > 200)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
657 error ("Apparently circular structure being printed");
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
658 #ifdef MAX_PRINT_CHARS
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
659 if (max_print && print_chars > max_print)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
660 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
661 PRINTCHAR ('\n');
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
662 print_chars = 0;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
663 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
664 #endif /* MAX_PRINT_CHARS */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
665
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
666 #ifdef SWITCH_ENUM_BUG
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
667 switch ((int) XTYPE (obj))
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
668 #else
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
669 switch (XTYPE (obj))
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
670 #endif
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
671 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
672 default:
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
673 /* We're in trouble if this happens!
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
674 Probably should just abort () */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
675 strout ("#<EMACS BUG: INVALID DATATYPE ", -1, printcharfun);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
676 sprintf (buf, "(#o%3o)", (int) XTYPE (obj));
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
677 strout (buf, -1, printcharfun);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
678 strout (" Save your buffers immediately and please report this bug>",
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
679 -1, printcharfun);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
680 break;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
681
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
682 #ifdef LISP_FLOAT_TYPE
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
683 case Lisp_Float:
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
684 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
685 char pigbuf[350]; /* see comments in float_to_string */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
686
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
687 float_to_string (pigbuf, XFLOAT(obj)->data);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
688 strout (pigbuf, -1, printcharfun);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
689 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
690 break;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
691 #endif /* LISP_FLOAT_TYPE */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
692
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
693 case Lisp_Int:
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
694 sprintf (buf, "%d", XINT (obj));
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
695 strout (buf, -1, printcharfun);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
696 break;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
697
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
698 case Lisp_String:
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
699 if (!escapeflag)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
700 print_string (obj, printcharfun);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
701 else
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
702 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
703 register int i;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
704 register unsigned char c;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
705 Lisp_Object obj1;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
706 struct gcpro gcpro1;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
707
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
708 /* You can't gcpro register variables, so copy obj to a
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
709 non-register variable so we can gcpro it without
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
710 making it non-register. */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
711 obj1 = obj;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
712 GCPRO1 (obj1);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
713
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
714 PRINTCHAR ('\"');
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
715 for (i = 0; i < XSTRING (obj)->size; i++)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
716 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
717 QUIT;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
718 c = XSTRING (obj)->data[i];
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
719 if (c == '\n' && print_escape_newlines)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
720 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
721 PRINTCHAR ('\\');
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
722 PRINTCHAR ('n');
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
723 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
724 else
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
725 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
726 if (c == '\"' || c == '\\')
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
727 PRINTCHAR ('\\');
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
728 PRINTCHAR (c);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
729 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
730 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
731 PRINTCHAR ('\"');
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
732 UNGCPRO;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
733 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
734 break;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
735
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
736 case Lisp_Symbol:
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
737 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
738 register int confusing;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
739 register unsigned char *p = XSYMBOL (obj)->name->data;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
740 register unsigned char *end = p + XSYMBOL (obj)->name->size;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
741 register unsigned char c;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
742
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
743 if (p != end && (*p == '-' || *p == '+')) p++;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
744 if (p == end)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
745 confusing = 0;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
746 else
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
747 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
748 while (p != end && *p >= '0' && *p <= '9')
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
749 p++;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
750 confusing = (end == p);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
751 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
752
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
753 p = XSYMBOL (obj)->name->data;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
754 while (p != end)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
755 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
756 QUIT;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
757 c = *p++;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
758 if (escapeflag)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
759 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
760 if (c == '\"' || c == '\\' || c == '\'' || c == ';' || c == '#' ||
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
761 c == '(' || c == ')' || c == ',' || c =='.' || c == '`' ||
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
762 c == '[' || c == ']' || c == '?' || c <= 040 || confusing)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
763 PRINTCHAR ('\\'), confusing = 0;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
764 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
765 PRINTCHAR (c);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
766 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
767 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
768 break;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
769
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
770 case Lisp_Cons:
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
771 /* If deeper than spec'd depth, print placeholder. */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
772 if (XTYPE (Vprint_level) == Lisp_Int
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
773 && print_depth > XINT (Vprint_level))
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
774 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
775 strout ("...", -1, printcharfun);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
776 break;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
777 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
778
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
779 PRINTCHAR ('(');
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
780 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
781 register int i = 0;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
782 register int max = 0;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
783
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
784 if (XTYPE (Vprint_length) == Lisp_Int)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
785 max = XINT (Vprint_length);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
786 while (CONSP (obj))
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
787 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
788 if (i++)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
789 PRINTCHAR (' ');
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
790 if (max && i > max)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
791 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
792 strout ("...", 3, printcharfun);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
793 break;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
794 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
795 print (Fcar (obj), printcharfun, escapeflag);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
796 obj = Fcdr (obj);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
797 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
798 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
799 if (!NULL (obj) && !CONSP (obj))
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
800 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
801 strout (" . ", 3, printcharfun);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
802 print (obj, printcharfun, escapeflag);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
803 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
804 PRINTCHAR (')');
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
805 break;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
806
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
807 case Lisp_Compiled:
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
808 strout ("#<byte-code ", -1, printcharfun);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
809 case Lisp_Vector:
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
810 PRINTCHAR ('[');
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
811 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
812 register int i;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
813 register Lisp_Object tem;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
814 for (i = 0; i < XVECTOR (obj)->size; i++)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
815 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
816 if (i) PRINTCHAR (' ');
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
817 tem = XVECTOR (obj)->contents[i];
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
818 print (tem, printcharfun, escapeflag);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
819 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
820 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
821 PRINTCHAR (']');
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
822 if (XTYPE (obj) == Lisp_Compiled)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
823 PRINTCHAR ('>');
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
824 break;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
825
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
826 #ifndef standalone
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
827 case Lisp_Buffer:
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
828 if (NULL (XBUFFER (obj)->name))
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
829 strout ("#<killed buffer>", -1, printcharfun);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
830 else if (escapeflag)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
831 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
832 strout ("#<buffer ", -1, printcharfun);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
833 print_string (XBUFFER (obj)->name, printcharfun);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
834 PRINTCHAR ('>');
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
835 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
836 else
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
837 print_string (XBUFFER (obj)->name, printcharfun);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
838 break;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
839
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
840 case Lisp_Process:
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
841 if (escapeflag)
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
842 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
843 strout ("#<process ", -1, printcharfun);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
844 print_string (XPROCESS (obj)->name, printcharfun);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
845 PRINTCHAR ('>');
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
846 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
847 else
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
848 print_string (XPROCESS (obj)->name, printcharfun);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
849 break;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
850
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
851 case Lisp_Window:
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
852 strout ("#<window ", -1, printcharfun);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
853 sprintf (buf, "%d", XFASTINT (XWINDOW (obj)->sequence_number));
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
854 strout (buf, -1, printcharfun);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
855 if (!NULL (XWINDOW (obj)->buffer))
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
856 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
857 strout (" on ", -1, printcharfun);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
858 print_string (XBUFFER (XWINDOW (obj)->buffer)->name, printcharfun);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
859 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
860 PRINTCHAR ('>');
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
861 break;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
862
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
863 case Lisp_Window_Configuration:
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
864 strout ("#<window-configuration>", -1, printcharfun);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
865 break;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
866
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
867 #ifdef MULTI_SCREEN
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
868 case Lisp_Screen:
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
869 strout ("#<screen ", -1, printcharfun);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
870 print_string (XSCREEN (obj)->name, printcharfun);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
871 sprintf (buf, " 0x%x", XFASTINT (XSCREEN (obj)));
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
872 strout (buf, -1, printcharfun);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
873 strout (">", -1, printcharfun);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
874 break;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
875 #endif /* MULTI_SCREEN */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
876
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
877 case Lisp_Marker:
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
878 strout ("#<marker ", -1, printcharfun);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
879 if (!(XMARKER (obj)->buffer))
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
880 strout ("in no buffer", -1, printcharfun);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
881 else
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
882 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
883 sprintf (buf, "at %d", marker_position (obj));
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
884 strout (buf, -1, printcharfun);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
885 strout (" in ", -1, printcharfun);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
886 print_string (XMARKER (obj)->buffer->name, printcharfun);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
887 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
888 PRINTCHAR ('>');
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
889 break;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
890 #endif /* standalone */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
891
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
892 case Lisp_Subr:
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
893 strout ("#<subr ", -1, printcharfun);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
894 strout (XSUBR (obj)->symbol_name, -1, printcharfun);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
895 PRINTCHAR ('>');
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
896 break;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
897 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
898
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
899 print_depth--;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
900 }
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
901
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
902 void
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
903 syms_of_print ()
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
904 {
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
905 staticpro (&Qprint_escape_newlines);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
906 Qprint_escape_newlines = intern ("print-escape-newlines");
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
907
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
908 DEFVAR_LISP ("standard-output", &Vstandard_output,
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
909 "Output stream `print' uses by default for outputting a character.\n\
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
910 This may be any function of one argument.\n\
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
911 It may also be a buffer (output is inserted before point)\n\
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
912 or a marker (output is inserted and the marker is advanced)\n\
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
913 or the symbol t (output appears in the minibuffer line).");
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
914 Vstandard_output = Qt;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
915 Qstandard_output = intern ("standard-output");
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
916 staticpro (&Qstandard_output);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
917
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
918 #ifdef LISP_FLOAT_TYPE
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
919 DEFVAR_LISP ("float-output-format", &Vfloat_output_format,
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
920 "The format descriptor string that lisp uses to print floats.\n\
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
921 This is a %-spec like those accepted by `printf' in C,\n\
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
922 but with some restrictions. It must start with the two characters `%.'.\n\
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
923 After that comes an integer precision specification,\n\
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
924 and then a letter which controls the format.\n\
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
925 The letters allowed are `e', `f' and `g'.\n\
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
926 Use `e' for exponential notation \"DIG.DIGITSeEXPT\"\n\
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
927 Use `f' for decimal point notation \"DIGITS.DIGITS\".\n\
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
928 Use `g' to choose the shorter of those two formats for the number at hand.\n\
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
929 The precision in any of these cases is the number of digits following\n\
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
930 the decimal point. With `f', a precision of 0 means to omit the\n\
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
931 decimal point. 0 is not allowed with `f' or `g'.\n\n\
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
932 A value of nil means to use `%.20g'.");
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
933 Vfloat_output_format = Qnil;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
934 Qfloat_output_format = intern ("float-output-format");
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
935 staticpro (&Qfloat_output_format);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
936 #endif /* LISP_FLOAT_TYPE */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
937
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
938 DEFVAR_LISP ("print-length", &Vprint_length,
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
939 "Maximum length of list to print before abbreviating.\
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
940 A value of nil means no limit.");
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
941 Vprint_length = Qnil;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
942
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
943 DEFVAR_LISP ("print-level", &Vprint_level,
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
944 "Maximum depth of list nesting to print before abbreviating.\
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
945 A value of nil means no limit.");
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
946 Vprint_level = Qnil;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
947
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
948 DEFVAR_BOOL ("print-escape-newlines", &print_escape_newlines,
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
949 "Non-nil means print newlines in strings as backslash-n.");
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
950 print_escape_newlines = 0;
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
951
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
952 /* prin1_to_string_buffer initialized in init_buffer_once in buffer.c */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
953 staticpro (&Vprin1_to_string_buffer);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
954
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
955 defsubr (&Sprin1);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
956 defsubr (&Sprin1_to_string);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
957 defsubr (&Sprinc);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
958 defsubr (&Sprint);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
959 defsubr (&Sterpri);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
960 defsubr (&Swrite_char);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
961 defsubr (&Sexternal_debugging_output);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
962
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
963 Qexternal_debugging_output = intern ("external-debugging-output");
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
964 staticpro (&Qexternal_debugging_output);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
965
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
966 #ifndef standalone
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
967 defsubr (&Swith_output_to_temp_buffer);
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
968 #endif /* not standalone */
52f53a69e5c4 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
969 }