* select.el (xselect--encode-string): Always use utf-8 for TEXT on Nextstep.
[emacs.git] / src / print.c
blob40e0fb6b8558e30ad62ebabd2a73748b8574d151
1 /* Lisp object printing and output streams.
3 Copyright (C) 1985-1986, 1988, 1993-1995, 1997-2012
4 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
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.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
22 #include <config.h>
23 #include <stdio.h>
24 #include <setjmp.h>
25 #include "lisp.h"
26 #include "buffer.h"
27 #include "character.h"
28 #include "charset.h"
29 #include "keyboard.h"
30 #include "frame.h"
31 #include "window.h"
32 #include "process.h"
33 #include "dispextern.h"
34 #include "termchar.h"
35 #include "intervals.h"
36 #include "blockinput.h"
37 #include "termhooks.h" /* For struct terminal. */
38 #include "font.h"
40 Lisp_Object Qstandard_output;
42 static Lisp_Object Qtemp_buffer_setup_hook;
44 /* These are used to print like we read. */
46 static Lisp_Object Qfloat_output_format;
48 #include <math.h>
49 #include <float.h>
50 #include <ftoastr.h>
52 /* Default to values appropriate for IEEE floating point. */
53 #ifndef DBL_DIG
54 #define DBL_DIG 15
55 #endif
57 /* Avoid actual stack overflow in print. */
58 static int print_depth;
60 /* Level of nesting inside outputting backquote in new style. */
61 static int new_backquote_output;
63 /* Detect most circularities to print finite output. */
64 #define PRINT_CIRCLE 200
65 static Lisp_Object being_printed[PRINT_CIRCLE];
67 /* When printing into a buffer, first we put the text in this
68 block, then insert it all at once. */
69 static char *print_buffer;
71 /* Size allocated in print_buffer. */
72 static EMACS_INT print_buffer_size;
73 /* Chars stored in print_buffer. */
74 static EMACS_INT print_buffer_pos;
75 /* Bytes stored in print_buffer. */
76 static EMACS_INT print_buffer_pos_byte;
78 Lisp_Object Qprint_escape_newlines;
79 static Lisp_Object Qprint_escape_multibyte, Qprint_escape_nonascii;
81 /* Vprint_number_table is a table, that keeps objects that are going to
82 be printed, to allow use of #n= and #n# to express sharing.
83 For any given object, the table can give the following values:
84 t the object will be printed only once.
85 -N the object will be printed several times and will take number N.
86 N the object has been printed so we can refer to it as #N#.
87 print_number_index holds the largest N already used.
88 N has to be striclty larger than 0 since we need to distinguish -N. */
89 static int print_number_index;
90 static void print_interval (INTERVAL interval, Lisp_Object printcharfun);
92 /* GDB resets this to zero on W32 to disable OutputDebugString calls. */
93 int print_output_debug_flag EXTERNALLY_VISIBLE = 1;
96 /* Low level output routines for characters and strings */
98 /* Lisp functions to do output using a stream
99 must have the stream in a variable called printcharfun
100 and must start with PRINTPREPARE, end with PRINTFINISH,
101 and use PRINTDECLARE to declare common variables.
102 Use PRINTCHAR to output one character,
103 or call strout to output a block of characters. */
105 #define PRINTDECLARE \
106 struct buffer *old = current_buffer; \
107 EMACS_INT old_point = -1, start_point = -1; \
108 EMACS_INT old_point_byte = -1, start_point_byte = -1; \
109 int specpdl_count = SPECPDL_INDEX (); \
110 int free_print_buffer = 0; \
111 int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters)); \
112 Lisp_Object original
114 #define PRINTPREPARE \
115 original = printcharfun; \
116 if (NILP (printcharfun)) printcharfun = Qt; \
117 if (BUFFERP (printcharfun)) \
119 if (XBUFFER (printcharfun) != current_buffer) \
120 Fset_buffer (printcharfun); \
121 printcharfun = Qnil; \
123 if (MARKERP (printcharfun)) \
125 EMACS_INT marker_pos; \
126 if (! XMARKER (printcharfun)->buffer) \
127 error ("Marker does not point anywhere"); \
128 if (XMARKER (printcharfun)->buffer != current_buffer) \
129 set_buffer_internal (XMARKER (printcharfun)->buffer); \
130 marker_pos = marker_position (printcharfun); \
131 if (marker_pos < BEGV || marker_pos > ZV) \
132 error ("Marker is outside the accessible part of the buffer"); \
133 old_point = PT; \
134 old_point_byte = PT_BYTE; \
135 SET_PT_BOTH (marker_pos, \
136 marker_byte_position (printcharfun)); \
137 start_point = PT; \
138 start_point_byte = PT_BYTE; \
139 printcharfun = Qnil; \
141 if (NILP (printcharfun)) \
143 Lisp_Object string; \
144 if (NILP (BVAR (current_buffer, enable_multibyte_characters)) \
145 && ! print_escape_multibyte) \
146 specbind (Qprint_escape_multibyte, Qt); \
147 if (! NILP (BVAR (current_buffer, enable_multibyte_characters)) \
148 && ! print_escape_nonascii) \
149 specbind (Qprint_escape_nonascii, Qt); \
150 if (print_buffer != 0) \
152 string = make_string_from_bytes (print_buffer, \
153 print_buffer_pos, \
154 print_buffer_pos_byte); \
155 record_unwind_protect (print_unwind, string); \
157 else \
159 ptrdiff_t new_size = 1000; \
160 print_buffer = (char *) xmalloc (new_size); \
161 print_buffer_size = new_size; \
162 free_print_buffer = 1; \
164 print_buffer_pos = 0; \
165 print_buffer_pos_byte = 0; \
167 if (EQ (printcharfun, Qt) && ! noninteractive) \
168 setup_echo_area_for_printing (multibyte);
170 #define PRINTFINISH \
171 if (NILP (printcharfun)) \
173 if (print_buffer_pos != print_buffer_pos_byte \
174 && NILP (BVAR (current_buffer, enable_multibyte_characters))) \
176 unsigned char *temp \
177 = (unsigned char *) alloca (print_buffer_pos + 1); \
178 copy_text ((unsigned char *) print_buffer, temp, \
179 print_buffer_pos_byte, 1, 0); \
180 insert_1_both ((char *) temp, print_buffer_pos, \
181 print_buffer_pos, 0, 1, 0); \
183 else \
184 insert_1_both (print_buffer, print_buffer_pos, \
185 print_buffer_pos_byte, 0, 1, 0); \
186 signal_after_change (PT - print_buffer_pos, 0, print_buffer_pos);\
188 if (free_print_buffer) \
190 xfree (print_buffer); \
191 print_buffer = 0; \
193 unbind_to (specpdl_count, Qnil); \
194 if (MARKERP (original)) \
195 set_marker_both (original, Qnil, PT, PT_BYTE); \
196 if (old_point >= 0) \
197 SET_PT_BOTH (old_point + (old_point >= start_point \
198 ? PT - start_point : 0), \
199 old_point_byte + (old_point_byte >= start_point_byte \
200 ? PT_BYTE - start_point_byte : 0)); \
201 if (old != current_buffer) \
202 set_buffer_internal (old);
204 #define PRINTCHAR(ch) printchar (ch, printcharfun)
206 /* This is used to restore the saved contents of print_buffer
207 when there is a recursive call to print. */
209 static Lisp_Object
210 print_unwind (Lisp_Object saved_text)
212 memcpy (print_buffer, SDATA (saved_text), SCHARS (saved_text));
213 return Qnil;
217 /* Print character CH using method FUN. FUN nil means print to
218 print_buffer. FUN t means print to echo area or stdout if
219 non-interactive. If FUN is neither nil nor t, call FUN with CH as
220 argument. */
222 static void
223 printchar (unsigned int ch, Lisp_Object fun)
225 if (!NILP (fun) && !EQ (fun, Qt))
226 call1 (fun, make_number (ch));
227 else
229 unsigned char str[MAX_MULTIBYTE_LENGTH];
230 int len = CHAR_STRING (ch, str);
232 QUIT;
234 if (NILP (fun))
236 if (print_buffer_size - len <= print_buffer_pos_byte)
238 ptrdiff_t new_size;
239 if (STRING_BYTES_BOUND / 2 < print_buffer_size)
240 string_overflow ();
241 new_size = print_buffer_size * 2;
242 print_buffer = (char *) xrealloc (print_buffer, new_size);
243 print_buffer_size = new_size;
245 memcpy (print_buffer + print_buffer_pos_byte, str, len);
246 print_buffer_pos += 1;
247 print_buffer_pos_byte += len;
249 else if (noninteractive)
251 fwrite (str, 1, len, stdout);
252 noninteractive_need_newline = 1;
254 else
256 int multibyte_p
257 = !NILP (BVAR (current_buffer, enable_multibyte_characters));
259 setup_echo_area_for_printing (multibyte_p);
260 insert_char (ch);
261 message_dolog ((char *) str, len, 0, multibyte_p);
267 /* Output SIZE characters, SIZE_BYTE bytes from string PTR using
268 method PRINTCHARFUN. If SIZE < 0, use the string length of PTR for
269 both SIZE and SIZE_BYTE. PRINTCHARFUN nil means output to
270 print_buffer. PRINTCHARFUN t means output to the echo area or to
271 stdout if non-interactive. If neither nil nor t, call Lisp
272 function PRINTCHARFUN for each character printed. MULTIBYTE
273 non-zero means PTR contains multibyte characters.
275 In the case where PRINTCHARFUN is nil, it is safe for PTR to point
276 to data in a Lisp string. Otherwise that is not safe. */
278 static void
279 strout (const char *ptr, EMACS_INT size, EMACS_INT size_byte,
280 Lisp_Object printcharfun)
282 if (size < 0)
283 size_byte = size = strlen (ptr);
285 if (NILP (printcharfun))
287 if (print_buffer_size - size_byte < print_buffer_pos_byte)
289 ptrdiff_t new_size;
290 if (STRING_BYTES_BOUND / 2 - size_byte < print_buffer_size)
291 string_overflow ();
292 new_size = print_buffer_size * 2 + size_byte;
293 print_buffer = (char *) xrealloc (print_buffer, new_size);
294 print_buffer_size = new_size;
296 memcpy (print_buffer + print_buffer_pos_byte, ptr, size_byte);
297 print_buffer_pos += size;
298 print_buffer_pos_byte += size_byte;
300 else if (noninteractive && EQ (printcharfun, Qt))
302 fwrite (ptr, 1, size_byte, stdout);
303 noninteractive_need_newline = 1;
305 else if (EQ (printcharfun, Qt))
307 /* Output to echo area. We're trying to avoid a little overhead
308 here, that's the reason we don't call printchar to do the
309 job. */
310 int i;
311 int multibyte_p
312 = !NILP (BVAR (current_buffer, enable_multibyte_characters));
314 setup_echo_area_for_printing (multibyte_p);
315 message_dolog (ptr, size_byte, 0, multibyte_p);
317 if (size == size_byte)
319 for (i = 0; i < size; ++i)
320 insert_char ((unsigned char) *ptr++);
322 else
324 int len;
325 for (i = 0; i < size_byte; i += len)
327 int ch = STRING_CHAR_AND_LENGTH ((const unsigned char *) ptr + i,
328 len);
329 insert_char (ch);
333 else
335 /* PRINTCHARFUN is a Lisp function. */
336 EMACS_INT i = 0;
338 if (size == size_byte)
340 while (i < size_byte)
342 int ch = ptr[i++];
343 PRINTCHAR (ch);
346 else
348 while (i < size_byte)
350 /* Here, we must convert each multi-byte form to the
351 corresponding character code before handing it to
352 PRINTCHAR. */
353 int len;
354 int ch = STRING_CHAR_AND_LENGTH ((const unsigned char *) ptr + i,
355 len);
356 PRINTCHAR (ch);
357 i += len;
363 /* Print the contents of a string STRING using PRINTCHARFUN.
364 It isn't safe to use strout in many cases,
365 because printing one char can relocate. */
367 static void
368 print_string (Lisp_Object string, Lisp_Object printcharfun)
370 if (EQ (printcharfun, Qt) || NILP (printcharfun))
372 EMACS_INT chars;
374 if (print_escape_nonascii)
375 string = string_escape_byte8 (string);
377 if (STRING_MULTIBYTE (string))
378 chars = SCHARS (string);
379 else if (! print_escape_nonascii
380 && (EQ (printcharfun, Qt)
381 ? ! NILP (BVAR (&buffer_defaults, enable_multibyte_characters))
382 : ! NILP (BVAR (current_buffer, enable_multibyte_characters))))
384 /* If unibyte string STRING contains 8-bit codes, we must
385 convert STRING to a multibyte string containing the same
386 character codes. */
387 Lisp_Object newstr;
388 EMACS_INT bytes;
390 chars = SBYTES (string);
391 bytes = count_size_as_multibyte (SDATA (string), chars);
392 if (chars < bytes)
394 newstr = make_uninit_multibyte_string (chars, bytes);
395 memcpy (SDATA (newstr), SDATA (string), chars);
396 str_to_multibyte (SDATA (newstr), bytes, chars);
397 string = newstr;
400 else
401 chars = SBYTES (string);
403 if (EQ (printcharfun, Qt))
405 /* Output to echo area. */
406 EMACS_INT nbytes = SBYTES (string);
407 char *buffer;
409 /* Copy the string contents so that relocation of STRING by
410 GC does not cause trouble. */
411 USE_SAFE_ALLOCA;
413 SAFE_ALLOCA (buffer, char *, nbytes);
414 memcpy (buffer, SDATA (string), nbytes);
416 strout (buffer, chars, SBYTES (string), printcharfun);
418 SAFE_FREE ();
420 else
421 /* No need to copy, since output to print_buffer can't GC. */
422 strout (SSDATA (string), chars, SBYTES (string), printcharfun);
424 else
426 /* Otherwise, string may be relocated by printing one char.
427 So re-fetch the string address for each character. */
428 EMACS_INT i;
429 EMACS_INT size = SCHARS (string);
430 EMACS_INT size_byte = SBYTES (string);
431 struct gcpro gcpro1;
432 GCPRO1 (string);
433 if (size == size_byte)
434 for (i = 0; i < size; i++)
435 PRINTCHAR (SREF (string, i));
436 else
437 for (i = 0; i < size_byte; )
439 /* Here, we must convert each multi-byte form to the
440 corresponding character code before handing it to PRINTCHAR. */
441 int len;
442 int ch = STRING_CHAR_AND_LENGTH (SDATA (string) + i, len);
443 PRINTCHAR (ch);
444 i += len;
446 UNGCPRO;
450 DEFUN ("write-char", Fwrite_char, Swrite_char, 1, 2, 0,
451 doc: /* Output character CHARACTER to stream PRINTCHARFUN.
452 PRINTCHARFUN defaults to the value of `standard-output' (which see). */)
453 (Lisp_Object character, Lisp_Object printcharfun)
455 PRINTDECLARE;
457 if (NILP (printcharfun))
458 printcharfun = Vstandard_output;
459 CHECK_NUMBER (character);
460 PRINTPREPARE;
461 PRINTCHAR (XINT (character));
462 PRINTFINISH;
463 return character;
466 /* Used from outside of print.c to print a block of SIZE
467 single-byte chars at DATA on the default output stream.
468 Do not use this on the contents of a Lisp string. */
470 void
471 write_string (const char *data, int size)
473 PRINTDECLARE;
474 Lisp_Object printcharfun;
476 printcharfun = Vstandard_output;
478 PRINTPREPARE;
479 strout (data, size, size, printcharfun);
480 PRINTFINISH;
483 /* Used to print a block of SIZE single-byte chars at DATA on a
484 specified stream PRINTCHARFUN.
485 Do not use this on the contents of a Lisp string. */
487 static void
488 write_string_1 (const char *data, int size, Lisp_Object printcharfun)
490 PRINTDECLARE;
492 PRINTPREPARE;
493 strout (data, size, size, printcharfun);
494 PRINTFINISH;
498 void
499 temp_output_buffer_setup (const char *bufname)
501 int count = SPECPDL_INDEX ();
502 register struct buffer *old = current_buffer;
503 register Lisp_Object buf;
505 record_unwind_protect (set_buffer_if_live, Fcurrent_buffer ());
507 Fset_buffer (Fget_buffer_create (build_string (bufname)));
509 Fkill_all_local_variables ();
510 delete_all_overlays (current_buffer);
511 BVAR (current_buffer, directory) = BVAR (old, directory);
512 BVAR (current_buffer, read_only) = Qnil;
513 BVAR (current_buffer, filename) = Qnil;
514 BVAR (current_buffer, undo_list) = Qt;
515 eassert (current_buffer->overlays_before == NULL);
516 eassert (current_buffer->overlays_after == NULL);
517 BVAR (current_buffer, enable_multibyte_characters)
518 = BVAR (&buffer_defaults, enable_multibyte_characters);
519 specbind (Qinhibit_read_only, Qt);
520 specbind (Qinhibit_modification_hooks, Qt);
521 Ferase_buffer ();
522 XSETBUFFER (buf, current_buffer);
524 Frun_hooks (1, &Qtemp_buffer_setup_hook);
526 unbind_to (count, Qnil);
528 specbind (Qstandard_output, buf);
531 static void print (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag);
532 static void print_preprocess (Lisp_Object obj);
533 static void print_preprocess_string (INTERVAL interval, Lisp_Object arg);
534 static void print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag);
536 DEFUN ("terpri", Fterpri, Sterpri, 0, 1, 0,
537 doc: /* Output a newline to stream PRINTCHARFUN.
538 If PRINTCHARFUN is omitted or nil, the value of `standard-output' is used. */)
539 (Lisp_Object printcharfun)
541 PRINTDECLARE;
543 if (NILP (printcharfun))
544 printcharfun = Vstandard_output;
545 PRINTPREPARE;
546 PRINTCHAR ('\n');
547 PRINTFINISH;
548 return Qt;
551 DEFUN ("prin1", Fprin1, Sprin1, 1, 2, 0,
552 doc: /* Output the printed representation of OBJECT, any Lisp object.
553 Quoting characters are printed when needed to make output that `read'
554 can handle, whenever this is possible. For complex objects, the behavior
555 is controlled by `print-level' and `print-length', which see.
557 OBJECT is any of the Lisp data types: a number, a string, a symbol,
558 a list, a buffer, a window, a frame, etc.
560 A printed representation of an object is text which describes that object.
562 Optional argument PRINTCHARFUN is the output stream, which can be one
563 of these:
565 - a buffer, in which case output is inserted into that buffer at point;
566 - a marker, in which case output is inserted at marker's position;
567 - a function, in which case that function is called once for each
568 character of OBJECT's printed representation;
569 - a symbol, in which case that symbol's function definition is called; or
570 - t, in which case the output is displayed in the echo area.
572 If PRINTCHARFUN is omitted, the value of `standard-output' (which see)
573 is used instead. */)
574 (Lisp_Object object, Lisp_Object printcharfun)
576 PRINTDECLARE;
578 if (NILP (printcharfun))
579 printcharfun = Vstandard_output;
580 PRINTPREPARE;
581 print (object, printcharfun, 1);
582 PRINTFINISH;
583 return object;
586 /* a buffer which is used to hold output being built by prin1-to-string */
587 Lisp_Object Vprin1_to_string_buffer;
589 DEFUN ("prin1-to-string", Fprin1_to_string, Sprin1_to_string, 1, 2, 0,
590 doc: /* Return a string containing the printed representation of OBJECT.
591 OBJECT can be any Lisp object. This function outputs quoting characters
592 when necessary to make output that `read' can handle, whenever possible,
593 unless the optional second argument NOESCAPE is non-nil. For complex objects,
594 the behavior is controlled by `print-level' and `print-length', which see.
596 OBJECT is any of the Lisp data types: a number, a string, a symbol,
597 a list, a buffer, a window, a frame, etc.
599 A printed representation of an object is text which describes that object. */)
600 (Lisp_Object object, Lisp_Object noescape)
602 Lisp_Object printcharfun;
603 /* struct gcpro gcpro1, gcpro2; */
604 Lisp_Object save_deactivate_mark;
605 int count = SPECPDL_INDEX ();
606 struct buffer *previous;
608 specbind (Qinhibit_modification_hooks, Qt);
611 PRINTDECLARE;
613 /* Save and restore this--we are altering a buffer
614 but we don't want to deactivate the mark just for that.
615 No need for specbind, since errors deactivate the mark. */
616 save_deactivate_mark = Vdeactivate_mark;
617 /* GCPRO2 (object, save_deactivate_mark); */
618 abort_on_gc++;
620 printcharfun = Vprin1_to_string_buffer;
621 PRINTPREPARE;
622 print (object, printcharfun, NILP (noescape));
623 /* Make Vprin1_to_string_buffer be the default buffer after PRINTFINISH */
624 PRINTFINISH;
627 previous = current_buffer;
628 set_buffer_internal (XBUFFER (Vprin1_to_string_buffer));
629 object = Fbuffer_string ();
630 if (SBYTES (object) == SCHARS (object))
631 STRING_SET_UNIBYTE (object);
633 /* Note that this won't make prepare_to_modify_buffer call
634 ask-user-about-supersession-threat because this buffer
635 does not visit a file. */
636 Ferase_buffer ();
637 set_buffer_internal (previous);
639 Vdeactivate_mark = save_deactivate_mark;
640 /* UNGCPRO; */
642 abort_on_gc--;
643 return unbind_to (count, object);
646 DEFUN ("princ", Fprinc, Sprinc, 1, 2, 0,
647 doc: /* Output the printed representation of OBJECT, any Lisp object.
648 No quoting characters are used; no delimiters are printed around
649 the contents of strings.
651 OBJECT is any of the Lisp data types: a number, a string, a symbol,
652 a list, a buffer, a window, a frame, etc.
654 A printed representation of an object is text which describes that object.
656 Optional argument PRINTCHARFUN is the output stream, which can be one
657 of these:
659 - a buffer, in which case output is inserted into that buffer at point;
660 - a marker, in which case output is inserted at marker's position;
661 - a function, in which case that function is called once for each
662 character of OBJECT's printed representation;
663 - a symbol, in which case that symbol's function definition is called; or
664 - t, in which case the output is displayed in the echo area.
666 If PRINTCHARFUN is omitted, the value of `standard-output' (which see)
667 is used instead. */)
668 (Lisp_Object object, Lisp_Object printcharfun)
670 PRINTDECLARE;
672 if (NILP (printcharfun))
673 printcharfun = Vstandard_output;
674 PRINTPREPARE;
675 print (object, printcharfun, 0);
676 PRINTFINISH;
677 return object;
680 DEFUN ("print", Fprint, Sprint, 1, 2, 0,
681 doc: /* Output the printed representation of OBJECT, with newlines around it.
682 Quoting characters are printed when needed to make output that `read'
683 can handle, whenever this is possible. For complex objects, the behavior
684 is controlled by `print-level' and `print-length', which see.
686 OBJECT is any of the Lisp data types: a number, a string, a symbol,
687 a list, a buffer, a window, a frame, etc.
689 A printed representation of an object is text which describes that object.
691 Optional argument PRINTCHARFUN is the output stream, which can be one
692 of these:
694 - a buffer, in which case output is inserted into that buffer at point;
695 - a marker, in which case output is inserted at marker's position;
696 - a function, in which case that function is called once for each
697 character of OBJECT's printed representation;
698 - a symbol, in which case that symbol's function definition is called; or
699 - t, in which case the output is displayed in the echo area.
701 If PRINTCHARFUN is omitted, the value of `standard-output' (which see)
702 is used instead. */)
703 (Lisp_Object object, Lisp_Object printcharfun)
705 PRINTDECLARE;
706 struct gcpro gcpro1;
708 if (NILP (printcharfun))
709 printcharfun = Vstandard_output;
710 GCPRO1 (object);
711 PRINTPREPARE;
712 PRINTCHAR ('\n');
713 print (object, printcharfun, 1);
714 PRINTCHAR ('\n');
715 PRINTFINISH;
716 UNGCPRO;
717 return object;
720 /* The subroutine object for external-debugging-output is kept here
721 for the convenience of the debugger. */
722 Lisp_Object Qexternal_debugging_output;
724 DEFUN ("external-debugging-output", Fexternal_debugging_output, Sexternal_debugging_output, 1, 1, 0,
725 doc: /* Write CHARACTER to stderr.
726 You can call print while debugging emacs, and pass it this function
727 to make it write to the debugging output. */)
728 (Lisp_Object character)
730 CHECK_NUMBER (character);
731 putc ((int) XINT (character), stderr);
733 #ifdef WINDOWSNT
734 /* Send the output to a debugger (nothing happens if there isn't one). */
735 if (print_output_debug_flag)
737 char buf[2] = {(char) XINT (character), '\0'};
738 OutputDebugString (buf);
740 #endif
742 return character;
745 /* This function is never called. Its purpose is to prevent
746 print_output_debug_flag from being optimized away. */
748 extern void debug_output_compilation_hack (int) EXTERNALLY_VISIBLE;
749 void
750 debug_output_compilation_hack (int x)
752 print_output_debug_flag = x;
755 #if defined (GNU_LINUX)
757 /* This functionality is not vitally important in general, so we rely on
758 non-portable ability to use stderr as lvalue. */
760 #define WITH_REDIRECT_DEBUGGING_OUTPUT 1
762 static FILE *initial_stderr_stream = NULL;
764 DEFUN ("redirect-debugging-output", Fredirect_debugging_output, Sredirect_debugging_output,
765 1, 2,
766 "FDebug output file: \nP",
767 doc: /* Redirect debugging output (stderr stream) to file FILE.
768 If FILE is nil, reset target to the initial stderr stream.
769 Optional arg APPEND non-nil (interactively, with prefix arg) means
770 append to existing target file. */)
771 (Lisp_Object file, Lisp_Object append)
773 if (initial_stderr_stream != NULL)
775 BLOCK_INPUT;
776 fclose (stderr);
777 UNBLOCK_INPUT;
779 stderr = initial_stderr_stream;
780 initial_stderr_stream = NULL;
782 if (STRINGP (file))
784 file = Fexpand_file_name (file, Qnil);
785 initial_stderr_stream = stderr;
786 stderr = fopen (SSDATA (file), NILP (append) ? "w" : "a");
787 if (stderr == NULL)
789 stderr = initial_stderr_stream;
790 initial_stderr_stream = NULL;
791 report_file_error ("Cannot open debugging output stream",
792 Fcons (file, Qnil));
795 return Qnil;
797 #endif /* GNU_LINUX */
800 /* This is the interface for debugging printing. */
802 void
803 debug_print (Lisp_Object arg)
805 Fprin1 (arg, Qexternal_debugging_output);
806 fprintf (stderr, "\r\n");
809 void safe_debug_print (Lisp_Object) EXTERNALLY_VISIBLE;
810 void
811 safe_debug_print (Lisp_Object arg)
813 int valid = valid_lisp_object_p (arg);
815 if (valid > 0)
816 debug_print (arg);
817 else
818 fprintf (stderr, "#<%s_LISP_OBJECT 0x%08"pI"x>\r\n",
819 !valid ? "INVALID" : "SOME",
820 XHASH (arg));
824 DEFUN ("error-message-string", Ferror_message_string, Serror_message_string,
825 1, 1, 0,
826 doc: /* Convert an error value (ERROR-SYMBOL . DATA) to an error message.
827 See Info anchor `(elisp)Definition of signal' for some details on how this
828 error message is constructed. */)
829 (Lisp_Object obj)
831 struct buffer *old = current_buffer;
832 Lisp_Object value;
833 struct gcpro gcpro1;
835 /* If OBJ is (error STRING), just return STRING.
836 That is not only faster, it also avoids the need to allocate
837 space here when the error is due to memory full. */
838 if (CONSP (obj) && EQ (XCAR (obj), Qerror)
839 && CONSP (XCDR (obj))
840 && STRINGP (XCAR (XCDR (obj)))
841 && NILP (XCDR (XCDR (obj))))
842 return XCAR (XCDR (obj));
844 print_error_message (obj, Vprin1_to_string_buffer, 0, Qnil);
846 set_buffer_internal (XBUFFER (Vprin1_to_string_buffer));
847 value = Fbuffer_string ();
849 GCPRO1 (value);
850 Ferase_buffer ();
851 set_buffer_internal (old);
852 UNGCPRO;
854 return value;
857 /* Print an error message for the error DATA onto Lisp output stream
858 STREAM (suitable for the print functions).
859 CONTEXT is a C string describing the context of the error.
860 CALLER is the Lisp function inside which the error was signaled. */
862 void
863 print_error_message (Lisp_Object data, Lisp_Object stream, const char *context,
864 Lisp_Object caller)
866 Lisp_Object errname, errmsg, file_error, tail;
867 struct gcpro gcpro1;
868 int i;
870 if (context != 0)
871 write_string_1 (context, -1, stream);
873 /* If we know from where the error was signaled, show it in
874 *Messages*. */
875 if (!NILP (caller) && SYMBOLP (caller))
877 Lisp_Object cname = SYMBOL_NAME (caller);
878 char *name = alloca (SBYTES (cname));
879 memcpy (name, SDATA (cname), SBYTES (cname));
880 message_dolog (name, SBYTES (cname), 0, 0);
881 message_dolog (": ", 2, 0, 0);
884 errname = Fcar (data);
886 if (EQ (errname, Qerror))
888 data = Fcdr (data);
889 if (!CONSP (data))
890 data = Qnil;
891 errmsg = Fcar (data);
892 file_error = Qnil;
894 else
896 Lisp_Object error_conditions;
897 errmsg = Fget (errname, Qerror_message);
898 error_conditions = Fget (errname, Qerror_conditions);
899 file_error = Fmemq (Qfile_error, error_conditions);
902 /* Print an error message including the data items. */
904 tail = Fcdr_safe (data);
905 GCPRO1 (tail);
907 /* For file-error, make error message by concatenating
908 all the data items. They are all strings. */
909 if (!NILP (file_error) && CONSP (tail))
910 errmsg = XCAR (tail), tail = XCDR (tail);
912 if (STRINGP (errmsg))
913 Fprinc (errmsg, stream);
914 else
915 write_string_1 ("peculiar error", -1, stream);
917 for (i = 0; CONSP (tail); tail = XCDR (tail), i = 1)
919 Lisp_Object obj;
921 write_string_1 (i ? ", " : ": ", 2, stream);
922 obj = XCAR (tail);
923 if (!NILP (file_error) || EQ (errname, Qend_of_file))
924 Fprinc (obj, stream);
925 else
926 Fprin1 (obj, stream);
929 UNGCPRO;
935 * The buffer should be at least as large as the max string size of the
936 * largest float, printed in the biggest notation. This is undoubtedly
937 * 20d float_output_format, with the negative of the C-constant "HUGE"
938 * from <math.h>.
940 * On the vax the worst case is -1e38 in 20d format which takes 61 bytes.
942 * I assume that IEEE-754 format numbers can take 329 bytes for the worst
943 * case of -1e307 in 20d float_output_format. What is one to do (short of
944 * re-writing _doprnt to be more sane)?
945 * -wsr
946 * Given the above, the buffer must be least FLOAT_TO_STRING_BUFSIZE bytes.
949 void
950 float_to_string (char *buf, double data)
952 char *cp;
953 int width;
955 /* Check for plus infinity in a way that won't lose
956 if there is no plus infinity. */
957 if (data == data / 2 && data > 1.0)
959 strcpy (buf, "1.0e+INF");
960 return;
962 /* Likewise for minus infinity. */
963 if (data == data / 2 && data < -1.0)
965 strcpy (buf, "-1.0e+INF");
966 return;
968 /* Check for NaN in a way that won't fail if there are no NaNs. */
969 if (! (data * 0.0 >= 0.0))
971 /* Prepend "-" if the NaN's sign bit is negative.
972 The sign bit of a double is the bit that is 1 in -0.0. */
973 int i;
974 union { double d; char c[sizeof (double)]; } u_data, u_minus_zero;
975 u_data.d = data;
976 u_minus_zero.d = - 0.0;
977 for (i = 0; i < sizeof (double); i++)
978 if (u_data.c[i] & u_minus_zero.c[i])
980 *buf++ = '-';
981 break;
984 strcpy (buf, "0.0e+NaN");
985 return;
988 if (NILP (Vfloat_output_format)
989 || !STRINGP (Vfloat_output_format))
990 lose:
992 /* Generate the fewest number of digits that represent the
993 floating point value without losing information. */
994 dtoastr (buf, FLOAT_TO_STRING_BUFSIZE - 2, 0, 0, data);
995 /* The decimal point must be printed, or the byte compiler can
996 get confused (Bug#8033). */
997 width = 1;
999 else /* oink oink */
1001 /* Check that the spec we have is fully valid.
1002 This means not only valid for printf,
1003 but meant for floats, and reasonable. */
1004 cp = SSDATA (Vfloat_output_format);
1006 if (cp[0] != '%')
1007 goto lose;
1008 if (cp[1] != '.')
1009 goto lose;
1011 cp += 2;
1013 /* Check the width specification. */
1014 width = -1;
1015 if ('0' <= *cp && *cp <= '9')
1017 width = 0;
1020 width = (width * 10) + (*cp++ - '0');
1021 if (DBL_DIG < width)
1022 goto lose;
1024 while (*cp >= '0' && *cp <= '9');
1026 /* A precision of zero is valid only for %f. */
1027 if (width == 0 && *cp != 'f')
1028 goto lose;
1031 if (*cp != 'e' && *cp != 'f' && *cp != 'g')
1032 goto lose;
1034 if (cp[1] != 0)
1035 goto lose;
1037 sprintf (buf, SSDATA (Vfloat_output_format), data);
1040 /* Make sure there is a decimal point with digit after, or an
1041 exponent, so that the value is readable as a float. But don't do
1042 this with "%.0f"; it's valid for that not to produce a decimal
1043 point. Note that width can be 0 only for %.0f. */
1044 if (width != 0)
1046 for (cp = buf; *cp; cp++)
1047 if ((*cp < '0' || *cp > '9') && *cp != '-')
1048 break;
1050 if (*cp == '.' && cp[1] == 0)
1052 cp[1] = '0';
1053 cp[2] = 0;
1055 else if (*cp == 0)
1057 *cp++ = '.';
1058 *cp++ = '0';
1059 *cp++ = 0;
1065 static void
1066 print (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag)
1068 new_backquote_output = 0;
1070 /* Reset print_number_index and Vprint_number_table only when
1071 the variable Vprint_continuous_numbering is nil. Otherwise,
1072 the values of these variables will be kept between several
1073 print functions. */
1074 if (NILP (Vprint_continuous_numbering)
1075 || NILP (Vprint_number_table))
1077 print_number_index = 0;
1078 Vprint_number_table = Qnil;
1081 /* Construct Vprint_number_table for print-gensym and print-circle. */
1082 if (!NILP (Vprint_gensym) || !NILP (Vprint_circle))
1084 /* Construct Vprint_number_table.
1085 This increments print_number_index for the objects added. */
1086 print_depth = 0;
1087 print_preprocess (obj);
1089 if (HASH_TABLE_P (Vprint_number_table))
1090 { /* Remove unnecessary objects, which appear only once in OBJ;
1091 that is, whose status is Qt.
1092 Maybe a better way to do that is to copy elements to
1093 a new hash table. */
1094 struct Lisp_Hash_Table *h = XHASH_TABLE (Vprint_number_table);
1095 EMACS_INT i;
1097 for (i = 0; i < HASH_TABLE_SIZE (h); ++i)
1098 if (!NILP (HASH_HASH (h, i))
1099 && EQ (HASH_VALUE (h, i), Qt))
1100 Fremhash (HASH_KEY (h, i), Vprint_number_table);
1104 print_depth = 0;
1105 print_object (obj, printcharfun, escapeflag);
1108 #define PRINT_CIRCLE_CANDIDATE_P(obj) \
1109 (STRINGP (obj) || CONSP (obj) \
1110 || (VECTORLIKEP (obj) \
1111 && (VECTORP (obj) || COMPILEDP (obj) \
1112 || CHAR_TABLE_P (obj) || SUB_CHAR_TABLE_P (obj) \
1113 || HASH_TABLE_P (obj) || FONTP (obj))) \
1114 || (! NILP (Vprint_gensym) \
1115 && SYMBOLP (obj) \
1116 && !SYMBOL_INTERNED_P (obj)))
1118 /* Construct Vprint_number_table according to the structure of OBJ.
1119 OBJ itself and all its elements will be added to Vprint_number_table
1120 recursively if it is a list, vector, compiled function, char-table,
1121 string (its text properties will be traced), or a symbol that has
1122 no obarray (this is for the print-gensym feature).
1123 The status fields of Vprint_number_table mean whether each object appears
1124 more than once in OBJ: Qnil at the first time, and Qt after that . */
1125 static void
1126 print_preprocess (Lisp_Object obj)
1128 int i;
1129 EMACS_INT size;
1130 int loop_count = 0;
1131 Lisp_Object halftail;
1133 /* Give up if we go so deep that print_object will get an error. */
1134 /* See similar code in print_object. */
1135 if (print_depth >= PRINT_CIRCLE)
1136 error ("Apparently circular structure being printed");
1138 /* Avoid infinite recursion for circular nested structure
1139 in the case where Vprint_circle is nil. */
1140 if (NILP (Vprint_circle))
1142 for (i = 0; i < print_depth; i++)
1143 if (EQ (obj, being_printed[i]))
1144 return;
1145 being_printed[print_depth] = obj;
1148 print_depth++;
1149 halftail = obj;
1151 loop:
1152 if (PRINT_CIRCLE_CANDIDATE_P (obj))
1154 if (!HASH_TABLE_P (Vprint_number_table))
1156 Lisp_Object args[2];
1157 args[0] = QCtest;
1158 args[1] = Qeq;
1159 Vprint_number_table = Fmake_hash_table (2, args);
1162 /* In case print-circle is nil and print-gensym is t,
1163 add OBJ to Vprint_number_table only when OBJ is a symbol. */
1164 if (! NILP (Vprint_circle) || SYMBOLP (obj))
1166 Lisp_Object num = Fgethash (obj, Vprint_number_table, Qnil);
1167 if (!NILP (num)
1168 /* If Vprint_continuous_numbering is non-nil and OBJ is a gensym,
1169 always print the gensym with a number. This is a special for
1170 the lisp function byte-compile-output-docform. */
1171 || (!NILP (Vprint_continuous_numbering)
1172 && SYMBOLP (obj)
1173 && !SYMBOL_INTERNED_P (obj)))
1174 { /* OBJ appears more than once. Let's remember that. */
1175 if (!INTEGERP (num))
1177 print_number_index++;
1178 /* Negative number indicates it hasn't been printed yet. */
1179 Fputhash (obj, make_number (- print_number_index),
1180 Vprint_number_table);
1182 print_depth--;
1183 return;
1185 else
1186 /* OBJ is not yet recorded. Let's add to the table. */
1187 Fputhash (obj, Qt, Vprint_number_table);
1190 switch (XTYPE (obj))
1192 case Lisp_String:
1193 /* A string may have text properties, which can be circular. */
1194 traverse_intervals_noorder (STRING_INTERVALS (obj),
1195 print_preprocess_string, Qnil);
1196 break;
1198 case Lisp_Cons:
1199 /* Use HALFTAIL and LOOP_COUNT to detect circular lists,
1200 just as in print_object. */
1201 if (loop_count && EQ (obj, halftail))
1202 break;
1203 print_preprocess (XCAR (obj));
1204 obj = XCDR (obj);
1205 loop_count++;
1206 if (!(loop_count & 1))
1207 halftail = XCDR (halftail);
1208 goto loop;
1210 case Lisp_Vectorlike:
1211 size = ASIZE (obj);
1212 if (size & PSEUDOVECTOR_FLAG)
1213 size &= PSEUDOVECTOR_SIZE_MASK;
1214 for (i = 0; i < size; i++)
1215 print_preprocess (XVECTOR (obj)->contents[i]);
1216 if (HASH_TABLE_P (obj))
1217 { /* For hash tables, the key_and_value slot is past
1218 `size' because it needs to be marked specially in case
1219 the table is weak. */
1220 struct Lisp_Hash_Table *h = XHASH_TABLE (obj);
1221 print_preprocess (h->key_and_value);
1223 break;
1225 default:
1226 break;
1229 print_depth--;
1232 static void
1233 print_preprocess_string (INTERVAL interval, Lisp_Object arg)
1235 print_preprocess (interval->plist);
1238 static void print_check_string_charset_prop (INTERVAL interval, Lisp_Object string);
1240 #define PRINT_STRING_NON_CHARSET_FOUND 1
1241 #define PRINT_STRING_UNSAFE_CHARSET_FOUND 2
1243 /* Bitwise or of the above macros. */
1244 static int print_check_string_result;
1246 static void
1247 print_check_string_charset_prop (INTERVAL interval, Lisp_Object string)
1249 Lisp_Object val;
1251 if (NILP (interval->plist)
1252 || (print_check_string_result == (PRINT_STRING_NON_CHARSET_FOUND
1253 | PRINT_STRING_UNSAFE_CHARSET_FOUND)))
1254 return;
1255 for (val = interval->plist; CONSP (val) && ! EQ (XCAR (val), Qcharset);
1256 val = XCDR (XCDR (val)));
1257 if (! CONSP (val))
1259 print_check_string_result |= PRINT_STRING_NON_CHARSET_FOUND;
1260 return;
1262 if (! (print_check_string_result & PRINT_STRING_NON_CHARSET_FOUND))
1264 if (! EQ (val, interval->plist)
1265 || CONSP (XCDR (XCDR (val))))
1266 print_check_string_result |= PRINT_STRING_NON_CHARSET_FOUND;
1268 if (NILP (Vprint_charset_text_property)
1269 || ! (print_check_string_result & PRINT_STRING_UNSAFE_CHARSET_FOUND))
1271 int i, c;
1272 EMACS_INT charpos = interval->position;
1273 EMACS_INT bytepos = string_char_to_byte (string, charpos);
1274 Lisp_Object charset;
1276 charset = XCAR (XCDR (val));
1277 for (i = 0; i < LENGTH (interval); i++)
1279 FETCH_STRING_CHAR_ADVANCE (c, string, charpos, bytepos);
1280 if (! ASCII_CHAR_P (c)
1281 && ! EQ (CHARSET_NAME (CHAR_CHARSET (c)), charset))
1283 print_check_string_result |= PRINT_STRING_UNSAFE_CHARSET_FOUND;
1284 break;
1290 /* The value is (charset . nil). */
1291 static Lisp_Object print_prune_charset_plist;
1293 static Lisp_Object
1294 print_prune_string_charset (Lisp_Object string)
1296 print_check_string_result = 0;
1297 traverse_intervals (STRING_INTERVALS (string), 0,
1298 print_check_string_charset_prop, string);
1299 if (! (print_check_string_result & PRINT_STRING_UNSAFE_CHARSET_FOUND))
1301 string = Fcopy_sequence (string);
1302 if (print_check_string_result & PRINT_STRING_NON_CHARSET_FOUND)
1304 if (NILP (print_prune_charset_plist))
1305 print_prune_charset_plist = Fcons (Qcharset, Qnil);
1306 Fremove_text_properties (make_number (0),
1307 make_number (SCHARS (string)),
1308 print_prune_charset_plist, string);
1310 else
1311 Fset_text_properties (make_number (0), make_number (SCHARS (string)),
1312 Qnil, string);
1314 return string;
1317 static void
1318 print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag)
1320 char buf[max (sizeof "from..to..in " + 2 * INT_STRLEN_BOUND (EMACS_INT),
1321 max (sizeof " . #" + INT_STRLEN_BOUND (printmax_t),
1322 40))];
1324 QUIT;
1326 /* See similar code in print_preprocess. */
1327 if (print_depth >= PRINT_CIRCLE)
1328 error ("Apparently circular structure being printed");
1330 /* Detect circularities and truncate them. */
1331 if (PRINT_CIRCLE_CANDIDATE_P (obj))
1333 if (NILP (Vprint_circle) && NILP (Vprint_gensym))
1335 /* Simple but incomplete way. */
1336 int i;
1337 for (i = 0; i < print_depth; i++)
1338 if (EQ (obj, being_printed[i]))
1340 sprintf (buf, "#%d", i);
1341 strout (buf, -1, -1, printcharfun);
1342 return;
1344 being_printed[print_depth] = obj;
1346 else
1348 /* With the print-circle feature. */
1349 Lisp_Object num = Fgethash (obj, Vprint_number_table, Qnil);
1350 if (INTEGERP (num))
1352 EMACS_INT n = XINT (num);
1353 if (n < 0)
1354 { /* Add a prefix #n= if OBJ has not yet been printed;
1355 that is, its status field is nil. */
1356 sprintf (buf, "#%"pI"d=", -n);
1357 strout (buf, -1, -1, printcharfun);
1358 /* OBJ is going to be printed. Remember that fact. */
1359 Fputhash (obj, make_number (- n), Vprint_number_table);
1361 else
1363 /* Just print #n# if OBJ has already been printed. */
1364 sprintf (buf, "#%"pI"d#", n);
1365 strout (buf, -1, -1, printcharfun);
1366 return;
1372 print_depth++;
1374 switch (XTYPE (obj))
1376 case_Lisp_Int:
1377 sprintf (buf, "%"pI"d", XINT (obj));
1378 strout (buf, -1, -1, printcharfun);
1379 break;
1381 case Lisp_Float:
1383 char pigbuf[FLOAT_TO_STRING_BUFSIZE];
1385 float_to_string (pigbuf, XFLOAT_DATA (obj));
1386 strout (pigbuf, -1, -1, printcharfun);
1388 break;
1390 case Lisp_String:
1391 if (!escapeflag)
1392 print_string (obj, printcharfun);
1393 else
1395 register EMACS_INT i_byte;
1396 struct gcpro gcpro1;
1397 unsigned char *str;
1398 EMACS_INT size_byte;
1399 /* 1 means we must ensure that the next character we output
1400 cannot be taken as part of a hex character escape. */
1401 int need_nonhex = 0;
1402 int multibyte = STRING_MULTIBYTE (obj);
1404 GCPRO1 (obj);
1406 if (! EQ (Vprint_charset_text_property, Qt))
1407 obj = print_prune_string_charset (obj);
1409 if (!NULL_INTERVAL_P (STRING_INTERVALS (obj)))
1411 PRINTCHAR ('#');
1412 PRINTCHAR ('(');
1415 PRINTCHAR ('\"');
1416 str = SDATA (obj);
1417 size_byte = SBYTES (obj);
1419 for (i_byte = 0; i_byte < size_byte;)
1421 /* Here, we must convert each multi-byte form to the
1422 corresponding character code before handing it to PRINTCHAR. */
1423 int len;
1424 int c;
1426 if (multibyte)
1428 c = STRING_CHAR_AND_LENGTH (str + i_byte, len);
1429 i_byte += len;
1431 else
1432 c = str[i_byte++];
1434 QUIT;
1436 if (c == '\n' && print_escape_newlines)
1438 PRINTCHAR ('\\');
1439 PRINTCHAR ('n');
1441 else if (c == '\f' && print_escape_newlines)
1443 PRINTCHAR ('\\');
1444 PRINTCHAR ('f');
1446 else if (multibyte
1447 && (CHAR_BYTE8_P (c)
1448 || (! ASCII_CHAR_P (c) && print_escape_multibyte)))
1450 /* When multibyte is disabled,
1451 print multibyte string chars using hex escapes.
1452 For a char code that could be in a unibyte string,
1453 when found in a multibyte string, always use a hex escape
1454 so it reads back as multibyte. */
1455 char outbuf[50];
1457 if (CHAR_BYTE8_P (c))
1458 sprintf (outbuf, "\\%03o", CHAR_TO_BYTE8 (c));
1459 else
1461 sprintf (outbuf, "\\x%04x", c);
1462 need_nonhex = 1;
1464 strout (outbuf, -1, -1, printcharfun);
1466 else if (! multibyte
1467 && SINGLE_BYTE_CHAR_P (c) && ! ASCII_BYTE_P (c)
1468 && print_escape_nonascii)
1470 /* When printing in a multibyte buffer
1471 or when explicitly requested,
1472 print single-byte non-ASCII string chars
1473 using octal escapes. */
1474 char outbuf[5];
1475 sprintf (outbuf, "\\%03o", c);
1476 strout (outbuf, -1, -1, printcharfun);
1478 else
1480 /* If we just had a hex escape, and this character
1481 could be taken as part of it,
1482 output `\ ' to prevent that. */
1483 if (need_nonhex)
1485 need_nonhex = 0;
1486 if ((c >= 'a' && c <= 'f')
1487 || (c >= 'A' && c <= 'F')
1488 || (c >= '0' && c <= '9'))
1489 strout ("\\ ", -1, -1, printcharfun);
1492 if (c == '\"' || c == '\\')
1493 PRINTCHAR ('\\');
1494 PRINTCHAR (c);
1497 PRINTCHAR ('\"');
1499 if (!NULL_INTERVAL_P (STRING_INTERVALS (obj)))
1501 traverse_intervals (STRING_INTERVALS (obj),
1502 0, print_interval, printcharfun);
1503 PRINTCHAR (')');
1506 UNGCPRO;
1508 break;
1510 case Lisp_Symbol:
1512 register int confusing;
1513 register unsigned char *p = SDATA (SYMBOL_NAME (obj));
1514 register unsigned char *end = p + SBYTES (SYMBOL_NAME (obj));
1515 register int c;
1516 int i, i_byte;
1517 EMACS_INT size_byte;
1518 Lisp_Object name;
1520 name = SYMBOL_NAME (obj);
1522 if (p != end && (*p == '-' || *p == '+')) p++;
1523 if (p == end)
1524 confusing = 0;
1525 /* If symbol name begins with a digit, and ends with a digit,
1526 and contains nothing but digits and `e', it could be treated
1527 as a number. So set CONFUSING.
1529 Symbols that contain periods could also be taken as numbers,
1530 but periods are always escaped, so we don't have to worry
1531 about them here. */
1532 else if (*p >= '0' && *p <= '9'
1533 && end[-1] >= '0' && end[-1] <= '9')
1535 while (p != end && ((*p >= '0' && *p <= '9')
1536 /* Needed for \2e10. */
1537 || *p == 'e' || *p == 'E'))
1538 p++;
1539 confusing = (end == p);
1541 else
1542 confusing = 0;
1544 size_byte = SBYTES (name);
1546 if (! NILP (Vprint_gensym) && !SYMBOL_INTERNED_P (obj))
1548 PRINTCHAR ('#');
1549 PRINTCHAR (':');
1551 else if (size_byte == 0)
1553 PRINTCHAR ('#');
1554 PRINTCHAR ('#');
1555 break;
1558 for (i = 0, i_byte = 0; i_byte < size_byte;)
1560 /* Here, we must convert each multi-byte form to the
1561 corresponding character code before handing it to PRINTCHAR. */
1562 FETCH_STRING_CHAR_ADVANCE (c, name, i, i_byte);
1563 QUIT;
1565 if (escapeflag)
1567 if (c == '\"' || c == '\\' || c == '\''
1568 || c == ';' || c == '#' || c == '(' || c == ')'
1569 || c == ',' || c == '.' || c == '`'
1570 || c == '[' || c == ']' || c == '?' || c <= 040
1571 || confusing)
1572 PRINTCHAR ('\\'), confusing = 0;
1574 PRINTCHAR (c);
1577 break;
1579 case Lisp_Cons:
1580 /* If deeper than spec'd depth, print placeholder. */
1581 if (INTEGERP (Vprint_level)
1582 && print_depth > XINT (Vprint_level))
1583 strout ("...", -1, -1, printcharfun);
1584 else if (print_quoted && CONSP (XCDR (obj)) && NILP (XCDR (XCDR (obj)))
1585 && (EQ (XCAR (obj), Qquote)))
1587 PRINTCHAR ('\'');
1588 print_object (XCAR (XCDR (obj)), printcharfun, escapeflag);
1590 else if (print_quoted && CONSP (XCDR (obj)) && NILP (XCDR (XCDR (obj)))
1591 && (EQ (XCAR (obj), Qfunction)))
1593 PRINTCHAR ('#');
1594 PRINTCHAR ('\'');
1595 print_object (XCAR (XCDR (obj)), printcharfun, escapeflag);
1597 else if (print_quoted && CONSP (XCDR (obj)) && NILP (XCDR (XCDR (obj)))
1598 && ((EQ (XCAR (obj), Qbackquote))))
1600 print_object (XCAR (obj), printcharfun, 0);
1601 new_backquote_output++;
1602 print_object (XCAR (XCDR (obj)), printcharfun, escapeflag);
1603 new_backquote_output--;
1605 else if (print_quoted && CONSP (XCDR (obj)) && NILP (XCDR (XCDR (obj)))
1606 && new_backquote_output
1607 && ((EQ (XCAR (obj), Qbackquote)
1608 || EQ (XCAR (obj), Qcomma)
1609 || EQ (XCAR (obj), Qcomma_at)
1610 || EQ (XCAR (obj), Qcomma_dot))))
1612 print_object (XCAR (obj), printcharfun, 0);
1613 new_backquote_output--;
1614 print_object (XCAR (XCDR (obj)), printcharfun, escapeflag);
1615 new_backquote_output++;
1617 else
1619 PRINTCHAR ('(');
1622 printmax_t i, print_length;
1623 Lisp_Object halftail = obj;
1625 /* Negative values of print-length are invalid in CL.
1626 Treat them like nil, as CMUCL does. */
1627 if (NATNUMP (Vprint_length))
1628 print_length = XFASTINT (Vprint_length);
1629 else
1630 print_length = TYPE_MAXIMUM (printmax_t);
1632 i = 0;
1633 while (CONSP (obj))
1635 /* Detect circular list. */
1636 if (NILP (Vprint_circle))
1638 /* Simple but incomplete way. */
1639 if (i != 0 && EQ (obj, halftail))
1641 sprintf (buf, " . #%"pMd, i / 2);
1642 strout (buf, -1, -1, printcharfun);
1643 goto end_of_list;
1646 else
1648 /* With the print-circle feature. */
1649 if (i != 0)
1651 Lisp_Object num = Fgethash (obj, Vprint_number_table, Qnil);
1652 if (INTEGERP (num))
1654 strout (" . ", 3, 3, printcharfun);
1655 print_object (obj, printcharfun, escapeflag);
1656 goto end_of_list;
1661 if (i)
1662 PRINTCHAR (' ');
1664 if (print_length <= i)
1666 strout ("...", 3, 3, printcharfun);
1667 goto end_of_list;
1670 i++;
1671 print_object (XCAR (obj), printcharfun, escapeflag);
1673 obj = XCDR (obj);
1674 if (!(i & 1))
1675 halftail = XCDR (halftail);
1679 /* OBJ non-nil here means it's the end of a dotted list. */
1680 if (!NILP (obj))
1682 strout (" . ", 3, 3, printcharfun);
1683 print_object (obj, printcharfun, escapeflag);
1686 end_of_list:
1687 PRINTCHAR (')');
1689 break;
1691 case Lisp_Vectorlike:
1692 if (PROCESSP (obj))
1694 if (escapeflag)
1696 strout ("#<process ", -1, -1, printcharfun);
1697 print_string (XPROCESS (obj)->name, printcharfun);
1698 PRINTCHAR ('>');
1700 else
1701 print_string (XPROCESS (obj)->name, printcharfun);
1703 else if (BOOL_VECTOR_P (obj))
1705 ptrdiff_t i;
1706 register unsigned char c;
1707 struct gcpro gcpro1;
1708 EMACS_INT size_in_chars
1709 = ((XBOOL_VECTOR (obj)->size + BOOL_VECTOR_BITS_PER_CHAR - 1)
1710 / BOOL_VECTOR_BITS_PER_CHAR);
1712 GCPRO1 (obj);
1714 PRINTCHAR ('#');
1715 PRINTCHAR ('&');
1716 sprintf (buf, "%"pI"d", XBOOL_VECTOR (obj)->size);
1717 strout (buf, -1, -1, printcharfun);
1718 PRINTCHAR ('\"');
1720 /* Don't print more characters than the specified maximum.
1721 Negative values of print-length are invalid. Treat them
1722 like a print-length of nil. */
1723 if (NATNUMP (Vprint_length)
1724 && XFASTINT (Vprint_length) < size_in_chars)
1725 size_in_chars = XFASTINT (Vprint_length);
1727 for (i = 0; i < size_in_chars; i++)
1729 QUIT;
1730 c = XBOOL_VECTOR (obj)->data[i];
1731 if (c == '\n' && print_escape_newlines)
1733 PRINTCHAR ('\\');
1734 PRINTCHAR ('n');
1736 else if (c == '\f' && print_escape_newlines)
1738 PRINTCHAR ('\\');
1739 PRINTCHAR ('f');
1741 else if (c > '\177')
1743 /* Use octal escapes to avoid encoding issues. */
1744 PRINTCHAR ('\\');
1745 PRINTCHAR ('0' + ((c >> 6) & 3));
1746 PRINTCHAR ('0' + ((c >> 3) & 7));
1747 PRINTCHAR ('0' + (c & 7));
1749 else
1751 if (c == '\"' || c == '\\')
1752 PRINTCHAR ('\\');
1753 PRINTCHAR (c);
1756 PRINTCHAR ('\"');
1758 UNGCPRO;
1760 else if (SUBRP (obj))
1762 strout ("#<subr ", -1, -1, printcharfun);
1763 strout (XSUBR (obj)->symbol_name, -1, -1, printcharfun);
1764 PRINTCHAR ('>');
1766 else if (WINDOWP (obj))
1768 strout ("#<window ", -1, -1, printcharfun);
1769 sprintf (buf, "%"pI"d", XFASTINT (XWINDOW (obj)->sequence_number));
1770 strout (buf, -1, -1, printcharfun);
1771 if (!NILP (XWINDOW (obj)->buffer))
1773 strout (" on ", -1, -1, printcharfun);
1774 print_string (BVAR (XBUFFER (XWINDOW (obj)->buffer), name), printcharfun);
1776 PRINTCHAR ('>');
1778 else if (TERMINALP (obj))
1780 struct terminal *t = XTERMINAL (obj);
1781 strout ("#<terminal ", -1, -1, printcharfun);
1782 sprintf (buf, "%d", t->id);
1783 strout (buf, -1, -1, printcharfun);
1784 if (t->name)
1786 strout (" on ", -1, -1, printcharfun);
1787 strout (t->name, -1, -1, printcharfun);
1789 PRINTCHAR ('>');
1791 else if (HASH_TABLE_P (obj))
1793 struct Lisp_Hash_Table *h = XHASH_TABLE (obj);
1794 int i;
1795 EMACS_INT real_size, size;
1796 #if 0
1797 strout ("#<hash-table", -1, -1, printcharfun);
1798 if (SYMBOLP (h->test))
1800 PRINTCHAR (' ');
1801 PRINTCHAR ('\'');
1802 strout (SDATA (SYMBOL_NAME (h->test)), -1, -1, printcharfun);
1803 PRINTCHAR (' ');
1804 strout (SDATA (SYMBOL_NAME (h->weak)), -1, -1, printcharfun);
1805 PRINTCHAR (' ');
1806 sprintf (buf, "%"pI"d/%"pI"d", h->count, ASIZE (h->next));
1807 strout (buf, -1, -1, printcharfun);
1809 sprintf (buf, " %p", h);
1810 strout (buf, -1, -1, printcharfun);
1811 PRINTCHAR ('>');
1812 #endif
1813 /* Implement a readable output, e.g.:
1814 #s(hash-table size 2 test equal data (k1 v1 k2 v2)) */
1815 /* Always print the size. */
1816 sprintf (buf, "#s(hash-table size %"pI"d", ASIZE (h->next));
1817 strout (buf, -1, -1, printcharfun);
1819 if (!NILP (h->test))
1821 strout (" test ", -1, -1, printcharfun);
1822 print_object (h->test, printcharfun, escapeflag);
1825 if (!NILP (h->weak))
1827 strout (" weakness ", -1, -1, printcharfun);
1828 print_object (h->weak, printcharfun, escapeflag);
1831 if (!NILP (h->rehash_size))
1833 strout (" rehash-size ", -1, -1, printcharfun);
1834 print_object (h->rehash_size, printcharfun, escapeflag);
1837 if (!NILP (h->rehash_threshold))
1839 strout (" rehash-threshold ", -1, -1, printcharfun);
1840 print_object (h->rehash_threshold, printcharfun, escapeflag);
1843 strout (" data ", -1, -1, printcharfun);
1845 /* Print the data here as a plist. */
1846 real_size = HASH_TABLE_SIZE (h);
1847 size = real_size;
1849 /* Don't print more elements than the specified maximum. */
1850 if (NATNUMP (Vprint_length)
1851 && XFASTINT (Vprint_length) < size)
1852 size = XFASTINT (Vprint_length);
1854 PRINTCHAR ('(');
1855 for (i = 0; i < size; i++)
1856 if (!NILP (HASH_HASH (h, i)))
1858 if (i) PRINTCHAR (' ');
1859 print_object (HASH_KEY (h, i), printcharfun, escapeflag);
1860 PRINTCHAR (' ');
1861 print_object (HASH_VALUE (h, i), printcharfun, escapeflag);
1864 if (size < real_size)
1865 strout (" ...", 4, 4, printcharfun);
1867 PRINTCHAR (')');
1868 PRINTCHAR (')');
1871 else if (BUFFERP (obj))
1873 if (NILP (BVAR (XBUFFER (obj), name)))
1874 strout ("#<killed buffer>", -1, -1, printcharfun);
1875 else if (escapeflag)
1877 strout ("#<buffer ", -1, -1, printcharfun);
1878 print_string (BVAR (XBUFFER (obj), name), printcharfun);
1879 PRINTCHAR ('>');
1881 else
1882 print_string (BVAR (XBUFFER (obj), name), printcharfun);
1884 else if (WINDOW_CONFIGURATIONP (obj))
1886 strout ("#<window-configuration>", -1, -1, printcharfun);
1888 else if (FRAMEP (obj))
1890 strout ((FRAME_LIVE_P (XFRAME (obj))
1891 ? "#<frame " : "#<dead frame "),
1892 -1, -1, printcharfun);
1893 print_string (XFRAME (obj)->name, printcharfun);
1894 sprintf (buf, " %p", XFRAME (obj));
1895 strout (buf, -1, -1, printcharfun);
1896 PRINTCHAR ('>');
1898 else if (FONTP (obj))
1900 EMACS_INT i;
1902 if (! FONT_OBJECT_P (obj))
1904 if (FONT_SPEC_P (obj))
1905 strout ("#<font-spec", -1, -1, printcharfun);
1906 else
1907 strout ("#<font-entity", -1, -1, printcharfun);
1908 for (i = 0; i < FONT_SPEC_MAX; i++)
1910 PRINTCHAR (' ');
1911 if (i < FONT_WEIGHT_INDEX || i > FONT_WIDTH_INDEX)
1912 print_object (AREF (obj, i), printcharfun, escapeflag);
1913 else
1914 print_object (font_style_symbolic (obj, i, 0),
1915 printcharfun, escapeflag);
1918 else
1920 strout ("#<font-object ", -1, -1, printcharfun);
1921 print_object (AREF (obj, FONT_NAME_INDEX), printcharfun,
1922 escapeflag);
1924 PRINTCHAR ('>');
1926 else
1928 EMACS_INT size = ASIZE (obj);
1929 if (COMPILEDP (obj))
1931 PRINTCHAR ('#');
1932 size &= PSEUDOVECTOR_SIZE_MASK;
1934 if (CHAR_TABLE_P (obj) || SUB_CHAR_TABLE_P (obj))
1936 /* We print a char-table as if it were a vector,
1937 lumping the parent and default slots in with the
1938 character slots. But we add #^ as a prefix. */
1940 /* Make each lowest sub_char_table start a new line.
1941 Otherwise we'll make a line extremely long, which
1942 results in slow redisplay. */
1943 if (SUB_CHAR_TABLE_P (obj)
1944 && XINT (XSUB_CHAR_TABLE (obj)->depth) == 3)
1945 PRINTCHAR ('\n');
1946 PRINTCHAR ('#');
1947 PRINTCHAR ('^');
1948 if (SUB_CHAR_TABLE_P (obj))
1949 PRINTCHAR ('^');
1950 size &= PSEUDOVECTOR_SIZE_MASK;
1952 if (size & PSEUDOVECTOR_FLAG)
1953 goto badtype;
1955 PRINTCHAR ('[');
1957 register int i;
1958 register Lisp_Object tem;
1959 EMACS_INT real_size = size;
1961 /* Don't print more elements than the specified maximum. */
1962 if (NATNUMP (Vprint_length)
1963 && XFASTINT (Vprint_length) < size)
1964 size = XFASTINT (Vprint_length);
1966 for (i = 0; i < size; i++)
1968 if (i) PRINTCHAR (' ');
1969 tem = XVECTOR (obj)->contents[i];
1970 print_object (tem, printcharfun, escapeflag);
1972 if (size < real_size)
1973 strout (" ...", 4, 4, printcharfun);
1975 PRINTCHAR (']');
1977 break;
1979 case Lisp_Misc:
1980 switch (XMISCTYPE (obj))
1982 case Lisp_Misc_Marker:
1983 strout ("#<marker ", -1, -1, printcharfun);
1984 /* Do you think this is necessary? */
1985 if (XMARKER (obj)->insertion_type != 0)
1986 strout ("(moves after insertion) ", -1, -1, printcharfun);
1987 if (! XMARKER (obj)->buffer)
1988 strout ("in no buffer", -1, -1, printcharfun);
1989 else
1991 sprintf (buf, "at %"pI"d", marker_position (obj));
1992 strout (buf, -1, -1, printcharfun);
1993 strout (" in ", -1, -1, printcharfun);
1994 print_string (BVAR (XMARKER (obj)->buffer, name), printcharfun);
1996 PRINTCHAR ('>');
1997 break;
1999 case Lisp_Misc_Overlay:
2000 strout ("#<overlay ", -1, -1, printcharfun);
2001 if (! XMARKER (OVERLAY_START (obj))->buffer)
2002 strout ("in no buffer", -1, -1, printcharfun);
2003 else
2005 sprintf (buf, "from %"pI"d to %"pI"d in ",
2006 marker_position (OVERLAY_START (obj)),
2007 marker_position (OVERLAY_END (obj)));
2008 strout (buf, -1, -1, printcharfun);
2009 print_string (BVAR (XMARKER (OVERLAY_START (obj))->buffer, name),
2010 printcharfun);
2012 PRINTCHAR ('>');
2013 break;
2015 /* Remaining cases shouldn't happen in normal usage, but let's print
2016 them anyway for the benefit of the debugger. */
2017 case Lisp_Misc_Free:
2018 strout ("#<misc free cell>", -1, -1, printcharfun);
2019 break;
2021 case Lisp_Misc_Save_Value:
2022 strout ("#<save_value ", -1, -1, printcharfun);
2023 sprintf (buf, "ptr=%p int=%"pD"d",
2024 XSAVE_VALUE (obj)->pointer,
2025 XSAVE_VALUE (obj)->integer);
2026 strout (buf, -1, -1, printcharfun);
2027 PRINTCHAR ('>');
2028 break;
2030 default:
2031 goto badtype;
2033 break;
2035 default:
2036 badtype:
2038 /* We're in trouble if this happens!
2039 Probably should just abort () */
2040 strout ("#<EMACS BUG: INVALID DATATYPE ", -1, -1, printcharfun);
2041 if (MISCP (obj))
2042 sprintf (buf, "(MISC 0x%04x)", (int) XMISCTYPE (obj));
2043 else if (VECTORLIKEP (obj))
2044 sprintf (buf, "(PVEC 0x%08"pI"x)", ASIZE (obj));
2045 else
2046 sprintf (buf, "(0x%02x)", (int) XTYPE (obj));
2047 strout (buf, -1, -1, printcharfun);
2048 strout (" Save your buffers immediately and please report this bug>",
2049 -1, -1, printcharfun);
2053 print_depth--;
2057 /* Print a description of INTERVAL using PRINTCHARFUN.
2058 This is part of printing a string that has text properties. */
2060 void
2061 print_interval (INTERVAL interval, Lisp_Object printcharfun)
2063 if (NILP (interval->plist))
2064 return;
2065 PRINTCHAR (' ');
2066 print_object (make_number (interval->position), printcharfun, 1);
2067 PRINTCHAR (' ');
2068 print_object (make_number (interval->position + LENGTH (interval)),
2069 printcharfun, 1);
2070 PRINTCHAR (' ');
2071 print_object (interval->plist, printcharfun, 1);
2075 void
2076 syms_of_print (void)
2078 DEFSYM (Qtemp_buffer_setup_hook, "temp-buffer-setup-hook");
2080 DEFVAR_LISP ("standard-output", Vstandard_output,
2081 doc: /* Output stream `print' uses by default for outputting a character.
2082 This may be any function of one argument.
2083 It may also be a buffer (output is inserted before point)
2084 or a marker (output is inserted and the marker is advanced)
2085 or the symbol t (output appears in the echo area). */);
2086 Vstandard_output = Qt;
2087 DEFSYM (Qstandard_output, "standard-output");
2089 DEFVAR_LISP ("float-output-format", Vfloat_output_format,
2090 doc: /* The format descriptor string used to print floats.
2091 This is a %-spec like those accepted by `printf' in C,
2092 but with some restrictions. It must start with the two characters `%.'.
2093 After that comes an integer precision specification,
2094 and then a letter which controls the format.
2095 The letters allowed are `e', `f' and `g'.
2096 Use `e' for exponential notation \"DIG.DIGITSeEXPT\"
2097 Use `f' for decimal point notation \"DIGITS.DIGITS\".
2098 Use `g' to choose the shorter of those two formats for the number at hand.
2099 The precision in any of these cases is the number of digits following
2100 the decimal point. With `f', a precision of 0 means to omit the
2101 decimal point. 0 is not allowed with `e' or `g'.
2103 A value of nil means to use the shortest notation
2104 that represents the number without losing information. */);
2105 Vfloat_output_format = Qnil;
2106 DEFSYM (Qfloat_output_format, "float-output-format");
2108 DEFVAR_LISP ("print-length", Vprint_length,
2109 doc: /* Maximum length of list to print before abbreviating.
2110 A value of nil means no limit. See also `eval-expression-print-length'. */);
2111 Vprint_length = Qnil;
2113 DEFVAR_LISP ("print-level", Vprint_level,
2114 doc: /* Maximum depth of list nesting to print before abbreviating.
2115 A value of nil means no limit. See also `eval-expression-print-level'. */);
2116 Vprint_level = Qnil;
2118 DEFVAR_BOOL ("print-escape-newlines", print_escape_newlines,
2119 doc: /* Non-nil means print newlines in strings as `\\n'.
2120 Also print formfeeds as `\\f'. */);
2121 print_escape_newlines = 0;
2123 DEFVAR_BOOL ("print-escape-nonascii", print_escape_nonascii,
2124 doc: /* Non-nil means print unibyte non-ASCII chars in strings as \\OOO.
2125 \(OOO is the octal representation of the character code.)
2126 Only single-byte characters are affected, and only in `prin1'.
2127 When the output goes in a multibyte buffer, this feature is
2128 enabled regardless of the value of the variable. */);
2129 print_escape_nonascii = 0;
2131 DEFVAR_BOOL ("print-escape-multibyte", print_escape_multibyte,
2132 doc: /* Non-nil means print multibyte characters in strings as \\xXXXX.
2133 \(XXXX is the hex representation of the character code.)
2134 This affects only `prin1'. */);
2135 print_escape_multibyte = 0;
2137 DEFVAR_BOOL ("print-quoted", print_quoted,
2138 doc: /* Non-nil means print quoted forms with reader syntax.
2139 I.e., (quote foo) prints as 'foo, (function foo) as #'foo. */);
2140 print_quoted = 0;
2142 DEFVAR_LISP ("print-gensym", Vprint_gensym,
2143 doc: /* Non-nil means print uninterned symbols so they will read as uninterned.
2144 I.e., the value of (make-symbol \"foobar\") prints as #:foobar.
2145 When the uninterned symbol appears within a recursive data structure,
2146 and the symbol appears more than once, in addition use the #N# and #N=
2147 constructs as needed, so that multiple references to the same symbol are
2148 shared once again when the text is read back. */);
2149 Vprint_gensym = Qnil;
2151 DEFVAR_LISP ("print-circle", Vprint_circle,
2152 doc: /* *Non-nil means print recursive structures using #N= and #N# syntax.
2153 If nil, printing proceeds recursively and may lead to
2154 `max-lisp-eval-depth' being exceeded or an error may occur:
2155 \"Apparently circular structure being printed.\" Also see
2156 `print-length' and `print-level'.
2157 If non-nil, shared substructures anywhere in the structure are printed
2158 with `#N=' before the first occurrence (in the order of the print
2159 representation) and `#N#' in place of each subsequent occurrence,
2160 where N is a positive decimal integer. */);
2161 Vprint_circle = Qnil;
2163 DEFVAR_LISP ("print-continuous-numbering", Vprint_continuous_numbering,
2164 doc: /* *Non-nil means number continuously across print calls.
2165 This affects the numbers printed for #N= labels and #M# references.
2166 See also `print-circle', `print-gensym', and `print-number-table'.
2167 This variable should not be set with `setq'; bind it with a `let' instead. */);
2168 Vprint_continuous_numbering = Qnil;
2170 DEFVAR_LISP ("print-number-table", Vprint_number_table,
2171 doc: /* A vector used internally to produce `#N=' labels and `#N#' references.
2172 The Lisp printer uses this vector to detect Lisp objects referenced more
2173 than once.
2175 When you bind `print-continuous-numbering' to t, you should probably
2176 also bind `print-number-table' to nil. This ensures that the value of
2177 `print-number-table' can be garbage-collected once the printing is
2178 done. If all elements of `print-number-table' are nil, it means that
2179 the printing done so far has not found any shared structure or objects
2180 that need to be recorded in the table. */);
2181 Vprint_number_table = Qnil;
2183 DEFVAR_LISP ("print-charset-text-property", Vprint_charset_text_property,
2184 doc: /* A flag to control printing of `charset' text property on printing a string.
2185 The value must be nil, t, or `default'.
2187 If the value is nil, don't print the text property `charset'.
2189 If the value is t, always print the text property `charset'.
2191 If the value is `default', print the text property `charset' only when
2192 the value is different from what is guessed in the current charset
2193 priorities. */);
2194 Vprint_charset_text_property = Qdefault;
2196 /* prin1_to_string_buffer initialized in init_buffer_once in buffer.c */
2197 staticpro (&Vprin1_to_string_buffer);
2199 defsubr (&Sprin1);
2200 defsubr (&Sprin1_to_string);
2201 defsubr (&Serror_message_string);
2202 defsubr (&Sprinc);
2203 defsubr (&Sprint);
2204 defsubr (&Sterpri);
2205 defsubr (&Swrite_char);
2206 defsubr (&Sexternal_debugging_output);
2207 #ifdef WITH_REDIRECT_DEBUGGING_OUTPUT
2208 defsubr (&Sredirect_debugging_output);
2209 #endif
2211 DEFSYM (Qexternal_debugging_output, "external-debugging-output");
2212 DEFSYM (Qprint_escape_newlines, "print-escape-newlines");
2213 DEFSYM (Qprint_escape_multibyte, "print-escape-multibyte");
2214 DEFSYM (Qprint_escape_nonascii, "print-escape-nonascii");
2216 print_prune_charset_plist = Qnil;
2217 staticpro (&print_prune_charset_plist);