Commit | Line | Data |
---|---|---|
38010d50 | 1 | /* Lisp object printing and output streams. |
0b5538bd TTN |
2 | Copyright (C) 1985, 1986, 1988, 1993, 1994, 1995, 1997, |
3 | 1998, 1999, 2000, 2001, 2002, 2003, 2004, | |
5df4f04c | 4 | 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. |
38010d50 JB |
5 | |
6 | This file is part of GNU Emacs. | |
7 | ||
9ec0b715 | 8 | GNU Emacs is free software: you can redistribute it and/or modify |
38010d50 | 9 | it under the terms of the GNU General Public License as published by |
9ec0b715 GM |
10 | the Free Software Foundation, either version 3 of the License, or |
11 | (at your option) any later version. | |
38010d50 JB |
12 | |
13 | GNU Emacs is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
9ec0b715 | 19 | along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ |
38010d50 JB |
20 | |
21 | ||
18160b98 | 22 | #include <config.h> |
38010d50 | 23 | #include <stdio.h> |
d7306fe6 | 24 | #include <setjmp.h> |
38010d50 | 25 | #include "lisp.h" |
38010d50 | 26 | #include "buffer.h" |
8b4b4467 | 27 | #include "character.h" |
71ea13cb | 28 | #include "charset.h" |
2538fae4 | 29 | #include "keyboard.h" |
0137dbf7 | 30 | #include "frame.h" |
38010d50 JB |
31 | #include "window.h" |
32 | #include "process.h" | |
33 | #include "dispextern.h" | |
34 | #include "termchar.h" | |
7651e1f5 | 35 | #include "intervals.h" |
f9467be3 | 36 | #include "blockinput.h" |
f76c8b1e | 37 | #include "termhooks.h" /* For struct terminal. */ |
2a7b7982 | 38 | #include "font.h" |
7651e1f5 | 39 | |
38010d50 JB |
40 | Lisp_Object Vstandard_output, Qstandard_output; |
41 | ||
d9c21094 RS |
42 | Lisp_Object Qtemp_buffer_setup_hook; |
43 | ||
2f100b5c | 44 | /* These are used to print like we read. */ |
2f100b5c | 45 | |
38010d50 | 46 | Lisp_Object Vfloat_output_format, Qfloat_output_format; |
f356c3fb | 47 | |
f356c3fb PE |
48 | #include <math.h> |
49 | ||
50 | #if STDC_HEADERS | |
51 | #include <float.h> | |
f356c3fb PE |
52 | #endif |
53 | ||
54 | /* Default to values appropriate for IEEE floating point. */ | |
55 | #ifndef FLT_RADIX | |
56 | #define FLT_RADIX 2 | |
57 | #endif | |
58 | #ifndef DBL_MANT_DIG | |
59 | #define DBL_MANT_DIG 53 | |
60 | #endif | |
61 | #ifndef DBL_DIG | |
62 | #define DBL_DIG 15 | |
63 | #endif | |
b0a1044b PE |
64 | #ifndef DBL_MIN |
65 | #define DBL_MIN 2.2250738585072014e-308 | |
66 | #endif | |
67 | ||
68 | #ifdef DBL_MIN_REPLACEMENT | |
69 | #undef DBL_MIN | |
70 | #define DBL_MIN DBL_MIN_REPLACEMENT | |
71 | #endif | |
f356c3fb PE |
72 | |
73 | /* Define DOUBLE_DIGITS_BOUND, an upper bound on the number of decimal digits | |
74 | needed to express a float without losing information. | |
75 | The general-case formula is valid for the usual case, IEEE floating point, | |
76 | but many compilers can't optimize the formula to an integer constant, | |
77 | so make a special case for it. */ | |
78 | #if FLT_RADIX == 2 && DBL_MANT_DIG == 53 | |
79 | #define DOUBLE_DIGITS_BOUND 17 /* IEEE floating point */ | |
80 | #else | |
81 | #define DOUBLE_DIGITS_BOUND ((int) ceil (log10 (pow (FLT_RADIX, DBL_MANT_DIG)))) | |
82 | #endif | |
83 | ||
38010d50 JB |
84 | /* Avoid actual stack overflow in print. */ |
85 | int print_depth; | |
86 | ||
a22dec27 SM |
87 | /* Level of nesting inside outputting backquote in new style. */ |
88 | int new_backquote_output; | |
0330bb60 | 89 | |
ec838c39 RS |
90 | /* Detect most circularities to print finite output. */ |
91 | #define PRINT_CIRCLE 200 | |
92 | Lisp_Object being_printed[PRINT_CIRCLE]; | |
93 | ||
6fec5601 RS |
94 | /* When printing into a buffer, first we put the text in this |
95 | block, then insert it all at once. */ | |
96 | char *print_buffer; | |
97 | ||
98 | /* Size allocated in print_buffer. */ | |
db063399 | 99 | EMACS_INT print_buffer_size; |
dc2a0b79 | 100 | /* Chars stored in print_buffer. */ |
db063399 | 101 | EMACS_INT print_buffer_pos; |
dc2a0b79 | 102 | /* Bytes stored in print_buffer. */ |
db063399 | 103 | EMACS_INT print_buffer_pos_byte; |
6fec5601 | 104 | |
38010d50 JB |
105 | /* Maximum length of list to print in full; noninteger means |
106 | effectively infinity */ | |
107 | ||
108 | Lisp_Object Vprint_length; | |
109 | ||
110 | /* Maximum depth of list to print in full; noninteger means | |
111 | effectively infinity. */ | |
112 | ||
113 | Lisp_Object Vprint_level; | |
114 | ||
115 | /* Nonzero means print newlines in strings as \n. */ | |
116 | ||
117 | int print_escape_newlines; | |
118 | ||
38940e93 RS |
119 | /* Nonzero means to print single-byte non-ascii characters in strings as |
120 | octal escapes. */ | |
121 | ||
122 | int print_escape_nonascii; | |
123 | ||
835d0be6 RS |
124 | /* Nonzero means to print multibyte characters in strings as hex escapes. */ |
125 | ||
126 | int print_escape_multibyte; | |
127 | ||
128 | Lisp_Object Qprint_escape_newlines; | |
129 | Lisp_Object Qprint_escape_multibyte, Qprint_escape_nonascii; | |
130 | ||
2f100b5c EN |
131 | /* Nonzero means print (quote foo) forms as 'foo, etc. */ |
132 | ||
133 | int print_quoted; | |
134 | ||
0f25ecc6 | 135 | /* Non-nil means print #: before uninterned symbols. */ |
081e0581 | 136 | |
e0f69431 | 137 | Lisp_Object Vprint_gensym; |
081e0581 | 138 | |
0f25ecc6 | 139 | /* Non-nil means print recursive structures using #n= and #n# syntax. */ |
081e0581 | 140 | |
0f25ecc6 RS |
141 | Lisp_Object Vprint_circle; |
142 | ||
143 | /* Non-nil means keep continuous number for #n= and #n# syntax | |
144 | between several print functions. */ | |
145 | ||
146 | Lisp_Object Vprint_continuous_numbering; | |
147 | ||
a65b85b5 SM |
148 | /* Vprint_number_table is a table, that keeps objects that are going to |
149 | be printed, to allow use of #n= and #n# to express sharing. | |
150 | For any given object, the table can give the following values: | |
151 | t the object will be printed only once. | |
152 | -N the object will be printed several times and will take number N. | |
153 | N the object has been printed so we can refer to it as #N#. | |
154 | print_number_index holds the largest N already used. | |
155 | N has to be striclty larger than 0 since we need to distinguish -N. */ | |
0f25ecc6 RS |
156 | int print_number_index; |
157 | Lisp_Object Vprint_number_table; | |
158 | ||
971de7fb | 159 | void print_interval (INTERVAL interval, Lisp_Object printcharfun); |
38010d50 | 160 | |
945b0111 | 161 | /* GDB resets this to zero on W32 to disable OutputDebugString calls. */ |
42c8bc9b | 162 | int print_output_debug_flag EXTERNALLY_VISIBLE = 1; |
945b0111 | 163 | |
38010d50 | 164 | \f |
eb8c3be9 | 165 | /* Low level output routines for characters and strings */ |
38010d50 JB |
166 | |
167 | /* Lisp functions to do output using a stream | |
081e0581 EN |
168 | must have the stream in a variable called printcharfun |
169 | and must start with PRINTPREPARE, end with PRINTFINISH, | |
170 | and use PRINTDECLARE to declare common variables. | |
171 | Use PRINTCHAR to output one character, | |
177c0ea7 | 172 | or call strout to output a block of characters. */ |
0788646c GM |
173 | |
174 | #define PRINTDECLARE \ | |
175 | struct buffer *old = current_buffer; \ | |
db063399 LMI |
176 | EMACS_INT old_point = -1, start_point = -1; \ |
177 | EMACS_INT old_point_byte = -1, start_point_byte = -1; \ | |
aed13378 | 178 | int specpdl_count = SPECPDL_INDEX (); \ |
0788646c GM |
179 | int free_print_buffer = 0; \ |
180 | int multibyte = !NILP (current_buffer->enable_multibyte_characters); \ | |
081e0581 EN |
181 | Lisp_Object original |
182 | ||
0788646c GM |
183 | #define PRINTPREPARE \ |
184 | original = printcharfun; \ | |
185 | if (NILP (printcharfun)) printcharfun = Qt; \ | |
186 | if (BUFFERP (printcharfun)) \ | |
187 | { \ | |
188 | if (XBUFFER (printcharfun) != current_buffer) \ | |
189 | Fset_buffer (printcharfun); \ | |
190 | printcharfun = Qnil; \ | |
191 | } \ | |
192 | if (MARKERP (printcharfun)) \ | |
193 | { \ | |
1cf21850 | 194 | EMACS_INT marker_pos; \ |
cd3587c1 | 195 | if (! XMARKER (printcharfun)->buffer) \ |
0788646c | 196 | error ("Marker does not point anywhere"); \ |
1cf21850 LK |
197 | if (XMARKER (printcharfun)->buffer != current_buffer) \ |
198 | set_buffer_internal (XMARKER (printcharfun)->buffer); \ | |
199 | marker_pos = marker_position (printcharfun); \ | |
200 | if (marker_pos < BEGV || marker_pos > ZV) \ | |
201 | error ("Marker is outside the accessible part of the buffer"); \ | |
0788646c GM |
202 | old_point = PT; \ |
203 | old_point_byte = PT_BYTE; \ | |
1cf21850 | 204 | SET_PT_BOTH (marker_pos, \ |
0788646c GM |
205 | marker_byte_position (printcharfun)); \ |
206 | start_point = PT; \ | |
207 | start_point_byte = PT_BYTE; \ | |
208 | printcharfun = Qnil; \ | |
209 | } \ | |
210 | if (NILP (printcharfun)) \ | |
211 | { \ | |
212 | Lisp_Object string; \ | |
213 | if (NILP (current_buffer->enable_multibyte_characters) \ | |
214 | && ! print_escape_multibyte) \ | |
215 | specbind (Qprint_escape_multibyte, Qt); \ | |
d39f07c2 RS |
216 | if (! NILP (current_buffer->enable_multibyte_characters) \ |
217 | && ! print_escape_nonascii) \ | |
218 | specbind (Qprint_escape_nonascii, Qt); \ | |
0788646c GM |
219 | if (print_buffer != 0) \ |
220 | { \ | |
221 | string = make_string_from_bytes (print_buffer, \ | |
222 | print_buffer_pos, \ | |
223 | print_buffer_pos_byte); \ | |
224 | record_unwind_protect (print_unwind, string); \ | |
225 | } \ | |
226 | else \ | |
227 | { \ | |
228 | print_buffer_size = 1000; \ | |
229 | print_buffer = (char *) xmalloc (print_buffer_size); \ | |
230 | free_print_buffer = 1; \ | |
231 | } \ | |
232 | print_buffer_pos = 0; \ | |
233 | print_buffer_pos_byte = 0; \ | |
234 | } \ | |
5494b50f | 235 | if (EQ (printcharfun, Qt) && ! noninteractive) \ |
0f25ecc6 | 236 | setup_echo_area_for_printing (multibyte); |
38010d50 | 237 | |
8a2ab0c6 RS |
238 | #define PRINTFINISH \ |
239 | if (NILP (printcharfun)) \ | |
240 | { \ | |
241 | if (print_buffer_pos != print_buffer_pos_byte \ | |
242 | && NILP (current_buffer->enable_multibyte_characters)) \ | |
243 | { \ | |
244 | unsigned char *temp \ | |
245 | = (unsigned char *) alloca (print_buffer_pos + 1); \ | |
246 | copy_text (print_buffer, temp, print_buffer_pos_byte, \ | |
247 | 1, 0); \ | |
248 | insert_1_both (temp, print_buffer_pos, \ | |
249 | print_buffer_pos, 0, 1, 0); \ | |
250 | } \ | |
251 | else \ | |
252 | insert_1_both (print_buffer, print_buffer_pos, \ | |
253 | print_buffer_pos_byte, 0, 1, 0); \ | |
570fab6c | 254 | signal_after_change (PT - print_buffer_pos, 0, print_buffer_pos);\ |
8a2ab0c6 RS |
255 | } \ |
256 | if (free_print_buffer) \ | |
257 | { \ | |
258 | xfree (print_buffer); \ | |
259 | print_buffer = 0; \ | |
260 | } \ | |
261 | unbind_to (specpdl_count, Qnil); \ | |
262 | if (MARKERP (original)) \ | |
263 | set_marker_both (original, Qnil, PT, PT_BYTE); \ | |
264 | if (old_point >= 0) \ | |
265 | SET_PT_BOTH (old_point + (old_point >= start_point \ | |
266 | ? PT - start_point : 0), \ | |
6ddd6eee | 267 | old_point_byte + (old_point_byte >= start_point_byte \ |
cd3587c1 | 268 | ? PT_BYTE - start_point_byte : 0)); \ |
8a2ab0c6 | 269 | if (old != current_buffer) \ |
0f25ecc6 | 270 | set_buffer_internal (old); |
38010d50 JB |
271 | |
272 | #define PRINTCHAR(ch) printchar (ch, printcharfun) | |
273 | ||
08e8d297 RS |
274 | /* This is used to restore the saved contents of print_buffer |
275 | when there is a recursive call to print. */ | |
0788646c | 276 | |
08e8d297 | 277 | static Lisp_Object |
971de7fb | 278 | print_unwind (Lisp_Object saved_text) |
08e8d297 | 279 | { |
72af86bd | 280 | memcpy (print_buffer, SDATA (saved_text), SCHARS (saved_text)); |
ee5263af | 281 | return Qnil; |
08e8d297 RS |
282 | } |
283 | ||
0788646c GM |
284 | |
285 | /* Print character CH using method FUN. FUN nil means print to | |
286 | print_buffer. FUN t means print to echo area or stdout if | |
287 | non-interactive. If FUN is neither nil nor t, call FUN with CH as | |
288 | argument. */ | |
38010d50 JB |
289 | |
290 | static void | |
971de7fb | 291 | printchar (unsigned int ch, Lisp_Object fun) |
38010d50 | 292 | { |
0788646c GM |
293 | if (!NILP (fun) && !EQ (fun, Qt)) |
294 | call1 (fun, make_number (ch)); | |
295 | else | |
38010d50 | 296 | { |
19a86a03 KH |
297 | unsigned char str[MAX_MULTIBYTE_LENGTH]; |
298 | int len = CHAR_STRING (ch, str); | |
299 | ||
09eddb56 | 300 | QUIT; |
177c0ea7 | 301 | |
0788646c | 302 | if (NILP (fun)) |
9a4d01d8 | 303 | { |
0788646c GM |
304 | if (print_buffer_pos_byte + len >= print_buffer_size) |
305 | print_buffer = (char *) xrealloc (print_buffer, | |
306 | print_buffer_size *= 2); | |
72af86bd | 307 | memcpy (print_buffer + print_buffer_pos_byte, str, len); |
0788646c GM |
308 | print_buffer_pos += 1; |
309 | print_buffer_pos_byte += len; | |
9a4d01d8 | 310 | } |
0788646c | 311 | else if (noninteractive) |
1134b854 | 312 | { |
0788646c GM |
313 | fwrite (str, 1, len, stdout); |
314 | noninteractive_need_newline = 1; | |
1134b854 | 315 | } |
0788646c | 316 | else |
d366d2e4 | 317 | { |
0788646c GM |
318 | int multibyte_p |
319 | = !NILP (current_buffer->enable_multibyte_characters); | |
177c0ea7 | 320 | |
eb7b678b | 321 | setup_echo_area_for_printing (multibyte_p); |
0788646c GM |
322 | insert_char (ch); |
323 | message_dolog (str, len, 0, multibyte_p); | |
d366d2e4 | 324 | } |
38010d50 | 325 | } |
38010d50 JB |
326 | } |
327 | ||
0788646c GM |
328 | |
329 | /* Output SIZE characters, SIZE_BYTE bytes from string PTR using | |
330 | method PRINTCHARFUN. If SIZE < 0, use the string length of PTR for | |
331 | both SIZE and SIZE_BYTE. PRINTCHARFUN nil means output to | |
332 | print_buffer. PRINTCHARFUN t means output to the echo area or to | |
333 | stdout if non-interactive. If neither nil nor t, call Lisp | |
334 | function PRINTCHARFUN for each character printed. MULTIBYTE | |
efb15f96 RS |
335 | non-zero means PTR contains multibyte characters. |
336 | ||
337 | In the case where PRINTCHARFUN is nil, it is safe for PTR to point | |
338 | to data in a Lisp string. Otherwise that is not safe. */ | |
0788646c | 339 | |
38010d50 | 340 | static void |
db063399 LMI |
341 | strout (const char *ptr, EMACS_INT size, EMACS_INT size_byte, |
342 | Lisp_Object printcharfun, int multibyte) | |
38010d50 | 343 | { |
087e3c46 | 344 | if (size < 0) |
dc2a0b79 | 345 | size_byte = size = strlen (ptr); |
087e3c46 | 346 | |
0788646c | 347 | if (NILP (printcharfun)) |
38010d50 | 348 | { |
dc2a0b79 | 349 | if (print_buffer_pos_byte + size_byte > print_buffer_size) |
6fec5601 | 350 | { |
dc2a0b79 | 351 | print_buffer_size = print_buffer_size * 2 + size_byte; |
6fec5601 RS |
352 | print_buffer = (char *) xrealloc (print_buffer, |
353 | print_buffer_size); | |
354 | } | |
72af86bd | 355 | memcpy (print_buffer + print_buffer_pos_byte, ptr, size_byte); |
6fec5601 | 356 | print_buffer_pos += size; |
dc2a0b79 | 357 | print_buffer_pos_byte += size_byte; |
38010d50 | 358 | } |
7b0cb8a0 | 359 | else if (noninteractive && EQ (printcharfun, Qt)) |
38010d50 | 360 | { |
0788646c GM |
361 | fwrite (ptr, 1, size_byte, stdout); |
362 | noninteractive_need_newline = 1; | |
363 | } | |
364 | else if (EQ (printcharfun, Qt)) | |
365 | { | |
366 | /* Output to echo area. We're trying to avoid a little overhead | |
367 | here, that's the reason we don't call printchar to do the | |
368 | job. */ | |
369 | int i; | |
370 | int multibyte_p | |
371 | = !NILP (current_buffer->enable_multibyte_characters); | |
177c0ea7 | 372 | |
eb7b678b | 373 | setup_echo_area_for_printing (multibyte_p); |
0788646c | 374 | message_dolog (ptr, size_byte, 0, multibyte_p); |
177c0ea7 | 375 | |
0788646c | 376 | if (size == size_byte) |
38010d50 | 377 | { |
0788646c | 378 | for (i = 0; i < size; ++i) |
bcdbfd36 | 379 | insert_char ((unsigned char) *ptr++); |
38010d50 | 380 | } |
0788646c | 381 | else |
38010d50 | 382 | { |
0788646c GM |
383 | int len; |
384 | for (i = 0; i < size_byte; i += len) | |
aec2b95b | 385 | { |
62a6e103 | 386 | int ch = STRING_CHAR_AND_LENGTH (ptr + i, len); |
0788646c | 387 | insert_char (ch); |
aec2b95b | 388 | } |
38010d50 | 389 | } |
0788646c GM |
390 | } |
391 | else | |
392 | { | |
393 | /* PRINTCHARFUN is a Lisp function. */ | |
da43f021 | 394 | EMACS_INT i = 0; |
38010d50 | 395 | |
0788646c | 396 | if (size == size_byte) |
4ad8bb20 | 397 | { |
0788646c | 398 | while (i < size_byte) |
4ad8bb20 | 399 | { |
0788646c GM |
400 | int ch = ptr[i++]; |
401 | PRINTCHAR (ch); | |
4ad8bb20 | 402 | } |
4ad8bb20 | 403 | } |
0788646c | 404 | else |
087e3c46 | 405 | { |
0788646c GM |
406 | while (i < size_byte) |
407 | { | |
408 | /* Here, we must convert each multi-byte form to the | |
409 | corresponding character code before handing it to | |
410 | PRINTCHAR. */ | |
411 | int len; | |
62a6e103 | 412 | int ch = STRING_CHAR_AND_LENGTH (ptr + i, len); |
0788646c GM |
413 | PRINTCHAR (ch); |
414 | i += len; | |
415 | } | |
087e3c46 | 416 | } |
38010d50 | 417 | } |
38010d50 JB |
418 | } |
419 | ||
420 | /* Print the contents of a string STRING using PRINTCHARFUN. | |
ed2c35ef RS |
421 | It isn't safe to use strout in many cases, |
422 | because printing one char can relocate. */ | |
38010d50 | 423 | |
dc2a0b79 | 424 | static void |
971de7fb | 425 | print_string (Lisp_Object string, Lisp_Object printcharfun) |
38010d50 | 426 | { |
6fec5601 | 427 | if (EQ (printcharfun, Qt) || NILP (printcharfun)) |
375fcc09 | 428 | { |
db063399 | 429 | EMACS_INT chars; |
375fcc09 | 430 | |
8b4b4467 KH |
431 | if (print_escape_nonascii) |
432 | string = string_escape_byte8 (string); | |
433 | ||
375fcc09 | 434 | if (STRING_MULTIBYTE (string)) |
d5db4077 | 435 | chars = SCHARS (string); |
8b4b4467 KH |
436 | else if (! print_escape_nonascii |
437 | && (EQ (printcharfun, Qt) | |
438 | ? ! NILP (buffer_defaults.enable_multibyte_characters) | |
439 | : ! NILP (current_buffer->enable_multibyte_characters))) | |
a76ef35d KH |
440 | { |
441 | /* If unibyte string STRING contains 8-bit codes, we must | |
442 | convert STRING to a multibyte string containing the same | |
443 | character codes. */ | |
444 | Lisp_Object newstr; | |
db063399 | 445 | EMACS_INT bytes; |
a76ef35d | 446 | |
d5db4077 KR |
447 | chars = SBYTES (string); |
448 | bytes = parse_str_to_multibyte (SDATA (string), chars); | |
a76ef35d KH |
449 | if (chars < bytes) |
450 | { | |
451 | newstr = make_uninit_multibyte_string (chars, bytes); | |
72af86bd | 452 | memcpy (SDATA (newstr), SDATA (string), chars); |
d5db4077 | 453 | str_to_multibyte (SDATA (newstr), bytes, chars); |
a76ef35d KH |
454 | string = newstr; |
455 | } | |
456 | } | |
375fcc09 | 457 | else |
d5db4077 | 458 | chars = SBYTES (string); |
375fcc09 | 459 | |
efb15f96 RS |
460 | if (EQ (printcharfun, Qt)) |
461 | { | |
462 | /* Output to echo area. */ | |
db063399 | 463 | EMACS_INT nbytes = SBYTES (string); |
efb15f96 RS |
464 | char *buffer; |
465 | ||
466 | /* Copy the string contents so that relocation of STRING by | |
467 | GC does not cause trouble. */ | |
468 | USE_SAFE_ALLOCA; | |
469 | ||
470 | SAFE_ALLOCA (buffer, char *, nbytes); | |
72af86bd | 471 | memcpy (buffer, SDATA (string), nbytes); |
efb15f96 RS |
472 | |
473 | strout (buffer, chars, SBYTES (string), | |
474 | printcharfun, STRING_MULTIBYTE (string)); | |
475 | ||
476 | SAFE_FREE (); | |
477 | } | |
478 | else | |
479 | /* No need to copy, since output to print_buffer can't GC. */ | |
480 | strout (SDATA (string), | |
481 | chars, SBYTES (string), | |
482 | printcharfun, STRING_MULTIBYTE (string)); | |
375fcc09 | 483 | } |
38010d50 JB |
484 | else |
485 | { | |
dc2a0b79 RS |
486 | /* Otherwise, string may be relocated by printing one char. |
487 | So re-fetch the string address for each character. */ | |
da43f021 | 488 | EMACS_INT i; |
db063399 LMI |
489 | EMACS_INT size = SCHARS (string); |
490 | EMACS_INT size_byte = SBYTES (string); | |
38010d50 JB |
491 | struct gcpro gcpro1; |
492 | GCPRO1 (string); | |
dc2a0b79 RS |
493 | if (size == size_byte) |
494 | for (i = 0; i < size; i++) | |
d5db4077 | 495 | PRINTCHAR (SREF (string, i)); |
dc2a0b79 | 496 | else |
6b61353c | 497 | for (i = 0; i < size_byte; ) |
dc2a0b79 RS |
498 | { |
499 | /* Here, we must convert each multi-byte form to the | |
500 | corresponding character code before handing it to PRINTCHAR. */ | |
501 | int len; | |
62a6e103 | 502 | int ch = STRING_CHAR_AND_LENGTH (SDATA (string) + i, len); |
dc2a0b79 RS |
503 | PRINTCHAR (ch); |
504 | i += len; | |
505 | } | |
38010d50 JB |
506 | UNGCPRO; |
507 | } | |
508 | } | |
509 | \f | |
510 | DEFUN ("write-char", Fwrite_char, Swrite_char, 1, 2, 0, | |
8c1a1077 PJ |
511 | doc: /* Output character CHARACTER to stream PRINTCHARFUN. |
512 | PRINTCHARFUN defaults to the value of `standard-output' (which see). */) | |
5842a27b | 513 | (Lisp_Object character, Lisp_Object printcharfun) |
38010d50 | 514 | { |
081e0581 | 515 | PRINTDECLARE; |
38010d50 | 516 | |
10eebdbb | 517 | if (NILP (printcharfun)) |
38010d50 | 518 | printcharfun = Vstandard_output; |
b7826503 | 519 | CHECK_NUMBER (character); |
38010d50 | 520 | PRINTPREPARE; |
3738a371 | 521 | PRINTCHAR (XINT (character)); |
38010d50 | 522 | PRINTFINISH; |
3738a371 | 523 | return character; |
38010d50 JB |
524 | } |
525 | ||
dc2a0b79 RS |
526 | /* Used from outside of print.c to print a block of SIZE |
527 | single-byte chars at DATA on the default output stream. | |
38010d50 JB |
528 | Do not use this on the contents of a Lisp string. */ |
529 | ||
dc22f25e | 530 | void |
a8fe7202 | 531 | write_string (const char *data, int size) |
38010d50 | 532 | { |
081e0581 | 533 | PRINTDECLARE; |
38010d50 | 534 | Lisp_Object printcharfun; |
38010d50 JB |
535 | |
536 | printcharfun = Vstandard_output; | |
537 | ||
538 | PRINTPREPARE; | |
dc2a0b79 | 539 | strout (data, size, size, printcharfun, 0); |
38010d50 JB |
540 | PRINTFINISH; |
541 | } | |
542 | ||
2f7c71a1 AS |
543 | /* Used to print a block of SIZE single-byte chars at DATA on a |
544 | specified stream PRINTCHARFUN. | |
38010d50 JB |
545 | Do not use this on the contents of a Lisp string. */ |
546 | ||
2f7c71a1 | 547 | static void |
a8fe7202 | 548 | write_string_1 (const char *data, int size, Lisp_Object printcharfun) |
38010d50 | 549 | { |
081e0581 | 550 | PRINTDECLARE; |
38010d50 JB |
551 | |
552 | PRINTPREPARE; | |
dc2a0b79 | 553 | strout (data, size, size, printcharfun, 0); |
38010d50 JB |
554 | PRINTFINISH; |
555 | } | |
556 | ||
557 | ||
38010d50 | 558 | void |
971de7fb | 559 | temp_output_buffer_setup (const char *bufname) |
38010d50 | 560 | { |
aed13378 | 561 | int count = SPECPDL_INDEX (); |
38010d50 JB |
562 | register struct buffer *old = current_buffer; |
563 | register Lisp_Object buf; | |
564 | ||
d9c21094 RS |
565 | record_unwind_protect (set_buffer_if_live, Fcurrent_buffer ()); |
566 | ||
38010d50 JB |
567 | Fset_buffer (Fget_buffer_create (build_string (bufname))); |
568 | ||
9756ea0f | 569 | Fkill_all_local_variables (); |
fd531951 | 570 | delete_all_overlays (current_buffer); |
2a1c968a | 571 | current_buffer->directory = old->directory; |
38010d50 | 572 | current_buffer->read_only = Qnil; |
c5c6d57c KH |
573 | current_buffer->filename = Qnil; |
574 | current_buffer->undo_list = Qt; | |
b3f6010e SM |
575 | eassert (current_buffer->overlays_before == NULL); |
576 | eassert (current_buffer->overlays_after == NULL); | |
c5c6d57c KH |
577 | current_buffer->enable_multibyte_characters |
578 | = buffer_defaults.enable_multibyte_characters; | |
d28eab19 KH |
579 | specbind (Qinhibit_read_only, Qt); |
580 | specbind (Qinhibit_modification_hooks, Qt); | |
38010d50 | 581 | Ferase_buffer (); |
633307b5 | 582 | XSETBUFFER (buf, current_buffer); |
38010d50 | 583 | |
98040cf1 | 584 | Frun_hooks (1, &Qtemp_buffer_setup_hook); |
d9c21094 RS |
585 | |
586 | unbind_to (count, Qnil); | |
587 | ||
588 | specbind (Qstandard_output, buf); | |
38010d50 JB |
589 | } |
590 | ||
591 | Lisp_Object | |
971de7fb | 592 | internal_with_output_to_temp_buffer (const char *bufname, Lisp_Object (*function) (Lisp_Object), Lisp_Object args) |
38010d50 | 593 | { |
aed13378 | 594 | int count = SPECPDL_INDEX (); |
38010d50 | 595 | Lisp_Object buf, val; |
0ab39c81 | 596 | struct gcpro gcpro1; |
38010d50 | 597 | |
0ab39c81 | 598 | GCPRO1 (args); |
38010d50 JB |
599 | record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); |
600 | temp_output_buffer_setup (bufname); | |
601 | buf = Vstandard_output; | |
0ab39c81 | 602 | UNGCPRO; |
38010d50 JB |
603 | |
604 | val = (*function) (args); | |
605 | ||
0ab39c81 | 606 | GCPRO1 (val); |
38010d50 | 607 | temp_output_buffer_show (buf); |
0ab39c81 | 608 | UNGCPRO; |
38010d50 JB |
609 | |
610 | return unbind_to (count, val); | |
611 | } | |
612 | ||
ab9ffd19 MB |
613 | DEFUN ("with-output-to-temp-buffer", |
614 | Fwith_output_to_temp_buffer, Swith_output_to_temp_buffer, | |
38010d50 | 615 | 1, UNEVALLED, 0, |
8c1a1077 | 616 | doc: /* Bind `standard-output' to buffer BUFNAME, eval BODY, then show that buffer. |
80281b01 RS |
617 | |
618 | This construct makes buffer BUFNAME empty before running BODY. | |
619 | It does not make the buffer current for BODY. | |
620 | Instead it binds `standard-output' to that buffer, so that output | |
621 | generated with `prin1' and similar functions in BODY goes into | |
622 | the buffer. | |
623 | ||
624 | At the end of BODY, this marks buffer BUFNAME unmodifed and displays | |
625 | it in a window, but does not select it. The normal way to do this is | |
626 | by calling `display-buffer', then running `temp-buffer-show-hook'. | |
627 | However, if `temp-buffer-show-function' is non-nil, it calls that | |
628 | function instead (and does not run `temp-buffer-show-hook'). The | |
629 | function gets one argument, the buffer to display. | |
630 | ||
631 | The return value of `with-output-to-temp-buffer' is the value of the | |
632 | last form in BODY. If BODY does not finish normally, the buffer | |
633 | BUFNAME is not displayed. | |
634 | ||
635 | This runs the hook `temp-buffer-setup-hook' before BODY, | |
636 | with the buffer BUFNAME temporarily current. It runs the hook | |
637 | `temp-buffer-show-hook' after displaying buffer BUFNAME, with that | |
638 | buffer temporarily current, and the window that was used to display it | |
639 | temporarily selected. But it doesn't run `temp-buffer-show-hook' | |
640 | if it uses `temp-buffer-show-function'. | |
ab9ffd19 | 641 | |
f0005db5 | 642 | usage: (with-output-to-temp-buffer BUFNAME BODY...) */) |
5842a27b | 643 | (Lisp_Object args) |
38010d50 JB |
644 | { |
645 | struct gcpro gcpro1; | |
646 | Lisp_Object name; | |
aed13378 | 647 | int count = SPECPDL_INDEX (); |
38010d50 JB |
648 | Lisp_Object buf, val; |
649 | ||
650 | GCPRO1(args); | |
651 | name = Feval (Fcar (args)); | |
b7826503 | 652 | CHECK_STRING (name); |
d5db4077 | 653 | temp_output_buffer_setup (SDATA (name)); |
38010d50 | 654 | buf = Vstandard_output; |
8bbfc258 | 655 | UNGCPRO; |
38010d50 | 656 | |
8bbfc258 | 657 | val = Fprogn (XCDR (args)); |
38010d50 | 658 | |
8bbfc258 | 659 | GCPRO1 (val); |
38010d50 | 660 | temp_output_buffer_show (buf); |
8bbfc258 | 661 | UNGCPRO; |
38010d50 JB |
662 | |
663 | return unbind_to (count, val); | |
664 | } | |
0788646c | 665 | |
38010d50 | 666 | \f |
971de7fb DN |
667 | static void print (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag); |
668 | static void print_preprocess (Lisp_Object obj); | |
669 | static void print_preprocess_string (INTERVAL interval, Lisp_Object arg); | |
670 | static void print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag); | |
38010d50 JB |
671 | |
672 | DEFUN ("terpri", Fterpri, Sterpri, 0, 1, 0, | |
8c1a1077 PJ |
673 | doc: /* Output a newline to stream PRINTCHARFUN. |
674 | If PRINTCHARFUN is omitted or nil, the value of `standard-output' is used. */) | |
5842a27b | 675 | (Lisp_Object printcharfun) |
38010d50 | 676 | { |
081e0581 | 677 | PRINTDECLARE; |
38010d50 | 678 | |
10eebdbb | 679 | if (NILP (printcharfun)) |
38010d50 JB |
680 | printcharfun = Vstandard_output; |
681 | PRINTPREPARE; | |
682 | PRINTCHAR ('\n'); | |
683 | PRINTFINISH; | |
684 | return Qt; | |
685 | } | |
686 | ||
687 | DEFUN ("prin1", Fprin1, Sprin1, 1, 2, 0, | |
8c1a1077 PJ |
688 | doc: /* Output the printed representation of OBJECT, any Lisp object. |
689 | Quoting characters are printed when needed to make output that `read' | |
9474c847 | 690 | can handle, whenever this is possible. For complex objects, the behavior |
7fab9223 | 691 | is controlled by `print-level' and `print-length', which see. |
8c1a1077 PJ |
692 | |
693 | OBJECT is any of the Lisp data types: a number, a string, a symbol, | |
694 | a list, a buffer, a window, a frame, etc. | |
695 | ||
696 | A printed representation of an object is text which describes that object. | |
697 | ||
698 | Optional argument PRINTCHARFUN is the output stream, which can be one | |
699 | of these: | |
700 | ||
701 | - a buffer, in which case output is inserted into that buffer at point; | |
702 | - a marker, in which case output is inserted at marker's position; | |
703 | - a function, in which case that function is called once for each | |
704 | character of OBJECT's printed representation; | |
705 | - a symbol, in which case that symbol's function definition is called; or | |
706 | - t, in which case the output is displayed in the echo area. | |
707 | ||
708 | If PRINTCHARFUN is omitted, the value of `standard-output' (which see) | |
709 | is used instead. */) | |
5842a27b | 710 | (Lisp_Object object, Lisp_Object printcharfun) |
38010d50 | 711 | { |
081e0581 | 712 | PRINTDECLARE; |
38010d50 | 713 | |
10eebdbb | 714 | if (NILP (printcharfun)) |
38010d50 JB |
715 | printcharfun = Vstandard_output; |
716 | PRINTPREPARE; | |
3738a371 | 717 | print (object, printcharfun, 1); |
38010d50 | 718 | PRINTFINISH; |
3738a371 | 719 | return object; |
38010d50 JB |
720 | } |
721 | ||
722 | /* a buffer which is used to hold output being built by prin1-to-string */ | |
723 | Lisp_Object Vprin1_to_string_buffer; | |
724 | ||
725 | DEFUN ("prin1-to-string", Fprin1_to_string, Sprin1_to_string, 1, 2, 0, | |
fd4d156b RS |
726 | doc: /* Return a string containing the printed representation of OBJECT. |
727 | OBJECT can be any Lisp object. This function outputs quoting characters | |
cf393f9b | 728 | when necessary to make output that `read' can handle, whenever possible, |
a2612656 EZ |
729 | unless the optional second argument NOESCAPE is non-nil. For complex objects, |
730 | the behavior is controlled by `print-level' and `print-length', which see. | |
8c1a1077 PJ |
731 | |
732 | OBJECT is any of the Lisp data types: a number, a string, a symbol, | |
733 | a list, a buffer, a window, a frame, etc. | |
734 | ||
735 | A printed representation of an object is text which describes that object. */) | |
5842a27b | 736 | (Lisp_Object object, Lisp_Object noescape) |
38010d50 | 737 | { |
081e0581 | 738 | Lisp_Object printcharfun; |
ca2de342 RS |
739 | /* struct gcpro gcpro1, gcpro2; */ |
740 | Lisp_Object save_deactivate_mark; | |
1a7de17e | 741 | int count = SPECPDL_INDEX (); |
6b61353c | 742 | struct buffer *previous; |
ca2de342 RS |
743 | |
744 | specbind (Qinhibit_modification_hooks, Qt); | |
2a42e8f6 | 745 | |
6b61353c KH |
746 | { |
747 | PRINTDECLARE; | |
748 | ||
749 | /* Save and restore this--we are altering a buffer | |
750 | but we don't want to deactivate the mark just for that. | |
751 | No need for specbind, since errors deactivate the mark. */ | |
752 | save_deactivate_mark = Vdeactivate_mark; | |
753 | /* GCPRO2 (object, save_deactivate_mark); */ | |
754 | abort_on_gc++; | |
755 | ||
756 | printcharfun = Vprin1_to_string_buffer; | |
757 | PRINTPREPARE; | |
758 | print (object, printcharfun, NILP (noescape)); | |
759 | /* Make Vprin1_to_string_buffer be the default buffer after PRINTFINSH */ | |
760 | PRINTFINISH; | |
761 | } | |
38010d50 | 762 | |
6b61353c | 763 | previous = current_buffer; |
38010d50 | 764 | set_buffer_internal (XBUFFER (Vprin1_to_string_buffer)); |
3738a371 | 765 | object = Fbuffer_string (); |
b51ee131 SM |
766 | if (SBYTES (object) == SCHARS (object)) |
767 | STRING_SET_UNIBYTE (object); | |
38010d50 | 768 | |
28b8f740 | 769 | /* Note that this won't make prepare_to_modify_buffer call |
6b61353c KH |
770 | ask-user-about-supersession-threat because this buffer |
771 | does not visit a file. */ | |
38010d50 | 772 | Ferase_buffer (); |
6b61353c | 773 | set_buffer_internal (previous); |
2a42e8f6 | 774 | |
ca2de342 RS |
775 | Vdeactivate_mark = save_deactivate_mark; |
776 | /* UNGCPRO; */ | |
38010d50 | 777 | |
ca2de342 RS |
778 | abort_on_gc--; |
779 | return unbind_to (count, object); | |
38010d50 JB |
780 | } |
781 | ||
782 | DEFUN ("princ", Fprinc, Sprinc, 1, 2, 0, | |
8c1a1077 PJ |
783 | doc: /* Output the printed representation of OBJECT, any Lisp object. |
784 | No quoting characters are used; no delimiters are printed around | |
785 | the contents of strings. | |
786 | ||
787 | OBJECT is any of the Lisp data types: a number, a string, a symbol, | |
788 | a list, a buffer, a window, a frame, etc. | |
789 | ||
790 | A printed representation of an object is text which describes that object. | |
791 | ||
792 | Optional argument PRINTCHARFUN is the output stream, which can be one | |
793 | of these: | |
794 | ||
795 | - a buffer, in which case output is inserted into that buffer at point; | |
796 | - a marker, in which case output is inserted at marker's position; | |
797 | - a function, in which case that function is called once for each | |
798 | character of OBJECT's printed representation; | |
799 | - a symbol, in which case that symbol's function definition is called; or | |
800 | - t, in which case the output is displayed in the echo area. | |
801 | ||
802 | If PRINTCHARFUN is omitted, the value of `standard-output' (which see) | |
803 | is used instead. */) | |
5842a27b | 804 | (Lisp_Object object, Lisp_Object printcharfun) |
38010d50 | 805 | { |
081e0581 | 806 | PRINTDECLARE; |
38010d50 | 807 | |
10eebdbb | 808 | if (NILP (printcharfun)) |
38010d50 JB |
809 | printcharfun = Vstandard_output; |
810 | PRINTPREPARE; | |
3738a371 | 811 | print (object, printcharfun, 0); |
38010d50 | 812 | PRINTFINISH; |
3738a371 | 813 | return object; |
38010d50 JB |
814 | } |
815 | ||
816 | DEFUN ("print", Fprint, Sprint, 1, 2, 0, | |
8c1a1077 PJ |
817 | doc: /* Output the printed representation of OBJECT, with newlines around it. |
818 | Quoting characters are printed when needed to make output that `read' | |
9474c847 | 819 | can handle, whenever this is possible. For complex objects, the behavior |
7fab9223 | 820 | is controlled by `print-level' and `print-length', which see. |
8c1a1077 PJ |
821 | |
822 | OBJECT is any of the Lisp data types: a number, a string, a symbol, | |
823 | a list, a buffer, a window, a frame, etc. | |
824 | ||
825 | A printed representation of an object is text which describes that object. | |
826 | ||
827 | Optional argument PRINTCHARFUN is the output stream, which can be one | |
828 | of these: | |
829 | ||
830 | - a buffer, in which case output is inserted into that buffer at point; | |
831 | - a marker, in which case output is inserted at marker's position; | |
832 | - a function, in which case that function is called once for each | |
833 | character of OBJECT's printed representation; | |
834 | - a symbol, in which case that symbol's function definition is called; or | |
835 | - t, in which case the output is displayed in the echo area. | |
836 | ||
837 | If PRINTCHARFUN is omitted, the value of `standard-output' (which see) | |
838 | is used instead. */) | |
5842a27b | 839 | (Lisp_Object object, Lisp_Object printcharfun) |
38010d50 | 840 | { |
081e0581 | 841 | PRINTDECLARE; |
38010d50 JB |
842 | struct gcpro gcpro1; |
843 | ||
10eebdbb | 844 | if (NILP (printcharfun)) |
38010d50 | 845 | printcharfun = Vstandard_output; |
3738a371 | 846 | GCPRO1 (object); |
38010d50 | 847 | PRINTPREPARE; |
38010d50 | 848 | PRINTCHAR ('\n'); |
3738a371 | 849 | print (object, printcharfun, 1); |
38010d50 JB |
850 | PRINTCHAR ('\n'); |
851 | PRINTFINISH; | |
38010d50 | 852 | UNGCPRO; |
3738a371 | 853 | return object; |
38010d50 JB |
854 | } |
855 | ||
856 | /* The subroutine object for external-debugging-output is kept here | |
857 | for the convenience of the debugger. */ | |
858 | Lisp_Object Qexternal_debugging_output; | |
859 | ||
4746118a | 860 | DEFUN ("external-debugging-output", Fexternal_debugging_output, Sexternal_debugging_output, 1, 1, 0, |
8c1a1077 PJ |
861 | doc: /* Write CHARACTER to stderr. |
862 | You can call print while debugging emacs, and pass it this function | |
863 | to make it write to the debugging output. */) | |
5842a27b | 864 | (Lisp_Object character) |
38010d50 | 865 | { |
b7826503 | 866 | CHECK_NUMBER (character); |
db063399 | 867 | putc ((int) XINT (character), stderr); |
cd22039d RS |
868 | |
869 | #ifdef WINDOWSNT | |
870 | /* Send the output to a debugger (nothing happens if there isn't one). */ | |
945b0111 EZ |
871 | if (print_output_debug_flag) |
872 | { | |
873 | char buf[2] = {(char) XINT (character), '\0'}; | |
874 | OutputDebugString (buf); | |
875 | } | |
cd22039d RS |
876 | #endif |
877 | ||
38010d50 JB |
878 | return character; |
879 | } | |
cf1bb91b | 880 | |
c33f8948 RS |
881 | /* This function is never called. Its purpose is to prevent |
882 | print_output_debug_flag from being optimized away. */ | |
883 | ||
dae581bf | 884 | void |
971de7fb | 885 | debug_output_compilation_hack (int x) |
c33f8948 RS |
886 | { |
887 | print_output_debug_flag = x; | |
888 | } | |
6b61353c | 889 | |
cd3587c1 | 890 | #if defined (GNU_LINUX) |
6b61353c KH |
891 | |
892 | /* This functionality is not vitally important in general, so we rely on | |
893 | non-portable ability to use stderr as lvalue. */ | |
894 | ||
895 | #define WITH_REDIRECT_DEBUGGING_OUTPUT 1 | |
896 | ||
897 | FILE *initial_stderr_stream = NULL; | |
898 | ||
899 | DEFUN ("redirect-debugging-output", Fredirect_debugging_output, Sredirect_debugging_output, | |
900 | 1, 2, | |
901 | "FDebug output file: \nP", | |
902 | doc: /* Redirect debugging output (stderr stream) to file FILE. | |
903 | If FILE is nil, reset target to the initial stderr stream. | |
904 | Optional arg APPEND non-nil (interactively, with prefix arg) means | |
28b8f740 | 905 | append to existing target file. */) |
5842a27b | 906 | (Lisp_Object file, Lisp_Object append) |
6b61353c KH |
907 | { |
908 | if (initial_stderr_stream != NULL) | |
f9467be3 YM |
909 | { |
910 | BLOCK_INPUT; | |
911 | fclose (stderr); | |
912 | UNBLOCK_INPUT; | |
913 | } | |
6b61353c KH |
914 | stderr = initial_stderr_stream; |
915 | initial_stderr_stream = NULL; | |
916 | ||
917 | if (STRINGP (file)) | |
918 | { | |
919 | file = Fexpand_file_name (file, Qnil); | |
920 | initial_stderr_stream = stderr; | |
cd3587c1 | 921 | stderr = fopen (SDATA (file), NILP (append) ? "w" : "a"); |
6b61353c KH |
922 | if (stderr == NULL) |
923 | { | |
924 | stderr = initial_stderr_stream; | |
925 | initial_stderr_stream = NULL; | |
926 | report_file_error ("Cannot open debugging output stream", | |
927 | Fcons (file, Qnil)); | |
928 | } | |
929 | } | |
930 | return Qnil; | |
931 | } | |
932 | #endif /* GNU_LINUX */ | |
933 | ||
934 | ||
cf1bb91b RS |
935 | /* This is the interface for debugging printing. */ |
936 | ||
937 | void | |
971de7fb | 938 | debug_print (Lisp_Object arg) |
cf1bb91b RS |
939 | { |
940 | Fprin1 (arg, Qexternal_debugging_output); | |
3684eb78 | 941 | fprintf (stderr, "\r\n"); |
cf1bb91b | 942 | } |
bd90dcd0 KS |
943 | |
944 | void | |
971de7fb | 945 | safe_debug_print (Lisp_Object arg) |
bd90dcd0 KS |
946 | { |
947 | int valid = valid_lisp_object_p (arg); | |
948 | ||
949 | if (valid > 0) | |
950 | debug_print (arg); | |
951 | else | |
952 | fprintf (stderr, "#<%s_LISP_OBJECT 0x%08lx>\r\n", | |
953 | !valid ? "INVALID" : "SOME", | |
4c37a414 | 954 | (unsigned long) XHASH (arg) |
bd90dcd0 KS |
955 | ); |
956 | } | |
957 | ||
38010d50 | 958 | \f |
113620cc KH |
959 | DEFUN ("error-message-string", Ferror_message_string, Serror_message_string, |
960 | 1, 1, 0, | |
6b61353c KH |
961 | doc: /* Convert an error value (ERROR-SYMBOL . DATA) to an error message. |
962 | See Info anchor `(elisp)Definition of signal' for some details on how this | |
963 | error message is constructed. */) | |
5842a27b | 964 | (Lisp_Object obj) |
113620cc KH |
965 | { |
966 | struct buffer *old = current_buffer; | |
63fbf4ff | 967 | Lisp_Object value; |
113620cc KH |
968 | struct gcpro gcpro1; |
969 | ||
0872e11f RS |
970 | /* If OBJ is (error STRING), just return STRING. |
971 | That is not only faster, it also avoids the need to allocate | |
972 | space here when the error is due to memory full. */ | |
94b342ce KR |
973 | if (CONSP (obj) && EQ (XCAR (obj), Qerror) |
974 | && CONSP (XCDR (obj)) | |
975 | && STRINGP (XCAR (XCDR (obj))) | |
976 | && NILP (XCDR (XCDR (obj)))) | |
977 | return XCAR (XCDR (obj)); | |
0872e11f | 978 | |
240e806c | 979 | print_error_message (obj, Vprin1_to_string_buffer, 0, Qnil); |
113620cc KH |
980 | |
981 | set_buffer_internal (XBUFFER (Vprin1_to_string_buffer)); | |
982 | value = Fbuffer_string (); | |
983 | ||
984 | GCPRO1 (value); | |
985 | Ferase_buffer (); | |
986 | set_buffer_internal (old); | |
987 | UNGCPRO; | |
988 | ||
989 | return value; | |
990 | } | |
991 | ||
c02279de | 992 | /* Print an error message for the error DATA onto Lisp output stream |
7ab56fea RS |
993 | STREAM (suitable for the print functions). |
994 | CONTEXT is a C string describing the context of the error. | |
995 | CALLER is the Lisp function inside which the error was signaled. */ | |
113620cc | 996 | |
dc22f25e | 997 | void |
a8fe7202 AS |
998 | print_error_message (Lisp_Object data, Lisp_Object stream, const char *context, |
999 | Lisp_Object caller) | |
113620cc KH |
1000 | { |
1001 | Lisp_Object errname, errmsg, file_error, tail; | |
1002 | struct gcpro gcpro1; | |
1003 | int i; | |
1004 | ||
240e806c RS |
1005 | if (context != 0) |
1006 | write_string_1 (context, -1, stream); | |
1007 | ||
1008 | /* If we know from where the error was signaled, show it in | |
1009 | *Messages*. */ | |
1010 | if (!NILP (caller) && SYMBOLP (caller)) | |
1011 | { | |
11fb15d5 KS |
1012 | Lisp_Object cname = SYMBOL_NAME (caller); |
1013 | char *name = alloca (SBYTES (cname)); | |
72af86bd | 1014 | memcpy (name, SDATA (cname), SBYTES (cname)); |
826256dd | 1015 | message_dolog (name, SBYTES (cname), 0, 0); |
240e806c RS |
1016 | message_dolog (": ", 2, 0, 0); |
1017 | } | |
1018 | ||
113620cc KH |
1019 | errname = Fcar (data); |
1020 | ||
1021 | if (EQ (errname, Qerror)) | |
1022 | { | |
1023 | data = Fcdr (data); | |
c02279de GM |
1024 | if (!CONSP (data)) |
1025 | data = Qnil; | |
113620cc KH |
1026 | errmsg = Fcar (data); |
1027 | file_error = Qnil; | |
1028 | } | |
1029 | else | |
1030 | { | |
c02279de | 1031 | Lisp_Object error_conditions; |
113620cc | 1032 | errmsg = Fget (errname, Qerror_message); |
c02279de GM |
1033 | error_conditions = Fget (errname, Qerror_conditions); |
1034 | file_error = Fmemq (Qfile_error, error_conditions); | |
113620cc KH |
1035 | } |
1036 | ||
1037 | /* Print an error message including the data items. */ | |
1038 | ||
1039 | tail = Fcdr_safe (data); | |
1040 | GCPRO1 (tail); | |
1041 | ||
1042 | /* For file-error, make error message by concatenating | |
1043 | all the data items. They are all strings. */ | |
8c29413d | 1044 | if (!NILP (file_error) && CONSP (tail)) |
94b342ce | 1045 | errmsg = XCAR (tail), tail = XCDR (tail); |
113620cc KH |
1046 | |
1047 | if (STRINGP (errmsg)) | |
1048 | Fprinc (errmsg, stream); | |
1049 | else | |
1050 | write_string_1 ("peculiar error", -1, stream); | |
1051 | ||
c02279de | 1052 | for (i = 0; CONSP (tail); tail = XCDR (tail), i++) |
113620cc | 1053 | { |
c02279de GM |
1054 | Lisp_Object obj; |
1055 | ||
113620cc | 1056 | write_string_1 (i ? ", " : ": ", 2, stream); |
c02279de GM |
1057 | obj = XCAR (tail); |
1058 | if (!NILP (file_error) || EQ (errname, Qend_of_file)) | |
1059 | Fprinc (obj, stream); | |
113620cc | 1060 | else |
c02279de | 1061 | Fprin1 (obj, stream); |
113620cc | 1062 | } |
177c0ea7 | 1063 | |
113620cc KH |
1064 | UNGCPRO; |
1065 | } | |
38010d50 | 1066 | |
c02279de GM |
1067 | |
1068 | \f | |
38010d50 | 1069 | /* |
edb2a707 | 1070 | * The buffer should be at least as large as the max string size of the |
8e6208c5 | 1071 | * largest float, printed in the biggest notation. This is undoubtedly |
38010d50 JB |
1072 | * 20d float_output_format, with the negative of the C-constant "HUGE" |
1073 | * from <math.h>. | |
177c0ea7 | 1074 | * |
38010d50 | 1075 | * On the vax the worst case is -1e38 in 20d format which takes 61 bytes. |
177c0ea7 | 1076 | * |
38010d50 JB |
1077 | * I assume that IEEE-754 format numbers can take 329 bytes for the worst |
1078 | * case of -1e307 in 20d float_output_format. What is one to do (short of | |
1079 | * re-writing _doprnt to be more sane)? | |
1080 | * -wsr | |
1081 | */ | |
edb2a707 RS |
1082 | |
1083 | void | |
971de7fb | 1084 | float_to_string (unsigned char *buf, double data) |
38010d50 | 1085 | { |
c7b14277 | 1086 | unsigned char *cp; |
322890c4 | 1087 | int width; |
177c0ea7 | 1088 | |
7f45de2d RS |
1089 | /* Check for plus infinity in a way that won't lose |
1090 | if there is no plus infinity. */ | |
1091 | if (data == data / 2 && data > 1.0) | |
1092 | { | |
1093 | strcpy (buf, "1.0e+INF"); | |
1094 | return; | |
1095 | } | |
1096 | /* Likewise for minus infinity. */ | |
1097 | if (data == data / 2 && data < -1.0) | |
1098 | { | |
1099 | strcpy (buf, "-1.0e+INF"); | |
1100 | return; | |
1101 | } | |
1102 | /* Check for NaN in a way that won't fail if there are no NaNs. */ | |
1103 | if (! (data * 0.0 >= 0.0)) | |
1104 | { | |
68c45bf0 PE |
1105 | /* Prepend "-" if the NaN's sign bit is negative. |
1106 | The sign bit of a double is the bit that is 1 in -0.0. */ | |
1107 | int i; | |
1108 | union { double d; char c[sizeof (double)]; } u_data, u_minus_zero; | |
1109 | u_data.d = data; | |
1110 | u_minus_zero.d = - 0.0; | |
1111 | for (i = 0; i < sizeof (double); i++) | |
1112 | if (u_data.c[i] & u_minus_zero.c[i]) | |
1113 | { | |
1114 | *buf++ = '-'; | |
1115 | break; | |
1116 | } | |
177c0ea7 | 1117 | |
7f45de2d RS |
1118 | strcpy (buf, "0.0e+NaN"); |
1119 | return; | |
1120 | } | |
1121 | ||
10eebdbb | 1122 | if (NILP (Vfloat_output_format) |
d4ae1f7e | 1123 | || !STRINGP (Vfloat_output_format)) |
38010d50 | 1124 | lose: |
322890c4 | 1125 | { |
f356c3fb PE |
1126 | /* Generate the fewest number of digits that represent the |
1127 | floating point value without losing information. | |
1128 | The following method is simple but a bit slow. | |
1129 | For ideas about speeding things up, please see: | |
1130 | ||
1131 | Guy L Steele Jr & Jon L White, How to print floating-point numbers | |
1132 | accurately. SIGPLAN notices 25, 6 (June 1990), 112-126. | |
1133 | ||
1134 | Robert G Burger & R Kent Dybvig, Printing floating point numbers | |
1135 | quickly and accurately, SIGPLAN notices 31, 5 (May 1996), 108-116. */ | |
1136 | ||
1137 | width = fabs (data) < DBL_MIN ? 1 : DBL_DIG; | |
1138 | do | |
1139 | sprintf (buf, "%.*g", width, data); | |
1140 | while (width++ < DOUBLE_DIGITS_BOUND && atof (buf) != data); | |
322890c4 | 1141 | } |
38010d50 JB |
1142 | else /* oink oink */ |
1143 | { | |
1144 | /* Check that the spec we have is fully valid. | |
1145 | This means not only valid for printf, | |
1146 | but meant for floats, and reasonable. */ | |
d5db4077 | 1147 | cp = SDATA (Vfloat_output_format); |
38010d50 JB |
1148 | |
1149 | if (cp[0] != '%') | |
1150 | goto lose; | |
1151 | if (cp[1] != '.') | |
1152 | goto lose; | |
1153 | ||
1154 | cp += 2; | |
c7b14277 JB |
1155 | |
1156 | /* Check the width specification. */ | |
322890c4 | 1157 | width = -1; |
c7b14277 | 1158 | if ('0' <= *cp && *cp <= '9') |
381cd4bb KH |
1159 | { |
1160 | width = 0; | |
1161 | do | |
1162 | width = (width * 10) + (*cp++ - '0'); | |
1163 | while (*cp >= '0' && *cp <= '9'); | |
1164 | ||
1165 | /* A precision of zero is valid only for %f. */ | |
1166 | if (width > DBL_DIG | |
1167 | || (width == 0 && *cp != 'f')) | |
1168 | goto lose; | |
1169 | } | |
38010d50 JB |
1170 | |
1171 | if (*cp != 'e' && *cp != 'f' && *cp != 'g') | |
1172 | goto lose; | |
1173 | ||
38010d50 JB |
1174 | if (cp[1] != 0) |
1175 | goto lose; | |
1176 | ||
d5db4077 | 1177 | sprintf (buf, SDATA (Vfloat_output_format), data); |
38010d50 | 1178 | } |
edb2a707 | 1179 | |
c7b14277 JB |
1180 | /* Make sure there is a decimal point with digit after, or an |
1181 | exponent, so that the value is readable as a float. But don't do | |
322890c4 RS |
1182 | this with "%.0f"; it's valid for that not to produce a decimal |
1183 | point. Note that width can be 0 only for %.0f. */ | |
1184 | if (width != 0) | |
0601fd3d | 1185 | { |
c7b14277 JB |
1186 | for (cp = buf; *cp; cp++) |
1187 | if ((*cp < '0' || *cp > '9') && *cp != '-') | |
1188 | break; | |
0601fd3d | 1189 | |
c7b14277 JB |
1190 | if (*cp == '.' && cp[1] == 0) |
1191 | { | |
1192 | cp[1] = '0'; | |
1193 | cp[2] = 0; | |
1194 | } | |
1195 | ||
1196 | if (*cp == 0) | |
1197 | { | |
1198 | *cp++ = '.'; | |
1199 | *cp++ = '0'; | |
1200 | *cp++ = 0; | |
1201 | } | |
edb2a707 | 1202 | } |
38010d50 | 1203 | } |
cc94f3b2 | 1204 | |
38010d50 JB |
1205 | \f |
1206 | static void | |
971de7fb | 1207 | print (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag) |
38010d50 | 1208 | { |
a22dec27 | 1209 | new_backquote_output = 0; |
38010d50 | 1210 | |
0f25ecc6 RS |
1211 | /* Reset print_number_index and Vprint_number_table only when |
1212 | the variable Vprint_continuous_numbering is nil. Otherwise, | |
1213 | the values of these variables will be kept between several | |
1214 | print functions. */ | |
e026eb89 KS |
1215 | if (NILP (Vprint_continuous_numbering) |
1216 | || NILP (Vprint_number_table)) | |
0f25ecc6 RS |
1217 | { |
1218 | print_number_index = 0; | |
1219 | Vprint_number_table = Qnil; | |
1220 | } | |
38010d50 | 1221 | |
0f25ecc6 RS |
1222 | /* Construct Vprint_number_table for print-gensym and print-circle. */ |
1223 | if (!NILP (Vprint_gensym) || !NILP (Vprint_circle)) | |
ec838c39 | 1224 | { |
e6d4cddd RS |
1225 | /* Construct Vprint_number_table. |
1226 | This increments print_number_index for the objects added. */ | |
9a6a4c40 | 1227 | print_depth = 0; |
0f25ecc6 | 1228 | print_preprocess (obj); |
e6d4cddd | 1229 | |
a65b85b5 SM |
1230 | if (HASH_TABLE_P (Vprint_number_table)) |
1231 | { /* Remove unnecessary objects, which appear only once in OBJ; | |
1232 | that is, whose status is Qt. | |
1233 | Maybe a better way to do that is to copy elements to | |
1234 | a new hash table. */ | |
1235 | struct Lisp_Hash_Table *h = XHASH_TABLE (Vprint_number_table); | |
1236 | int i; | |
e6d4cddd | 1237 | |
a65b85b5 SM |
1238 | for (i = 0; i < HASH_TABLE_SIZE (h); ++i) |
1239 | if (!NILP (HASH_HASH (h, i)) | |
1240 | && EQ (HASH_VALUE (h, i), Qt)) | |
1241 | Fremhash (HASH_KEY (h, i), Vprint_number_table); | |
1242 | } | |
0f25ecc6 RS |
1243 | } |
1244 | ||
9a6a4c40 | 1245 | print_depth = 0; |
0f25ecc6 RS |
1246 | print_object (obj, printcharfun, escapeflag); |
1247 | } | |
1248 | ||
1249 | /* Construct Vprint_number_table according to the structure of OBJ. | |
1250 | OBJ itself and all its elements will be added to Vprint_number_table | |
1251 | recursively if it is a list, vector, compiled function, char-table, | |
1252 | string (its text properties will be traced), or a symbol that has | |
1253 | no obarray (this is for the print-gensym feature). | |
1254 | The status fields of Vprint_number_table mean whether each object appears | |
1255 | more than once in OBJ: Qnil at the first time, and Qt after that . */ | |
1256 | static void | |
971de7fb | 1257 | print_preprocess (Lisp_Object obj) |
0f25ecc6 | 1258 | { |
6b61353c KH |
1259 | int i; |
1260 | EMACS_INT size; | |
c1132671 RS |
1261 | int loop_count = 0; |
1262 | Lisp_Object halftail; | |
1263 | ||
15479e8b RS |
1264 | /* Give up if we go so deep that print_object will get an error. */ |
1265 | /* See similar code in print_object. */ | |
1266 | if (print_depth >= PRINT_CIRCLE) | |
6b8dfbf7 | 1267 | error ("Apparently circular structure being printed"); |
15479e8b | 1268 | |
c1132671 RS |
1269 | /* Avoid infinite recursion for circular nested structure |
1270 | in the case where Vprint_circle is nil. */ | |
1271 | if (NILP (Vprint_circle)) | |
1272 | { | |
1273 | for (i = 0; i < print_depth; i++) | |
1274 | if (EQ (obj, being_printed[i])) | |
1275 | return; | |
1276 | being_printed[print_depth] = obj; | |
1277 | } | |
1278 | ||
c1132671 RS |
1279 | print_depth++; |
1280 | halftail = obj; | |
0f25ecc6 RS |
1281 | |
1282 | loop: | |
1283 | if (STRINGP (obj) || CONSP (obj) || VECTORP (obj) | |
6d77fa95 | 1284 | || COMPILEDP (obj) || CHAR_TABLE_P (obj) || SUB_CHAR_TABLE_P (obj) |
f19a0f5b | 1285 | || HASH_TABLE_P (obj) |
0f25ecc6 | 1286 | || (! NILP (Vprint_gensym) |
bf9f2aab GM |
1287 | && SYMBOLP (obj) |
1288 | && !SYMBOL_INTERNED_P (obj))) | |
0f25ecc6 | 1289 | { |
a65b85b5 SM |
1290 | if (!HASH_TABLE_P (Vprint_number_table)) |
1291 | { | |
1292 | Lisp_Object args[2]; | |
1293 | args[0] = QCtest; | |
1294 | args[1] = Qeq; | |
1295 | Vprint_number_table = Fmake_hash_table (2, args); | |
1296 | } | |
1297 | ||
aca2020b KH |
1298 | /* In case print-circle is nil and print-gensym is t, |
1299 | add OBJ to Vprint_number_table only when OBJ is a symbol. */ | |
1300 | if (! NILP (Vprint_circle) || SYMBOLP (obj)) | |
0f25ecc6 | 1301 | { |
a65b85b5 SM |
1302 | Lisp_Object num = Fgethash (obj, Vprint_number_table, Qnil); |
1303 | if (!NILP (num) | |
1304 | /* If Vprint_continuous_numbering is non-nil and OBJ is a gensym, | |
1305 | always print the gensym with a number. This is a special for | |
1306 | the lisp function byte-compile-output-docform. */ | |
1307 | || (!NILP (Vprint_continuous_numbering) | |
1308 | && SYMBOLP (obj) | |
1309 | && !SYMBOL_INTERNED_P (obj))) | |
1310 | { /* OBJ appears more than once. Let's remember that. */ | |
17870c01 | 1311 | if (!INTEGERP (num)) |
aca2020b | 1312 | { |
a65b85b5 SM |
1313 | print_number_index++; |
1314 | /* Negative number indicates it hasn't been printed yet. */ | |
1315 | Fputhash (obj, make_number (- print_number_index), | |
1316 | Vprint_number_table); | |
aca2020b | 1317 | } |
a65b85b5 SM |
1318 | print_depth--; |
1319 | return; | |
0f25ecc6 | 1320 | } |
a65b85b5 SM |
1321 | else |
1322 | /* OBJ is not yet recorded. Let's add to the table. */ | |
1323 | Fputhash (obj, Qt, Vprint_number_table); | |
0f25ecc6 | 1324 | } |
0f25ecc6 | 1325 | |
8e50cc2d | 1326 | switch (XTYPE (obj)) |
0f25ecc6 RS |
1327 | { |
1328 | case Lisp_String: | |
0f25ecc6 | 1329 | /* A string may have text properties, which can be circular. */ |
d5db4077 | 1330 | traverse_intervals_noorder (STRING_INTERVALS (obj), |
8bbfc258 | 1331 | print_preprocess_string, Qnil); |
0f25ecc6 RS |
1332 | break; |
1333 | ||
1334 | case Lisp_Cons: | |
c1132671 RS |
1335 | /* Use HALFTAIL and LOOP_COUNT to detect circular lists, |
1336 | just as in print_object. */ | |
1337 | if (loop_count && EQ (obj, halftail)) | |
1338 | break; | |
0f25ecc6 RS |
1339 | print_preprocess (XCAR (obj)); |
1340 | obj = XCDR (obj); | |
c1132671 RS |
1341 | loop_count++; |
1342 | if (!(loop_count & 1)) | |
1343 | halftail = XCDR (halftail); | |
0f25ecc6 RS |
1344 | goto loop; |
1345 | ||
1346 | case Lisp_Vectorlike: | |
6b61353c KH |
1347 | size = XVECTOR (obj)->size; |
1348 | if (size & PSEUDOVECTOR_FLAG) | |
1349 | size &= PSEUDOVECTOR_SIZE_MASK; | |
0f25ecc6 RS |
1350 | for (i = 0; i < size; i++) |
1351 | print_preprocess (XVECTOR (obj)->contents[i]); | |
3e0de07f SM |
1352 | if (HASH_TABLE_P (obj)) |
1353 | { /* For hash tables, the key_and_value slot is past | |
a65b85b5 SM |
1354 | `size' because it needs to be marked specially in case |
1355 | the table is weak. */ | |
3e0de07f SM |
1356 | struct Lisp_Hash_Table *h = XHASH_TABLE (obj); |
1357 | print_preprocess (h->key_and_value); | |
1358 | } | |
ee5263af GM |
1359 | break; |
1360 | ||
1361 | default: | |
1362 | break; | |
0f25ecc6 RS |
1363 | } |
1364 | } | |
c1132671 | 1365 | print_depth--; |
0f25ecc6 RS |
1366 | } |
1367 | ||
0f25ecc6 | 1368 | static void |
971de7fb | 1369 | print_preprocess_string (INTERVAL interval, Lisp_Object arg) |
0f25ecc6 RS |
1370 | { |
1371 | print_preprocess (interval->plist); | |
1372 | } | |
0f25ecc6 | 1373 | |
71ea13cb KH |
1374 | /* A flag to control printing of `charset' text property. |
1375 | The default value is Qdefault. */ | |
1376 | Lisp_Object Vprint_charset_text_property; | |
71ea13cb | 1377 | |
971de7fb | 1378 | static void print_check_string_charset_prop (INTERVAL interval, Lisp_Object string); |
71ea13cb KH |
1379 | |
1380 | #define PRINT_STRING_NON_CHARSET_FOUND 1 | |
1381 | #define PRINT_STRING_UNSAFE_CHARSET_FOUND 2 | |
1382 | ||
51e4f4a8 | 1383 | /* Bitwise or of the above macros. */ |
71ea13cb KH |
1384 | static int print_check_string_result; |
1385 | ||
1386 | static void | |
971de7fb | 1387 | print_check_string_charset_prop (INTERVAL interval, Lisp_Object string) |
71ea13cb KH |
1388 | { |
1389 | Lisp_Object val; | |
1390 | ||
1391 | if (NILP (interval->plist) | |
1392 | || (print_check_string_result == (PRINT_STRING_NON_CHARSET_FOUND | |
1393 | | PRINT_STRING_UNSAFE_CHARSET_FOUND))) | |
1394 | return; | |
1395 | for (val = interval->plist; CONSP (val) && ! EQ (XCAR (val), Qcharset); | |
1396 | val = XCDR (XCDR (val))); | |
1397 | if (! CONSP (val)) | |
1398 | { | |
1399 | print_check_string_result |= PRINT_STRING_NON_CHARSET_FOUND; | |
1400 | return; | |
1401 | } | |
1402 | if (! (print_check_string_result & PRINT_STRING_NON_CHARSET_FOUND)) | |
1403 | { | |
1404 | if (! EQ (val, interval->plist) | |
1405 | || CONSP (XCDR (XCDR (val)))) | |
1406 | print_check_string_result |= PRINT_STRING_NON_CHARSET_FOUND; | |
1407 | } | |
1408 | if (NILP (Vprint_charset_text_property) | |
1409 | || ! (print_check_string_result & PRINT_STRING_UNSAFE_CHARSET_FOUND)) | |
1410 | { | |
1411 | int i, c; | |
db063399 LMI |
1412 | EMACS_INT charpos = interval->position; |
1413 | EMACS_INT bytepos = string_char_to_byte (string, charpos); | |
71ea13cb KH |
1414 | Lisp_Object charset; |
1415 | ||
1416 | charset = XCAR (XCDR (val)); | |
1417 | for (i = 0; i < LENGTH (interval); i++) | |
1418 | { | |
1419 | FETCH_STRING_CHAR_ADVANCE (c, string, charpos, bytepos); | |
c80bcdbc KH |
1420 | if (! ASCII_CHAR_P (c) |
1421 | && ! EQ (CHARSET_NAME (CHAR_CHARSET (c)), charset)) | |
71ea13cb KH |
1422 | { |
1423 | print_check_string_result |= PRINT_STRING_UNSAFE_CHARSET_FOUND; | |
1424 | break; | |
1425 | } | |
1426 | } | |
1427 | } | |
1428 | } | |
1429 | ||
1430 | /* The value is (charset . nil). */ | |
1431 | static Lisp_Object print_prune_charset_plist; | |
1432 | ||
1433 | static Lisp_Object | |
971de7fb | 1434 | print_prune_string_charset (Lisp_Object string) |
71ea13cb KH |
1435 | { |
1436 | print_check_string_result = 0; | |
1437 | traverse_intervals (STRING_INTERVALS (string), 0, | |
1438 | print_check_string_charset_prop, string); | |
1439 | if (! (print_check_string_result & PRINT_STRING_UNSAFE_CHARSET_FOUND)) | |
1440 | { | |
1441 | string = Fcopy_sequence (string); | |
1442 | if (print_check_string_result & PRINT_STRING_NON_CHARSET_FOUND) | |
1443 | { | |
1444 | if (NILP (print_prune_charset_plist)) | |
1445 | print_prune_charset_plist = Fcons (Qcharset, Qnil); | |
eabe04c0 KH |
1446 | Fremove_text_properties (make_number (0), |
1447 | make_number (SCHARS (string)), | |
71ea13cb KH |
1448 | print_prune_charset_plist, string); |
1449 | } | |
1450 | else | |
eabe04c0 KH |
1451 | Fset_text_properties (make_number (0), make_number (SCHARS (string)), |
1452 | Qnil, string); | |
71ea13cb KH |
1453 | } |
1454 | return string; | |
1455 | } | |
1456 | ||
0f25ecc6 | 1457 | static void |
971de7fb | 1458 | print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag) |
0f25ecc6 | 1459 | { |
28b8f740 | 1460 | char buf[40]; |
0f25ecc6 RS |
1461 | |
1462 | QUIT; | |
1463 | ||
76afdf7e | 1464 | /* See similar code in print_preprocess. */ |
51dc79f8 | 1465 | if (print_depth >= PRINT_CIRCLE) |
76afdf7e CY |
1466 | error ("Apparently circular structure being printed"); |
1467 | ||
0f25ecc6 RS |
1468 | /* Detect circularities and truncate them. */ |
1469 | if (STRINGP (obj) || CONSP (obj) || VECTORP (obj) | |
dec47cc3 | 1470 | || COMPILEDP (obj) || CHAR_TABLE_P (obj) || SUB_CHAR_TABLE_P (obj) |
f19a0f5b | 1471 | || HASH_TABLE_P (obj) |
0f25ecc6 | 1472 | || (! NILP (Vprint_gensym) |
bf9f2aab GM |
1473 | && SYMBOLP (obj) |
1474 | && !SYMBOL_INTERNED_P (obj))) | |
0f25ecc6 RS |
1475 | { |
1476 | if (NILP (Vprint_circle) && NILP (Vprint_gensym)) | |
1477 | { | |
1478 | /* Simple but incomplete way. */ | |
1479 | int i; | |
1480 | for (i = 0; i < print_depth; i++) | |
1481 | if (EQ (obj, being_printed[i])) | |
1482 | { | |
1483 | sprintf (buf, "#%d", i); | |
1484 | strout (buf, -1, -1, printcharfun, 0); | |
1485 | return; | |
1486 | } | |
1487 | being_printed[print_depth] = obj; | |
1488 | } | |
1489 | else | |
1490 | { | |
1491 | /* With the print-circle feature. */ | |
a65b85b5 SM |
1492 | Lisp_Object num = Fgethash (obj, Vprint_number_table, Qnil); |
1493 | if (INTEGERP (num)) | |
1494 | { | |
1495 | int n = XINT (num); | |
1496 | if (n < 0) | |
1497 | { /* Add a prefix #n= if OBJ has not yet been printed; | |
1498 | that is, its status field is nil. */ | |
1499 | sprintf (buf, "#%d=", -n); | |
1500 | strout (buf, -1, -1, printcharfun, 0); | |
1501 | /* OBJ is going to be printed. Remember that fact. */ | |
1502 | Fputhash (obj, make_number (- n), Vprint_number_table); | |
1503 | } | |
1504 | else | |
1505 | { | |
1506 | /* Just print #n# if OBJ has already been printed. */ | |
1507 | sprintf (buf, "#%d#", n); | |
1508 | strout (buf, -1, -1, printcharfun, 0); | |
1509 | return; | |
1510 | } | |
1511 | } | |
0f25ecc6 | 1512 | } |
ec838c39 | 1513 | } |
ec838c39 | 1514 | |
38010d50 JB |
1515 | print_depth++; |
1516 | ||
8e50cc2d | 1517 | switch (XTYPE (obj)) |
38010d50 | 1518 | { |
2de9f71c | 1519 | case_Lisp_Int: |
b8180922 | 1520 | if (sizeof (int) == sizeof (EMACS_INT)) |
6af1696d | 1521 | sprintf (buf, "%d", (int) XINT (obj)); |
b8180922 | 1522 | else if (sizeof (long) == sizeof (EMACS_INT)) |
63fbf4ff | 1523 | sprintf (buf, "%ld", (long) XINT (obj)); |
b8180922 RS |
1524 | else |
1525 | abort (); | |
dc2a0b79 | 1526 | strout (buf, -1, -1, printcharfun, 0); |
ca0569ad RS |
1527 | break; |
1528 | ||
ca0569ad RS |
1529 | case Lisp_Float: |
1530 | { | |
1531 | char pigbuf[350]; /* see comments in float_to_string */ | |
38010d50 | 1532 | |
94b342ce | 1533 | float_to_string (pigbuf, XFLOAT_DATA (obj)); |
dc2a0b79 | 1534 | strout (pigbuf, -1, -1, printcharfun, 0); |
ca0569ad RS |
1535 | } |
1536 | break; | |
ca0569ad RS |
1537 | |
1538 | case Lisp_String: | |
38010d50 JB |
1539 | if (!escapeflag) |
1540 | print_string (obj, printcharfun); | |
1541 | else | |
1542 | { | |
da43f021 | 1543 | register EMACS_INT i, i_byte; |
38010d50 | 1544 | struct gcpro gcpro1; |
872a36d2 | 1545 | unsigned char *str; |
db063399 | 1546 | EMACS_INT size_byte; |
453fa987 RS |
1547 | /* 1 means we must ensure that the next character we output |
1548 | cannot be taken as part of a hex character escape. */ | |
1549 | int need_nonhex = 0; | |
db300f59 | 1550 | int multibyte = STRING_MULTIBYTE (obj); |
38010d50 | 1551 | |
7651e1f5 RS |
1552 | GCPRO1 (obj); |
1553 | ||
71ea13cb KH |
1554 | if (! EQ (Vprint_charset_text_property, Qt)) |
1555 | obj = print_prune_string_charset (obj); | |
1556 | ||
d5db4077 | 1557 | if (!NULL_INTERVAL_P (STRING_INTERVALS (obj))) |
7651e1f5 RS |
1558 | { |
1559 | PRINTCHAR ('#'); | |
1560 | PRINTCHAR ('('); | |
1561 | } | |
38010d50 JB |
1562 | |
1563 | PRINTCHAR ('\"'); | |
d5db4077 KR |
1564 | str = SDATA (obj); |
1565 | size_byte = SBYTES (obj); | |
dc2a0b79 RS |
1566 | |
1567 | for (i = 0, i_byte = 0; i_byte < size_byte;) | |
38010d50 | 1568 | { |
6ddd6eee RS |
1569 | /* Here, we must convert each multi-byte form to the |
1570 | corresponding character code before handing it to PRINTCHAR. */ | |
1571 | int len; | |
dc2a0b79 RS |
1572 | int c; |
1573 | ||
db300f59 | 1574 | if (multibyte) |
872a36d2 | 1575 | { |
62a6e103 | 1576 | c = STRING_CHAR_AND_LENGTH (str + i_byte, len); |
8b4b4467 | 1577 | i_byte += len; |
872a36d2 | 1578 | } |
dc2a0b79 | 1579 | else |
872a36d2 | 1580 | c = str[i_byte++]; |
dc2a0b79 | 1581 | |
38010d50 | 1582 | QUIT; |
6ddd6eee | 1583 | |
38010d50 JB |
1584 | if (c == '\n' && print_escape_newlines) |
1585 | { | |
1586 | PRINTCHAR ('\\'); | |
1587 | PRINTCHAR ('n'); | |
1588 | } | |
c6f7982f RM |
1589 | else if (c == '\f' && print_escape_newlines) |
1590 | { | |
1591 | PRINTCHAR ('\\'); | |
1592 | PRINTCHAR ('f'); | |
1593 | } | |
ae7367d3 | 1594 | else if (multibyte |
73af357a KH |
1595 | && (CHAR_BYTE8_P (c) |
1596 | || (! ASCII_CHAR_P (c) && print_escape_multibyte))) | |
dc2a0b79 RS |
1597 | { |
1598 | /* When multibyte is disabled, | |
ae7367d3 RS |
1599 | print multibyte string chars using hex escapes. |
1600 | For a char code that could be in a unibyte string, | |
1601 | when found in a multibyte string, always use a hex escape | |
1602 | so it reads back as multibyte. */ | |
dc2a0b79 | 1603 | unsigned char outbuf[50]; |
8b4b4467 KH |
1604 | |
1605 | if (CHAR_BYTE8_P (c)) | |
1606 | sprintf (outbuf, "\\%03o", CHAR_TO_BYTE8 (c)); | |
1607 | else | |
8f924df7 KH |
1608 | { |
1609 | sprintf (outbuf, "\\x%04x", c); | |
1610 | need_nonhex = 1; | |
1611 | } | |
dc2a0b79 RS |
1612 | strout (outbuf, -1, -1, printcharfun, 0); |
1613 | } | |
db300f59 RS |
1614 | else if (! multibyte |
1615 | && SINGLE_BYTE_CHAR_P (c) && ! ASCII_BYTE_P (c) | |
835d0be6 | 1616 | && print_escape_nonascii) |
974a6ff5 | 1617 | { |
835d0be6 RS |
1618 | /* When printing in a multibyte buffer |
1619 | or when explicitly requested, | |
974a6ff5 KH |
1620 | print single-byte non-ASCII string chars |
1621 | using octal escapes. */ | |
1622 | unsigned char outbuf[5]; | |
1623 | sprintf (outbuf, "\\%03o", c); | |
1624 | strout (outbuf, -1, -1, printcharfun, 0); | |
1625 | } | |
38010d50 JB |
1626 | else |
1627 | { | |
453fa987 RS |
1628 | /* If we just had a hex escape, and this character |
1629 | could be taken as part of it, | |
1630 | output `\ ' to prevent that. */ | |
1b62edd6 KH |
1631 | if (need_nonhex) |
1632 | { | |
1633 | need_nonhex = 0; | |
1634 | if ((c >= 'a' && c <= 'f') | |
453fa987 | 1635 | || (c >= 'A' && c <= 'F') |
1b62edd6 KH |
1636 | || (c >= '0' && c <= '9')) |
1637 | strout ("\\ ", -1, -1, printcharfun, 0); | |
1638 | } | |
453fa987 | 1639 | |
38010d50 JB |
1640 | if (c == '\"' || c == '\\') |
1641 | PRINTCHAR ('\\'); | |
1642 | PRINTCHAR (c); | |
1643 | } | |
1644 | } | |
1645 | PRINTCHAR ('\"'); | |
7651e1f5 | 1646 | |
d5db4077 | 1647 | if (!NULL_INTERVAL_P (STRING_INTERVALS (obj))) |
7651e1f5 | 1648 | { |
d5db4077 | 1649 | traverse_intervals (STRING_INTERVALS (obj), |
8bbfc258 | 1650 | 0, print_interval, printcharfun); |
7651e1f5 RS |
1651 | PRINTCHAR (')'); |
1652 | } | |
7651e1f5 | 1653 | |
38010d50 JB |
1654 | UNGCPRO; |
1655 | } | |
ca0569ad | 1656 | break; |
38010d50 | 1657 | |
ca0569ad RS |
1658 | case Lisp_Symbol: |
1659 | { | |
1660 | register int confusing; | |
d5db4077 KR |
1661 | register unsigned char *p = SDATA (SYMBOL_NAME (obj)); |
1662 | register unsigned char *end = p + SBYTES (SYMBOL_NAME (obj)); | |
2190a05e | 1663 | register int c; |
db063399 LMI |
1664 | int i, i_byte; |
1665 | EMACS_INT size_byte; | |
dc2a0b79 RS |
1666 | Lisp_Object name; |
1667 | ||
76d0b3ae | 1668 | name = SYMBOL_NAME (obj); |
ca0569ad RS |
1669 | |
1670 | if (p != end && (*p == '-' || *p == '+')) p++; | |
1671 | if (p == end) | |
1672 | confusing = 0; | |
d27497e3 RS |
1673 | /* If symbol name begins with a digit, and ends with a digit, |
1674 | and contains nothing but digits and `e', it could be treated | |
1675 | as a number. So set CONFUSING. | |
1676 | ||
1677 | Symbols that contain periods could also be taken as numbers, | |
1678 | but periods are always escaped, so we don't have to worry | |
1679 | about them here. */ | |
1680 | else if (*p >= '0' && *p <= '9' | |
1681 | && end[-1] >= '0' && end[-1] <= '9') | |
ca0569ad | 1682 | { |
e837058b RS |
1683 | while (p != end && ((*p >= '0' && *p <= '9') |
1684 | /* Needed for \2e10. */ | |
01a8d3fa | 1685 | || *p == 'e' || *p == 'E')) |
ca0569ad RS |
1686 | p++; |
1687 | confusing = (end == p); | |
1688 | } | |
d27497e3 RS |
1689 | else |
1690 | confusing = 0; | |
ca0569ad | 1691 | |
bf9f2aab | 1692 | if (! NILP (Vprint_gensym) && !SYMBOL_INTERNED_P (obj)) |
081e0581 | 1693 | { |
081e0581 EN |
1694 | PRINTCHAR ('#'); |
1695 | PRINTCHAR (':'); | |
1696 | } | |
1697 | ||
d5db4077 | 1698 | size_byte = SBYTES (name); |
dc2a0b79 RS |
1699 | |
1700 | for (i = 0, i_byte = 0; i_byte < size_byte;) | |
ca0569ad | 1701 | { |
6ddd6eee RS |
1702 | /* Here, we must convert each multi-byte form to the |
1703 | corresponding character code before handing it to PRINTCHAR. */ | |
eba90784 | 1704 | FETCH_STRING_CHAR_ADVANCE (c, name, i, i_byte); |
ca0569ad | 1705 | QUIT; |
09eddb56 | 1706 | |
ca0569ad RS |
1707 | if (escapeflag) |
1708 | { | |
09eddb56 RS |
1709 | if (c == '\"' || c == '\\' || c == '\'' |
1710 | || c == ';' || c == '#' || c == '(' || c == ')' | |
1711 | || c == ',' || c =='.' || c == '`' | |
1712 | || c == '[' || c == ']' || c == '?' || c <= 040 | |
1713 | || confusing) | |
ca0569ad RS |
1714 | PRINTCHAR ('\\'), confusing = 0; |
1715 | } | |
1716 | PRINTCHAR (c); | |
1717 | } | |
1718 | } | |
1719 | break; | |
1720 | ||
1721 | case Lisp_Cons: | |
38010d50 | 1722 | /* If deeper than spec'd depth, print placeholder. */ |
d4ae1f7e | 1723 | if (INTEGERP (Vprint_level) |
38010d50 | 1724 | && print_depth > XINT (Vprint_level)) |
dc2a0b79 | 1725 | strout ("...", -1, -1, printcharfun, 0); |
2f100b5c EN |
1726 | else if (print_quoted && CONSP (XCDR (obj)) && NILP (XCDR (XCDR (obj))) |
1727 | && (EQ (XCAR (obj), Qquote))) | |
1728 | { | |
1729 | PRINTCHAR ('\''); | |
0f25ecc6 | 1730 | print_object (XCAR (XCDR (obj)), printcharfun, escapeflag); |
2f100b5c EN |
1731 | } |
1732 | else if (print_quoted && CONSP (XCDR (obj)) && NILP (XCDR (XCDR (obj))) | |
1733 | && (EQ (XCAR (obj), Qfunction))) | |
1734 | { | |
1735 | PRINTCHAR ('#'); | |
1736 | PRINTCHAR ('\''); | |
0f25ecc6 | 1737 | print_object (XCAR (XCDR (obj)), printcharfun, escapeflag); |
2f100b5c EN |
1738 | } |
1739 | else if (print_quoted && CONSP (XCDR (obj)) && NILP (XCDR (XCDR (obj))) | |
a22dec27 SM |
1740 | && ((EQ (XCAR (obj), Qbackquote)))) |
1741 | { | |
1742 | print_object (XCAR (obj), printcharfun, 0); | |
1743 | new_backquote_output++; | |
1744 | print_object (XCAR (XCDR (obj)), printcharfun, escapeflag); | |
1745 | new_backquote_output--; | |
1746 | } | |
1747 | else if (print_quoted && CONSP (XCDR (obj)) && NILP (XCDR (XCDR (obj))) | |
1748 | && new_backquote_output | |
2f100b5c EN |
1749 | && ((EQ (XCAR (obj), Qbackquote) |
1750 | || EQ (XCAR (obj), Qcomma) | |
1751 | || EQ (XCAR (obj), Qcomma_at) | |
1752 | || EQ (XCAR (obj), Qcomma_dot)))) | |
1753 | { | |
0f25ecc6 | 1754 | print_object (XCAR (obj), printcharfun, 0); |
a22dec27 | 1755 | new_backquote_output--; |
0f25ecc6 | 1756 | print_object (XCAR (XCDR (obj)), printcharfun, escapeflag); |
a22dec27 | 1757 | new_backquote_output++; |
2f100b5c | 1758 | } |
e0f93814 | 1759 | else |
38010d50 | 1760 | { |
e0f93814 | 1761 | PRINTCHAR ('('); |
177c0ea7 | 1762 | |
0330bb60 RS |
1763 | /* If the first element is a backquote form, |
1764 | print it old-style so it won't be misunderstood. */ | |
1765 | if (print_quoted && CONSP (XCAR (obj)) | |
1766 | && CONSP (XCDR (XCAR (obj))) | |
1767 | && NILP (XCDR (XCDR (XCAR (obj)))) | |
1768 | && EQ (XCAR (XCAR (obj)), Qbackquote)) | |
1769 | { | |
1770 | Lisp_Object tem; | |
1771 | tem = XCAR (obj); | |
1772 | PRINTCHAR ('('); | |
1773 | ||
1774 | print_object (Qbackquote, printcharfun, 0); | |
1775 | PRINTCHAR (' '); | |
1776 | ||
0330bb60 | 1777 | print_object (XCAR (XCDR (tem)), printcharfun, 0); |
0330bb60 RS |
1778 | PRINTCHAR (')'); |
1779 | ||
1780 | obj = XCDR (obj); | |
1781 | } | |
1782 | ||
38010d50 | 1783 | { |
db063399 LMI |
1784 | EMACS_INT print_length; |
1785 | int i; | |
1eab22b5 | 1786 | Lisp_Object halftail = obj; |
e0f93814 | 1787 | |
9ab8560d | 1788 | /* Negative values of print-length are invalid in CL. |
42ac1ed4 GM |
1789 | Treat them like nil, as CMUCL does. */ |
1790 | if (NATNUMP (Vprint_length)) | |
1791 | print_length = XFASTINT (Vprint_length); | |
1792 | else | |
1793 | print_length = 0; | |
1794 | ||
1795 | i = 0; | |
e0f93814 | 1796 | while (CONSP (obj)) |
38010d50 | 1797 | { |
1eab22b5 | 1798 | /* Detect circular list. */ |
0f25ecc6 | 1799 | if (NILP (Vprint_circle)) |
1eab22b5 | 1800 | { |
0f25ecc6 RS |
1801 | /* Simple but imcomplete way. */ |
1802 | if (i != 0 && EQ (obj, halftail)) | |
1803 | { | |
1804 | sprintf (buf, " . #%d", i / 2); | |
1805 | strout (buf, -1, -1, printcharfun, 0); | |
1806 | goto end_of_list; | |
1807 | } | |
1808 | } | |
1809 | else | |
1810 | { | |
1811 | /* With the print-circle feature. */ | |
1812 | if (i != 0) | |
1813 | { | |
a65b85b5 SM |
1814 | Lisp_Object num = Fgethash (obj, Vprint_number_table, Qnil); |
1815 | if (INTEGERP (num)) | |
36de6a04 AS |
1816 | { |
1817 | strout (" . ", 3, 3, printcharfun, 0); | |
1818 | print_object (obj, printcharfun, escapeflag); | |
1819 | goto end_of_list; | |
1820 | } | |
0f25ecc6 | 1821 | } |
1eab22b5 | 1822 | } |
177c0ea7 | 1823 | |
e0f93814 KH |
1824 | if (i++) |
1825 | PRINTCHAR (' '); | |
177c0ea7 | 1826 | |
f4fe72d5 | 1827 | if (print_length && i > print_length) |
e0f93814 | 1828 | { |
dc2a0b79 | 1829 | strout ("...", 3, 3, printcharfun, 0); |
0f25ecc6 | 1830 | goto end_of_list; |
e0f93814 | 1831 | } |
177c0ea7 | 1832 | |
0f25ecc6 | 1833 | print_object (XCAR (obj), printcharfun, escapeflag); |
177c0ea7 | 1834 | |
2f100b5c | 1835 | obj = XCDR (obj); |
1eab22b5 RS |
1836 | if (!(i & 1)) |
1837 | halftail = XCDR (halftail); | |
38010d50 | 1838 | } |
38010d50 | 1839 | } |
42ac1ed4 GM |
1840 | |
1841 | /* OBJ non-nil here means it's the end of a dotted list. */ | |
2f100b5c | 1842 | if (!NILP (obj)) |
e0f93814 | 1843 | { |
dc2a0b79 | 1844 | strout (" . ", 3, 3, printcharfun, 0); |
0f25ecc6 | 1845 | print_object (obj, printcharfun, escapeflag); |
e0f93814 | 1846 | } |
177c0ea7 | 1847 | |
0f25ecc6 | 1848 | end_of_list: |
e0f93814 | 1849 | PRINTCHAR (')'); |
38010d50 | 1850 | } |
ca0569ad RS |
1851 | break; |
1852 | ||
1853 | case Lisp_Vectorlike: | |
1854 | if (PROCESSP (obj)) | |
1855 | { | |
1856 | if (escapeflag) | |
1857 | { | |
dc2a0b79 | 1858 | strout ("#<process ", -1, -1, printcharfun, 0); |
ca0569ad RS |
1859 | print_string (XPROCESS (obj)->name, printcharfun); |
1860 | PRINTCHAR ('>'); | |
1861 | } | |
1862 | else | |
1863 | print_string (XPROCESS (obj)->name, printcharfun); | |
1864 | } | |
ed2c35ef RS |
1865 | else if (BOOL_VECTOR_P (obj)) |
1866 | { | |
1867 | register int i; | |
1868 | register unsigned char c; | |
1869 | struct gcpro gcpro1; | |
db063399 | 1870 | EMACS_INT size_in_chars |
4b5af5e4 AS |
1871 | = ((XBOOL_VECTOR (obj)->size + BOOL_VECTOR_BITS_PER_CHAR - 1) |
1872 | / BOOL_VECTOR_BITS_PER_CHAR); | |
ed2c35ef RS |
1873 | |
1874 | GCPRO1 (obj); | |
1875 | ||
1876 | PRINTCHAR ('#'); | |
1877 | PRINTCHAR ('&'); | |
474f84d9 | 1878 | sprintf (buf, "%ld", (long) XBOOL_VECTOR (obj)->size); |
dc2a0b79 | 1879 | strout (buf, -1, -1, printcharfun, 0); |
ed2c35ef | 1880 | PRINTCHAR ('\"'); |
a40384bc | 1881 | |
42ac1ed4 | 1882 | /* Don't print more characters than the specified maximum. |
9ab8560d | 1883 | Negative values of print-length are invalid. Treat them |
42ac1ed4 GM |
1884 | like a print-length of nil. */ |
1885 | if (NATNUMP (Vprint_length) | |
1886 | && XFASTINT (Vprint_length) < size_in_chars) | |
1887 | size_in_chars = XFASTINT (Vprint_length); | |
a40384bc | 1888 | |
ed2c35ef RS |
1889 | for (i = 0; i < size_in_chars; i++) |
1890 | { | |
1891 | QUIT; | |
1892 | c = XBOOL_VECTOR (obj)->data[i]; | |
f10fdbfd | 1893 | if (c == '\n' && print_escape_newlines) |
ed2c35ef RS |
1894 | { |
1895 | PRINTCHAR ('\\'); | |
1896 | PRINTCHAR ('n'); | |
1897 | } | |
1898 | else if (c == '\f' && print_escape_newlines) | |
1899 | { | |
1900 | PRINTCHAR ('\\'); | |
1901 | PRINTCHAR ('f'); | |
1902 | } | |
4b5af5e4 AS |
1903 | else if (c > '\177') |
1904 | { | |
1905 | /* Use octal escapes to avoid encoding issues. */ | |
1906 | PRINTCHAR ('\\'); | |
1907 | PRINTCHAR ('0' + ((c >> 6) & 3)); | |
1908 | PRINTCHAR ('0' + ((c >> 3) & 7)); | |
1909 | PRINTCHAR ('0' + (c & 7)); | |
1910 | } | |
ed2c35ef RS |
1911 | else |
1912 | { | |
1913 | if (c == '\"' || c == '\\') | |
1914 | PRINTCHAR ('\\'); | |
1915 | PRINTCHAR (c); | |
1916 | } | |
1917 | } | |
1918 | PRINTCHAR ('\"'); | |
1919 | ||
1920 | UNGCPRO; | |
1921 | } | |
ca0569ad RS |
1922 | else if (SUBRP (obj)) |
1923 | { | |
dc2a0b79 RS |
1924 | strout ("#<subr ", -1, -1, printcharfun, 0); |
1925 | strout (XSUBR (obj)->symbol_name, -1, -1, printcharfun, 0); | |
ca0569ad RS |
1926 | PRINTCHAR ('>'); |
1927 | } | |
ca0569ad RS |
1928 | else if (WINDOWP (obj)) |
1929 | { | |
dc2a0b79 | 1930 | strout ("#<window ", -1, -1, printcharfun, 0); |
474f84d9 | 1931 | sprintf (buf, "%ld", (long) XFASTINT (XWINDOW (obj)->sequence_number)); |
dc2a0b79 | 1932 | strout (buf, -1, -1, printcharfun, 0); |
ca0569ad RS |
1933 | if (!NILP (XWINDOW (obj)->buffer)) |
1934 | { | |
dc2a0b79 | 1935 | strout (" on ", -1, -1, printcharfun, 0); |
ca0569ad RS |
1936 | print_string (XBUFFER (XWINDOW (obj)->buffer)->name, printcharfun); |
1937 | } | |
1938 | PRINTCHAR ('>'); | |
1939 | } | |
f76c8b1e SM |
1940 | else if (TERMINALP (obj)) |
1941 | { | |
1942 | struct terminal *t = XTERMINAL (obj); | |
1943 | strout ("#<terminal ", -1, -1, printcharfun, 0); | |
1944 | sprintf (buf, "%d", t->id); | |
1945 | strout (buf, -1, -1, printcharfun, 0); | |
1946 | if (t->name) | |
1947 | { | |
1948 | strout (" on ", -1, -1, printcharfun, 0); | |
1949 | strout (t->name, -1, -1, printcharfun, 0); | |
1950 | } | |
1951 | PRINTCHAR ('>'); | |
1952 | } | |
7eb03302 GM |
1953 | else if (HASH_TABLE_P (obj)) |
1954 | { | |
1955 | struct Lisp_Hash_Table *h = XHASH_TABLE (obj); | |
db063399 LMI |
1956 | int i; |
1957 | EMACS_INT real_size, size; | |
f19a0f5b | 1958 | #if 0 |
7eb03302 GM |
1959 | strout ("#<hash-table", -1, -1, printcharfun, 0); |
1960 | if (SYMBOLP (h->test)) | |
1961 | { | |
1962 | PRINTCHAR (' '); | |
1963 | PRINTCHAR ('\''); | |
d5db4077 | 1964 | strout (SDATA (SYMBOL_NAME (h->test)), -1, -1, printcharfun, 0); |
7eb03302 | 1965 | PRINTCHAR (' '); |
d5db4077 | 1966 | strout (SDATA (SYMBOL_NAME (h->weak)), -1, -1, printcharfun, 0); |
7eb03302 | 1967 | PRINTCHAR (' '); |
878f97ff | 1968 | sprintf (buf, "%ld/%ld", (long) h->count, |
474f84d9 | 1969 | (long) XVECTOR (h->next)->size); |
7eb03302 GM |
1970 | strout (buf, -1, -1, printcharfun, 0); |
1971 | } | |
1972 | sprintf (buf, " 0x%lx", (unsigned long) h); | |
1973 | strout (buf, -1, -1, printcharfun, 0); | |
1974 | PRINTCHAR ('>'); | |
f19a0f5b TZ |
1975 | #endif |
1976 | /* Implement a readable output, e.g.: | |
1977 | #s(hash-table size 2 test equal data (k1 v1 k2 v2)) */ | |
1978 | /* Always print the size. */ | |
1979 | sprintf (buf, "#s(hash-table size %ld", | |
1980 | (long) XVECTOR (h->next)->size); | |
1981 | strout (buf, -1, -1, printcharfun, 0); | |
1982 | ||
1983 | if (!NILP (h->test)) | |
1984 | { | |
1985 | strout (" test ", -1, -1, printcharfun, 0); | |
1986 | print_object (h->test, printcharfun, 0); | |
1987 | } | |
1988 | ||
1989 | if (!NILP (h->weak)) | |
1990 | { | |
1991 | strout (" weakness ", -1, -1, printcharfun, 0); | |
1992 | print_object (h->weak, printcharfun, 0); | |
1993 | } | |
1994 | ||
1995 | if (!NILP (h->rehash_size)) | |
1996 | { | |
1997 | strout (" rehash-size ", -1, -1, printcharfun, 0); | |
1998 | print_object (h->rehash_size, printcharfun, 0); | |
1999 | } | |
2000 | ||
2001 | if (!NILP (h->rehash_threshold)) | |
2002 | { | |
2003 | strout (" rehash-threshold ", -1, -1, printcharfun, 0); | |
2004 | print_object (h->rehash_threshold, printcharfun, 0); | |
2005 | } | |
2006 | ||
2007 | strout (" data ", -1, -1, printcharfun, 0); | |
2008 | ||
2009 | /* Print the data here as a plist. */ | |
b0ca0f33 DN |
2010 | real_size = HASH_TABLE_SIZE (h); |
2011 | size = real_size; | |
f19a0f5b TZ |
2012 | |
2013 | /* Don't print more elements than the specified maximum. */ | |
2014 | if (NATNUMP (Vprint_length) | |
2015 | && XFASTINT (Vprint_length) < size) | |
2016 | size = XFASTINT (Vprint_length); | |
2017 | ||
2018 | PRINTCHAR ('('); | |
2019 | for (i = 0; i < size; i++) | |
2020 | if (!NILP (HASH_HASH (h, i))) | |
2021 | { | |
2022 | if (i) PRINTCHAR (' '); | |
3ed8bbdc | 2023 | print_object (HASH_KEY (h, i), printcharfun, 1); |
f19a0f5b | 2024 | PRINTCHAR (' '); |
3ed8bbdc | 2025 | print_object (HASH_VALUE (h, i), printcharfun, 1); |
f19a0f5b TZ |
2026 | } |
2027 | ||
2028 | if (size < real_size) | |
2029 | strout (" ...", 4, 4, printcharfun, 0); | |
2030 | ||
2031 | PRINTCHAR (')'); | |
2032 | PRINTCHAR (')'); | |
2033 | ||
7eb03302 | 2034 | } |
908b0ae5 RS |
2035 | else if (BUFFERP (obj)) |
2036 | { | |
2037 | if (NILP (XBUFFER (obj)->name)) | |
dc2a0b79 | 2038 | strout ("#<killed buffer>", -1, -1, printcharfun, 0); |
908b0ae5 RS |
2039 | else if (escapeflag) |
2040 | { | |
dc2a0b79 | 2041 | strout ("#<buffer ", -1, -1, printcharfun, 0); |
908b0ae5 RS |
2042 | print_string (XBUFFER (obj)->name, printcharfun); |
2043 | PRINTCHAR ('>'); | |
2044 | } | |
2045 | else | |
2046 | print_string (XBUFFER (obj)->name, printcharfun); | |
2047 | } | |
ca0569ad RS |
2048 | else if (WINDOW_CONFIGURATIONP (obj)) |
2049 | { | |
dc2a0b79 | 2050 | strout ("#<window-configuration>", -1, -1, printcharfun, 0); |
ca0569ad | 2051 | } |
ca0569ad RS |
2052 | else if (FRAMEP (obj)) |
2053 | { | |
2054 | strout ((FRAME_LIVE_P (XFRAME (obj)) | |
2055 | ? "#<frame " : "#<dead frame "), | |
dc2a0b79 | 2056 | -1, -1, printcharfun, 0); |
ca0569ad | 2057 | print_string (XFRAME (obj)->name, printcharfun); |
aab3aa14 | 2058 | sprintf (buf, " 0x%lx", (unsigned long) (XFRAME (obj))); |
dc2a0b79 | 2059 | strout (buf, -1, -1, printcharfun, 0); |
ca0569ad RS |
2060 | PRINTCHAR ('>'); |
2061 | } | |
2a7b7982 KH |
2062 | else if (FONTP (obj)) |
2063 | { | |
2064 | EMACS_INT i; | |
2065 | ||
2066 | if (! FONT_OBJECT_P (obj)) | |
2067 | { | |
2068 | if (FONT_SPEC_P (obj)) | |
2069 | strout ("#<font-spec", -1, -1, printcharfun, 0); | |
2070 | else | |
2071 | strout ("#<font-entity", -1, -1, printcharfun, 0); | |
2072 | for (i = 0; i < FONT_SPEC_MAX; i++) | |
2073 | { | |
2074 | PRINTCHAR (' '); | |
2075 | if (i < FONT_WEIGHT_INDEX || i > FONT_WIDTH_INDEX) | |
2076 | print_object (AREF (obj, i), printcharfun, escapeflag); | |
2077 | else | |
2078 | print_object (font_style_symbolic (obj, i, 0), | |
2079 | printcharfun, escapeflag); | |
2080 | } | |
2081 | } | |
2082 | else | |
2083 | { | |
2084 | strout ("#<font-object ", -1, -1, printcharfun, 0); | |
2085 | print_object (AREF (obj, FONT_NAME_INDEX), printcharfun, | |
2086 | escapeflag); | |
2087 | } | |
2088 | PRINTCHAR ('>'); | |
2089 | } | |
ca0569ad RS |
2090 | else |
2091 | { | |
6b61353c | 2092 | EMACS_INT size = XVECTOR (obj)->size; |
ca0569ad RS |
2093 | if (COMPILEDP (obj)) |
2094 | { | |
2095 | PRINTCHAR ('#'); | |
2096 | size &= PSEUDOVECTOR_SIZE_MASK; | |
2097 | } | |
8b4b4467 | 2098 | if (CHAR_TABLE_P (obj) || SUB_CHAR_TABLE_P (obj)) |
ed2c35ef RS |
2099 | { |
2100 | /* We print a char-table as if it were a vector, | |
2101 | lumping the parent and default slots in with the | |
2102 | character slots. But we add #^ as a prefix. */ | |
223509a3 KH |
2103 | |
2104 | /* Make each lowest sub_char_table start a new line. | |
2105 | Otherwise we'll make a line extremely long, which | |
2106 | results in slow redisplay. */ | |
2107 | if (SUB_CHAR_TABLE_P (obj) | |
2108 | && XINT (XSUB_CHAR_TABLE (obj)->depth) == 3) | |
2109 | PRINTCHAR ('\n'); | |
ed2c35ef RS |
2110 | PRINTCHAR ('#'); |
2111 | PRINTCHAR ('^'); | |
3701b5de KH |
2112 | if (SUB_CHAR_TABLE_P (obj)) |
2113 | PRINTCHAR ('^'); | |
ed2c35ef RS |
2114 | size &= PSEUDOVECTOR_SIZE_MASK; |
2115 | } | |
00d76abc KH |
2116 | if (size & PSEUDOVECTOR_FLAG) |
2117 | goto badtype; | |
ca0569ad RS |
2118 | |
2119 | PRINTCHAR ('['); | |
38010d50 | 2120 | { |
ca0569ad RS |
2121 | register int i; |
2122 | register Lisp_Object tem; | |
db063399 | 2123 | EMACS_INT real_size = size; |
a40384bc RS |
2124 | |
2125 | /* Don't print more elements than the specified maximum. */ | |
42ac1ed4 GM |
2126 | if (NATNUMP (Vprint_length) |
2127 | && XFASTINT (Vprint_length) < size) | |
2128 | size = XFASTINT (Vprint_length); | |
a40384bc | 2129 | |
ca0569ad RS |
2130 | for (i = 0; i < size; i++) |
2131 | { | |
2132 | if (i) PRINTCHAR (' '); | |
2133 | tem = XVECTOR (obj)->contents[i]; | |
0f25ecc6 | 2134 | print_object (tem, printcharfun, escapeflag); |
ca0569ad | 2135 | } |
d6ac884e KH |
2136 | if (size < real_size) |
2137 | strout (" ...", 4, 4, printcharfun, 0); | |
38010d50 | 2138 | } |
ca0569ad RS |
2139 | PRINTCHAR (']'); |
2140 | } | |
2141 | break; | |
2142 | ||
ca0569ad | 2143 | case Lisp_Misc: |
5db20f08 | 2144 | switch (XMISCTYPE (obj)) |
38010d50 | 2145 | { |
00d76abc | 2146 | case Lisp_Misc_Marker: |
dc2a0b79 | 2147 | strout ("#<marker ", -1, -1, printcharfun, 0); |
087e3c46 KH |
2148 | /* Do you think this is necessary? */ |
2149 | if (XMARKER (obj)->insertion_type != 0) | |
210ebd3d | 2150 | strout ("(moves after insertion) ", -1, -1, printcharfun, 0); |
cd3587c1 | 2151 | if (! XMARKER (obj)->buffer) |
dc2a0b79 | 2152 | strout ("in no buffer", -1, -1, printcharfun, 0); |
ca0569ad RS |
2153 | else |
2154 | { | |
d585695f | 2155 | sprintf (buf, "at %ld", (long)marker_position (obj)); |
dc2a0b79 RS |
2156 | strout (buf, -1, -1, printcharfun, 0); |
2157 | strout (" in ", -1, -1, printcharfun, 0); | |
ca0569ad RS |
2158 | print_string (XMARKER (obj)->buffer->name, printcharfun); |
2159 | } | |
38010d50 | 2160 | PRINTCHAR ('>'); |
908b0ae5 | 2161 | break; |
00d76abc KH |
2162 | |
2163 | case Lisp_Misc_Overlay: | |
dc2a0b79 | 2164 | strout ("#<overlay ", -1, -1, printcharfun, 0); |
cd3587c1 | 2165 | if (! XMARKER (OVERLAY_START (obj))->buffer) |
dc2a0b79 | 2166 | strout ("in no buffer", -1, -1, printcharfun, 0); |
ca0569ad RS |
2167 | else |
2168 | { | |
d585695f EZ |
2169 | sprintf (buf, "from %ld to %ld in ", |
2170 | (long)marker_position (OVERLAY_START (obj)), | |
2171 | (long)marker_position (OVERLAY_END (obj))); | |
dc2a0b79 | 2172 | strout (buf, -1, -1, printcharfun, 0); |
ca0569ad RS |
2173 | print_string (XMARKER (OVERLAY_START (obj))->buffer->name, |
2174 | printcharfun); | |
2175 | } | |
2176 | PRINTCHAR ('>'); | |
908b0ae5 | 2177 | break; |
00d76abc KH |
2178 | |
2179 | /* Remaining cases shouldn't happen in normal usage, but let's print | |
2180 | them anyway for the benefit of the debugger. */ | |
2181 | case Lisp_Misc_Free: | |
dc2a0b79 | 2182 | strout ("#<misc free cell>", -1, -1, printcharfun, 0); |
00d76abc KH |
2183 | break; |
2184 | ||
c069fee4 KS |
2185 | case Lisp_Misc_Save_Value: |
2186 | strout ("#<save_value ", -1, -1, printcharfun, 0); | |
44455197 | 2187 | sprintf(buf, "ptr=0x%08lx int=%d", |
c069fee4 KS |
2188 | (unsigned long) XSAVE_VALUE (obj)->pointer, |
2189 | XSAVE_VALUE (obj)->integer); | |
2190 | strout (buf, -1, -1, printcharfun, 0); | |
2191 | PRINTCHAR ('>'); | |
2192 | break; | |
2193 | ||
00d76abc KH |
2194 | default: |
2195 | goto badtype; | |
e0f93814 | 2196 | } |
00d76abc | 2197 | break; |
ca0569ad RS |
2198 | |
2199 | default: | |
00d76abc | 2200 | badtype: |
ca0569ad RS |
2201 | { |
2202 | /* We're in trouble if this happens! | |
2203 | Probably should just abort () */ | |
dc2a0b79 | 2204 | strout ("#<EMACS BUG: INVALID DATATYPE ", -1, -1, printcharfun, 0); |
00d76abc | 2205 | if (MISCP (obj)) |
5db20f08 | 2206 | sprintf (buf, "(MISC 0x%04x)", (int) XMISCTYPE (obj)); |
00d76abc KH |
2207 | else if (VECTORLIKEP (obj)) |
2208 | sprintf (buf, "(PVEC 0x%08x)", (int) XVECTOR (obj)->size); | |
2209 | else | |
2210 | sprintf (buf, "(0x%02x)", (int) XTYPE (obj)); | |
dc2a0b79 | 2211 | strout (buf, -1, -1, printcharfun, 0); |
ca0569ad | 2212 | strout (" Save your buffers immediately and please report this bug>", |
dc2a0b79 | 2213 | -1, -1, printcharfun, 0); |
ca0569ad | 2214 | } |
38010d50 JB |
2215 | } |
2216 | ||
2217 | print_depth--; | |
2218 | } | |
2219 | \f | |
7651e1f5 RS |
2220 | |
2221 | /* Print a description of INTERVAL using PRINTCHARFUN. | |
2222 | This is part of printing a string that has text properties. */ | |
2223 | ||
2224 | void | |
971de7fb | 2225 | print_interval (INTERVAL interval, Lisp_Object printcharfun) |
7651e1f5 | 2226 | { |
71ea13cb KH |
2227 | if (NILP (interval->plist)) |
2228 | return; | |
30503c0b | 2229 | PRINTCHAR (' '); |
0f25ecc6 | 2230 | print_object (make_number (interval->position), printcharfun, 1); |
7651e1f5 | 2231 | PRINTCHAR (' '); |
0f25ecc6 | 2232 | print_object (make_number (interval->position + LENGTH (interval)), |
cd3587c1 | 2233 | printcharfun, 1); |
7651e1f5 | 2234 | PRINTCHAR (' '); |
0f25ecc6 | 2235 | print_object (interval->plist, printcharfun, 1); |
7651e1f5 RS |
2236 | } |
2237 | ||
7651e1f5 | 2238 | \f |
38010d50 | 2239 | void |
971de7fb | 2240 | syms_of_print (void) |
38010d50 | 2241 | { |
d67b4f80 | 2242 | Qtemp_buffer_setup_hook = intern_c_string ("temp-buffer-setup-hook"); |
d9c21094 RS |
2243 | staticpro (&Qtemp_buffer_setup_hook); |
2244 | ||
38010d50 | 2245 | DEFVAR_LISP ("standard-output", &Vstandard_output, |
8c1a1077 PJ |
2246 | doc: /* Output stream `print' uses by default for outputting a character. |
2247 | This may be any function of one argument. | |
2248 | It may also be a buffer (output is inserted before point) | |
2249 | or a marker (output is inserted and the marker is advanced) | |
2250 | or the symbol t (output appears in the echo area). */); | |
38010d50 | 2251 | Vstandard_output = Qt; |
d67b4f80 | 2252 | Qstandard_output = intern_c_string ("standard-output"); |
38010d50 JB |
2253 | staticpro (&Qstandard_output); |
2254 | ||
38010d50 | 2255 | DEFVAR_LISP ("float-output-format", &Vfloat_output_format, |
8c1a1077 PJ |
2256 | doc: /* The format descriptor string used to print floats. |
2257 | This is a %-spec like those accepted by `printf' in C, | |
2258 | but with some restrictions. It must start with the two characters `%.'. | |
2259 | After that comes an integer precision specification, | |
2260 | and then a letter which controls the format. | |
2261 | The letters allowed are `e', `f' and `g'. | |
2262 | Use `e' for exponential notation \"DIG.DIGITSeEXPT\" | |
2263 | Use `f' for decimal point notation \"DIGITS.DIGITS\". | |
2264 | Use `g' to choose the shorter of those two formats for the number at hand. | |
2265 | The precision in any of these cases is the number of digits following | |
2266 | the decimal point. With `f', a precision of 0 means to omit the | |
2267 | decimal point. 0 is not allowed with `e' or `g'. | |
2268 | ||
2269 | A value of nil means to use the shortest notation | |
2270 | that represents the number without losing information. */); | |
38010d50 | 2271 | Vfloat_output_format = Qnil; |
d67b4f80 | 2272 | Qfloat_output_format = intern_c_string ("float-output-format"); |
38010d50 | 2273 | staticpro (&Qfloat_output_format); |
38010d50 JB |
2274 | |
2275 | DEFVAR_LISP ("print-length", &Vprint_length, | |
8c1a1077 PJ |
2276 | doc: /* Maximum length of list to print before abbreviating. |
2277 | A value of nil means no limit. See also `eval-expression-print-length'. */); | |
38010d50 JB |
2278 | Vprint_length = Qnil; |
2279 | ||
2280 | DEFVAR_LISP ("print-level", &Vprint_level, | |
8c1a1077 PJ |
2281 | doc: /* Maximum depth of list nesting to print before abbreviating. |
2282 | A value of nil means no limit. See also `eval-expression-print-level'. */); | |
38010d50 JB |
2283 | Vprint_level = Qnil; |
2284 | ||
2285 | DEFVAR_BOOL ("print-escape-newlines", &print_escape_newlines, | |
8c1a1077 PJ |
2286 | doc: /* Non-nil means print newlines in strings as `\\n'. |
2287 | Also print formfeeds as `\\f'. */); | |
38010d50 JB |
2288 | print_escape_newlines = 0; |
2289 | ||
38940e93 | 2290 | DEFVAR_BOOL ("print-escape-nonascii", &print_escape_nonascii, |
8c1a1077 PJ |
2291 | doc: /* Non-nil means print unibyte non-ASCII chars in strings as \\OOO. |
2292 | \(OOO is the octal representation of the character code.) | |
249c0f71 RS |
2293 | Only single-byte characters are affected, and only in `prin1'. |
2294 | When the output goes in a multibyte buffer, this feature is | |
2295 | enabled regardless of the value of the variable. */); | |
38940e93 RS |
2296 | print_escape_nonascii = 0; |
2297 | ||
835d0be6 | 2298 | DEFVAR_BOOL ("print-escape-multibyte", &print_escape_multibyte, |
8c1a1077 PJ |
2299 | doc: /* Non-nil means print multibyte characters in strings as \\xXXXX. |
2300 | \(XXXX is the hex representation of the character code.) | |
2301 | This affects only `prin1'. */); | |
835d0be6 RS |
2302 | print_escape_multibyte = 0; |
2303 | ||
2f100b5c | 2304 | DEFVAR_BOOL ("print-quoted", &print_quoted, |
8c1a1077 | 2305 | doc: /* Non-nil means print quoted forms with reader syntax. |
db75cb5f | 2306 | I.e., (quote foo) prints as 'foo, (function foo) as #'foo. */); |
2f100b5c EN |
2307 | print_quoted = 0; |
2308 | ||
e0f69431 | 2309 | DEFVAR_LISP ("print-gensym", &Vprint_gensym, |
8c1a1077 PJ |
2310 | doc: /* Non-nil means print uninterned symbols so they will read as uninterned. |
2311 | I.e., the value of (make-symbol \"foobar\") prints as #:foobar. | |
2312 | When the uninterned symbol appears within a recursive data structure, | |
2313 | and the symbol appears more than once, in addition use the #N# and #N= | |
2314 | constructs as needed, so that multiple references to the same symbol are | |
2315 | shared once again when the text is read back. */); | |
e0f69431 RS |
2316 | Vprint_gensym = Qnil; |
2317 | ||
0f25ecc6 | 2318 | DEFVAR_LISP ("print-circle", &Vprint_circle, |
8c1a1077 PJ |
2319 | doc: /* *Non-nil means print recursive structures using #N= and #N# syntax. |
2320 | If nil, printing proceeds recursively and may lead to | |
2321 | `max-lisp-eval-depth' being exceeded or an error may occur: | |
2322 | \"Apparently circular structure being printed.\" Also see | |
2323 | `print-length' and `print-level'. | |
2324 | If non-nil, shared substructures anywhere in the structure are printed | |
2325 | with `#N=' before the first occurrence (in the order of the print | |
2326 | representation) and `#N#' in place of each subsequent occurrence, | |
2327 | where N is a positive decimal integer. */); | |
0f25ecc6 RS |
2328 | Vprint_circle = Qnil; |
2329 | ||
2330 | DEFVAR_LISP ("print-continuous-numbering", &Vprint_continuous_numbering, | |
8c1a1077 PJ |
2331 | doc: /* *Non-nil means number continuously across print calls. |
2332 | This affects the numbers printed for #N= labels and #M# references. | |
2333 | See also `print-circle', `print-gensym', and `print-number-table'. | |
2334 | This variable should not be set with `setq'; bind it with a `let' instead. */); | |
0f25ecc6 RS |
2335 | Vprint_continuous_numbering = Qnil; |
2336 | ||
2337 | DEFVAR_LISP ("print-number-table", &Vprint_number_table, | |
8c1a1077 PJ |
2338 | doc: /* A vector used internally to produce `#N=' labels and `#N#' references. |
2339 | The Lisp printer uses this vector to detect Lisp objects referenced more | |
e6d4cddd RS |
2340 | than once. |
2341 | ||
2342 | When you bind `print-continuous-numbering' to t, you should probably | |
2343 | also bind `print-number-table' to nil. This ensures that the value of | |
2344 | `print-number-table' can be garbage-collected once the printing is | |
2345 | done. If all elements of `print-number-table' are nil, it means that | |
2346 | the printing done so far has not found any shared structure or objects | |
2347 | that need to be recorded in the table. */); | |
0f25ecc6 | 2348 | Vprint_number_table = Qnil; |
081e0581 | 2349 | |
71ea13cb KH |
2350 | DEFVAR_LISP ("print-charset-text-property", &Vprint_charset_text_property, |
2351 | doc: /* A flag to control printing of `charset' text property on printing a string. | |
2352 | The value must be nil, t, or `default'. | |
2353 | ||
2354 | If the value is nil, don't print the text property `charset'. | |
2355 | ||
2356 | If the value is t, always print the text property `charset'. | |
2357 | ||
2358 | If the value is `default', print the text property `charset' only when | |
2359 | the value is different from what is guessed in the current charset | |
dedbd91c | 2360 | priorities. */); |
71ea13cb KH |
2361 | Vprint_charset_text_property = Qdefault; |
2362 | ||
38010d50 JB |
2363 | /* prin1_to_string_buffer initialized in init_buffer_once in buffer.c */ |
2364 | staticpro (&Vprin1_to_string_buffer); | |
2365 | ||
2366 | defsubr (&Sprin1); | |
2367 | defsubr (&Sprin1_to_string); | |
113620cc | 2368 | defsubr (&Serror_message_string); |
38010d50 JB |
2369 | defsubr (&Sprinc); |
2370 | defsubr (&Sprint); | |
2371 | defsubr (&Sterpri); | |
2372 | defsubr (&Swrite_char); | |
2373 | defsubr (&Sexternal_debugging_output); | |
6b61353c KH |
2374 | #ifdef WITH_REDIRECT_DEBUGGING_OUTPUT |
2375 | defsubr (&Sredirect_debugging_output); | |
2376 | #endif | |
38010d50 | 2377 | |
d67b4f80 | 2378 | Qexternal_debugging_output = intern_c_string ("external-debugging-output"); |
38010d50 JB |
2379 | staticpro (&Qexternal_debugging_output); |
2380 | ||
d67b4f80 | 2381 | Qprint_escape_newlines = intern_c_string ("print-escape-newlines"); |
2f100b5c EN |
2382 | staticpro (&Qprint_escape_newlines); |
2383 | ||
d67b4f80 | 2384 | Qprint_escape_multibyte = intern_c_string ("print-escape-multibyte"); |
835d0be6 RS |
2385 | staticpro (&Qprint_escape_multibyte); |
2386 | ||
d67b4f80 | 2387 | Qprint_escape_nonascii = intern_c_string ("print-escape-nonascii"); |
835d0be6 RS |
2388 | staticpro (&Qprint_escape_nonascii); |
2389 | ||
71ea13cb KH |
2390 | print_prune_charset_plist = Qnil; |
2391 | staticpro (&print_prune_charset_plist); | |
2392 | ||
38010d50 | 2393 | defsubr (&Swith_output_to_temp_buffer); |
38010d50 | 2394 | } |
6b61353c KH |
2395 | |
2396 | /* arch-tag: bc797170-94ae-41de-86e3-75e20f8f7a39 | |
2397 | (do not change this comment) */ |