ifdef guarding of xwidget code. not complete
[emacs.git] / src / print.c
blob15650d1bb6e20ee81356a3e5f2aaad08571c9e43
1 /* Lisp object printing and output streams.
3 Copyright (C) 1985-1986, 1988, 1993-1995, 1997-2011
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"
39 #ifdef HAVE_XWIDGETS
40 #include "xwidget.h"
41 #endif
42 Lisp_Object Qstandard_output;
44 static Lisp_Object Qtemp_buffer_setup_hook;
46 /* These are used to print like we read. */
48 static Lisp_Object Qfloat_output_format;
50 #include <math.h>
51 #include <float.h>
52 #include <ftoastr.h>
54 /* Default to values appropriate for IEEE floating point. */
55 #ifndef DBL_DIG
56 #define DBL_DIG 15
57 #endif
59 /* Avoid actual stack overflow in print. */
60 static int print_depth;
62 /* Level of nesting inside outputting backquote in new style. */
63 static int new_backquote_output;
65 /* Detect most circularities to print finite output. */
66 #define PRINT_CIRCLE 200
67 static Lisp_Object being_printed[PRINT_CIRCLE];
69 /* When printing into a buffer, first we put the text in this
70 block, then insert it all at once. */
71 static char *print_buffer;
73 /* Size allocated in print_buffer. */
74 static EMACS_INT print_buffer_size;
75 /* Chars stored in print_buffer. */
76 static EMACS_INT print_buffer_pos;
77 /* Bytes stored in print_buffer. */
78 static EMACS_INT print_buffer_pos_byte;
80 Lisp_Object Qprint_escape_newlines;
81 static Lisp_Object Qprint_escape_multibyte, Qprint_escape_nonascii;
83 /* Vprint_number_table is a table, that keeps objects that are going to
84 be printed, to allow use of #n= and #n# to express sharing.
85 For any given object, the table can give the following values:
86 t the object will be printed only once.
87 -N the object will be printed several times and will take number N.
88 N the object has been printed so we can refer to it as #N#.
89 print_number_index holds the largest N already used.
90 N has to be striclty larger than 0 since we need to distinguish -N. */
91 static int print_number_index;
92 static void print_interval (INTERVAL interval, Lisp_Object printcharfun);
94 /* GDB resets this to zero on W32 to disable OutputDebugString calls. */
95 int print_output_debug_flag EXTERNALLY_VISIBLE = 1;
98 /* Low level output routines for characters and strings */
100 /* Lisp functions to do output using a stream
101 must have the stream in a variable called printcharfun
102 and must start with PRINTPREPARE, end with PRINTFINISH,
103 and use PRINTDECLARE to declare common variables.
104 Use PRINTCHAR to output one character,
105 or call strout to output a block of characters. */
107 #define PRINTDECLARE \
108 struct buffer *old = current_buffer; \
109 EMACS_INT old_point = -1, start_point = -1; \
110 EMACS_INT old_point_byte = -1, start_point_byte = -1; \
111 int specpdl_count = SPECPDL_INDEX (); \
112 int free_print_buffer = 0; \
113 int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters)); \
114 Lisp_Object original
116 #define PRINTPREPARE \
117 original = printcharfun; \
118 if (NILP (printcharfun)) printcharfun = Qt; \
119 if (BUFFERP (printcharfun)) \
121 if (XBUFFER (printcharfun) != current_buffer) \
122 Fset_buffer (printcharfun); \
123 printcharfun = Qnil; \
125 if (MARKERP (printcharfun)) \
127 EMACS_INT marker_pos; \
128 if (! XMARKER (printcharfun)->buffer) \
129 error ("Marker does not point anywhere"); \
130 if (XMARKER (printcharfun)->buffer != current_buffer) \
131 set_buffer_internal (XMARKER (printcharfun)->buffer); \
132 marker_pos = marker_position (printcharfun); \
133 if (marker_pos < BEGV || marker_pos > ZV) \
134 error ("Marker is outside the accessible part of the buffer"); \
135 old_point = PT; \
136 old_point_byte = PT_BYTE; \
137 SET_PT_BOTH (marker_pos, \
138 marker_byte_position (printcharfun)); \
139 start_point = PT; \
140 start_point_byte = PT_BYTE; \
141 printcharfun = Qnil; \
143 if (NILP (printcharfun)) \
145 Lisp_Object string; \
146 if (NILP (BVAR (current_buffer, enable_multibyte_characters)) \
147 && ! print_escape_multibyte) \
148 specbind (Qprint_escape_multibyte, Qt); \
149 if (! NILP (BVAR (current_buffer, enable_multibyte_characters)) \
150 && ! print_escape_nonascii) \
151 specbind (Qprint_escape_nonascii, Qt); \
152 if (print_buffer != 0) \
154 string = make_string_from_bytes (print_buffer, \
155 print_buffer_pos, \
156 print_buffer_pos_byte); \
157 record_unwind_protect (print_unwind, string); \
159 else \
161 ptrdiff_t new_size = 1000; \
162 print_buffer = (char *) xmalloc (new_size); \
163 print_buffer_size = new_size; \
164 free_print_buffer = 1; \
166 print_buffer_pos = 0; \
167 print_buffer_pos_byte = 0; \
169 if (EQ (printcharfun, Qt) && ! noninteractive) \
170 setup_echo_area_for_printing (multibyte);
172 #define PRINTFINISH \
173 if (NILP (printcharfun)) \
175 if (print_buffer_pos != print_buffer_pos_byte \
176 && NILP (BVAR (current_buffer, enable_multibyte_characters))) \
178 unsigned char *temp \
179 = (unsigned char *) alloca (print_buffer_pos + 1); \
180 copy_text ((unsigned char *) print_buffer, temp, \
181 print_buffer_pos_byte, 1, 0); \
182 insert_1_both ((char *) temp, print_buffer_pos, \
183 print_buffer_pos, 0, 1, 0); \
185 else \
186 insert_1_both (print_buffer, print_buffer_pos, \
187 print_buffer_pos_byte, 0, 1, 0); \
188 signal_after_change (PT - print_buffer_pos, 0, print_buffer_pos);\
190 if (free_print_buffer) \
192 xfree (print_buffer); \
193 print_buffer = 0; \
195 unbind_to (specpdl_count, Qnil); \
196 if (MARKERP (original)) \
197 set_marker_both (original, Qnil, PT, PT_BYTE); \
198 if (old_point >= 0) \
199 SET_PT_BOTH (old_point + (old_point >= start_point \
200 ? PT - start_point : 0), \
201 old_point_byte + (old_point_byte >= start_point_byte \
202 ? PT_BYTE - start_point_byte : 0)); \
203 if (old != current_buffer) \
204 set_buffer_internal (old);
206 #define PRINTCHAR(ch) printchar (ch, printcharfun)
208 /* This is used to restore the saved contents of print_buffer
209 when there is a recursive call to print. */
211 static Lisp_Object
212 print_unwind (Lisp_Object saved_text)
214 memcpy (print_buffer, SDATA (saved_text), SCHARS (saved_text));
215 return Qnil;
219 /* Print character CH using method FUN. FUN nil means print to
220 print_buffer. FUN t means print to echo area or stdout if
221 non-interactive. If FUN is neither nil nor t, call FUN with CH as
222 argument. */
224 static void
225 printchar (unsigned int ch, Lisp_Object fun)
227 if (!NILP (fun) && !EQ (fun, Qt))
228 call1 (fun, make_number (ch));
229 else
231 unsigned char str[MAX_MULTIBYTE_LENGTH];
232 int len = CHAR_STRING (ch, str);
234 QUIT;
236 if (NILP (fun))
238 if (print_buffer_size - len <= print_buffer_pos_byte)
240 ptrdiff_t new_size;
241 if (STRING_BYTES_BOUND / 2 < print_buffer_size)
242 string_overflow ();
243 new_size = print_buffer_size * 2;
244 print_buffer = (char *) xrealloc (print_buffer, new_size);
245 print_buffer_size = new_size;
247 memcpy (print_buffer + print_buffer_pos_byte, str, len);
248 print_buffer_pos += 1;
249 print_buffer_pos_byte += len;
251 else if (noninteractive)
253 fwrite (str, 1, len, stdout);
254 noninteractive_need_newline = 1;
256 else
258 int multibyte_p
259 = !NILP (BVAR (current_buffer, enable_multibyte_characters));
261 setup_echo_area_for_printing (multibyte_p);
262 insert_char (ch);
263 message_dolog ((char *) str, len, 0, multibyte_p);
269 /* Output SIZE characters, SIZE_BYTE bytes from string PTR using
270 method PRINTCHARFUN. If SIZE < 0, use the string length of PTR for
271 both SIZE and SIZE_BYTE. PRINTCHARFUN nil means output to
272 print_buffer. PRINTCHARFUN t means output to the echo area or to
273 stdout if non-interactive. If neither nil nor t, call Lisp
274 function PRINTCHARFUN for each character printed. MULTIBYTE
275 non-zero means PTR contains multibyte characters.
277 In the case where PRINTCHARFUN is nil, it is safe for PTR to point
278 to data in a Lisp string. Otherwise that is not safe. */
280 static void
281 strout (const char *ptr, EMACS_INT size, EMACS_INT size_byte,
282 Lisp_Object printcharfun)
284 if (size < 0)
285 size_byte = size = strlen (ptr);
287 if (NILP (printcharfun))
289 if (print_buffer_size - size_byte < print_buffer_pos_byte)
291 ptrdiff_t new_size;
292 if (STRING_BYTES_BOUND / 2 - size_byte < print_buffer_size)
293 string_overflow ();
294 new_size = print_buffer_size * 2 + size_byte;
295 print_buffer = (char *) xrealloc (print_buffer, new_size);
296 print_buffer_size = new_size;
298 memcpy (print_buffer + print_buffer_pos_byte, ptr, size_byte);
299 print_buffer_pos += size;
300 print_buffer_pos_byte += size_byte;
302 else if (noninteractive && EQ (printcharfun, Qt))
304 fwrite (ptr, 1, size_byte, stdout);
305 noninteractive_need_newline = 1;
307 else if (EQ (printcharfun, Qt))
309 /* Output to echo area. We're trying to avoid a little overhead
310 here, that's the reason we don't call printchar to do the
311 job. */
312 int i;
313 int multibyte_p
314 = !NILP (BVAR (current_buffer, enable_multibyte_characters));
316 setup_echo_area_for_printing (multibyte_p);
317 message_dolog (ptr, size_byte, 0, multibyte_p);
319 if (size == size_byte)
321 for (i = 0; i < size; ++i)
322 insert_char ((unsigned char) *ptr++);
324 else
326 int len;
327 for (i = 0; i < size_byte; i += len)
329 int ch = STRING_CHAR_AND_LENGTH ((const unsigned char *) ptr + i,
330 len);
331 insert_char (ch);
335 else
337 /* PRINTCHARFUN is a Lisp function. */
338 EMACS_INT i = 0;
340 if (size == size_byte)
342 while (i < size_byte)
344 int ch = ptr[i++];
345 PRINTCHAR (ch);
348 else
350 while (i < size_byte)
352 /* Here, we must convert each multi-byte form to the
353 corresponding character code before handing it to
354 PRINTCHAR. */
355 int len;
356 int ch = STRING_CHAR_AND_LENGTH ((const unsigned char *) ptr + i,
357 len);
358 PRINTCHAR (ch);
359 i += len;
365 /* Print the contents of a string STRING using PRINTCHARFUN.
366 It isn't safe to use strout in many cases,
367 because printing one char can relocate. */
369 static void
370 print_string (Lisp_Object string, Lisp_Object printcharfun)
372 if (EQ (printcharfun, Qt) || NILP (printcharfun))
374 EMACS_INT chars;
376 if (print_escape_nonascii)
377 string = string_escape_byte8 (string);
379 if (STRING_MULTIBYTE (string))
380 chars = SCHARS (string);
381 else if (! print_escape_nonascii
382 && (EQ (printcharfun, Qt)
383 ? ! NILP (BVAR (&buffer_defaults, enable_multibyte_characters))
384 : ! NILP (BVAR (current_buffer, enable_multibyte_characters))))
386 /* If unibyte string STRING contains 8-bit codes, we must
387 convert STRING to a multibyte string containing the same
388 character codes. */
389 Lisp_Object newstr;
390 EMACS_INT bytes;
392 chars = SBYTES (string);
393 bytes = count_size_as_multibyte (SDATA (string), chars);
394 if (chars < bytes)
396 newstr = make_uninit_multibyte_string (chars, bytes);
397 memcpy (SDATA (newstr), SDATA (string), chars);
398 str_to_multibyte (SDATA (newstr), bytes, chars);
399 string = newstr;
402 else
403 chars = SBYTES (string);
405 if (EQ (printcharfun, Qt))
407 /* Output to echo area. */
408 EMACS_INT nbytes = SBYTES (string);
409 char *buffer;
411 /* Copy the string contents so that relocation of STRING by
412 GC does not cause trouble. */
413 USE_SAFE_ALLOCA;
415 SAFE_ALLOCA (buffer, char *, nbytes);
416 memcpy (buffer, SDATA (string), nbytes);
418 strout (buffer, chars, SBYTES (string), printcharfun);
420 SAFE_FREE ();
422 else
423 /* No need to copy, since output to print_buffer can't GC. */
424 strout (SSDATA (string), chars, SBYTES (string), printcharfun);
426 else
428 /* Otherwise, string may be relocated by printing one char.
429 So re-fetch the string address for each character. */
430 EMACS_INT i;
431 EMACS_INT size = SCHARS (string);
432 EMACS_INT size_byte = SBYTES (string);
433 struct gcpro gcpro1;
434 GCPRO1 (string);
435 if (size == size_byte)
436 for (i = 0; i < size; i++)
437 PRINTCHAR (SREF (string, i));
438 else
439 for (i = 0; i < size_byte; )
441 /* Here, we must convert each multi-byte form to the
442 corresponding character code before handing it to PRINTCHAR. */
443 int len;
444 int ch = STRING_CHAR_AND_LENGTH (SDATA (string) + i, len);
445 PRINTCHAR (ch);
446 i += len;
448 UNGCPRO;
452 DEFUN ("write-char", Fwrite_char, Swrite_char, 1, 2, 0,
453 doc: /* Output character CHARACTER to stream PRINTCHARFUN.
454 PRINTCHARFUN defaults to the value of `standard-output' (which see). */)
455 (Lisp_Object character, Lisp_Object printcharfun)
457 PRINTDECLARE;
459 if (NILP (printcharfun))
460 printcharfun = Vstandard_output;
461 CHECK_NUMBER (character);
462 PRINTPREPARE;
463 PRINTCHAR (XINT (character));
464 PRINTFINISH;
465 return character;
468 /* Used from outside of print.c to print a block of SIZE
469 single-byte chars at DATA on the default output stream.
470 Do not use this on the contents of a Lisp string. */
472 void
473 write_string (const char *data, int size)
475 PRINTDECLARE;
476 Lisp_Object printcharfun;
478 printcharfun = Vstandard_output;
480 PRINTPREPARE;
481 strout (data, size, size, printcharfun);
482 PRINTFINISH;
485 /* Used to print a block of SIZE single-byte chars at DATA on a
486 specified stream PRINTCHARFUN.
487 Do not use this on the contents of a Lisp string. */
489 static void
490 write_string_1 (const char *data, int size, Lisp_Object printcharfun)
492 PRINTDECLARE;
494 PRINTPREPARE;
495 strout (data, size, size, printcharfun);
496 PRINTFINISH;
500 void
501 temp_output_buffer_setup (const char *bufname)
503 int count = SPECPDL_INDEX ();
504 register struct buffer *old = current_buffer;
505 register Lisp_Object buf;
507 record_unwind_protect (set_buffer_if_live, Fcurrent_buffer ());
509 Fset_buffer (Fget_buffer_create (build_string (bufname)));
511 Fkill_all_local_variables ();
512 delete_all_overlays (current_buffer);
513 BVAR (current_buffer, directory) = BVAR (old, directory);
514 BVAR (current_buffer, read_only) = Qnil;
515 BVAR (current_buffer, filename) = Qnil;
516 BVAR (current_buffer, undo_list) = Qt;
517 eassert (current_buffer->overlays_before == NULL);
518 eassert (current_buffer->overlays_after == NULL);
519 BVAR (current_buffer, enable_multibyte_characters)
520 = BVAR (&buffer_defaults, enable_multibyte_characters);
521 specbind (Qinhibit_read_only, Qt);
522 specbind (Qinhibit_modification_hooks, Qt);
523 Ferase_buffer ();
524 XSETBUFFER (buf, current_buffer);
526 Frun_hooks (1, &Qtemp_buffer_setup_hook);
528 unbind_to (count, Qnil);
530 specbind (Qstandard_output, buf);
533 static void print (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag);
534 static void print_preprocess (Lisp_Object obj);
535 static void print_preprocess_string (INTERVAL interval, Lisp_Object arg);
536 static void print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag);
538 DEFUN ("terpri", Fterpri, Sterpri, 0, 1, 0,
539 doc: /* Output a newline to stream PRINTCHARFUN.
540 If PRINTCHARFUN is omitted or nil, the value of `standard-output' is used. */)
541 (Lisp_Object printcharfun)
543 PRINTDECLARE;
545 if (NILP (printcharfun))
546 printcharfun = Vstandard_output;
547 PRINTPREPARE;
548 PRINTCHAR ('\n');
549 PRINTFINISH;
550 return Qt;
553 DEFUN ("prin1", Fprin1, Sprin1, 1, 2, 0,
554 doc: /* Output the printed representation of OBJECT, any Lisp object.
555 Quoting characters are printed when needed to make output that `read'
556 can handle, whenever this is possible. For complex objects, the behavior
557 is controlled by `print-level' and `print-length', which see.
559 OBJECT is any of the Lisp data types: a number, a string, a symbol,
560 a list, a buffer, a window, a frame, etc.
562 A printed representation of an object is text which describes that object.
564 Optional argument PRINTCHARFUN is the output stream, which can be one
565 of these:
567 - a buffer, in which case output is inserted into that buffer at point;
568 - a marker, in which case output is inserted at marker's position;
569 - a function, in which case that function is called once for each
570 character of OBJECT's printed representation;
571 - a symbol, in which case that symbol's function definition is called; or
572 - t, in which case the output is displayed in the echo area.
574 If PRINTCHARFUN is omitted, the value of `standard-output' (which see)
575 is used instead. */)
576 (Lisp_Object object, Lisp_Object printcharfun)
578 PRINTDECLARE;
580 if (NILP (printcharfun))
581 printcharfun = Vstandard_output;
582 PRINTPREPARE;
583 print (object, printcharfun, 1);
584 PRINTFINISH;
585 return object;
588 /* a buffer which is used to hold output being built by prin1-to-string */
589 Lisp_Object Vprin1_to_string_buffer;
591 DEFUN ("prin1-to-string", Fprin1_to_string, Sprin1_to_string, 1, 2, 0,
592 doc: /* Return a string containing the printed representation of OBJECT.
593 OBJECT can be any Lisp object. This function outputs quoting characters
594 when necessary to make output that `read' can handle, whenever possible,
595 unless the optional second argument NOESCAPE is non-nil. For complex objects,
596 the behavior is controlled by `print-level' and `print-length', which see.
598 OBJECT is any of the Lisp data types: a number, a string, a symbol,
599 a list, a buffer, a window, a frame, etc.
601 A printed representation of an object is text which describes that object. */)
602 (Lisp_Object object, Lisp_Object noescape)
604 Lisp_Object printcharfun;
605 /* struct gcpro gcpro1, gcpro2; */
606 Lisp_Object save_deactivate_mark;
607 int count = SPECPDL_INDEX ();
608 struct buffer *previous;
610 specbind (Qinhibit_modification_hooks, Qt);
613 PRINTDECLARE;
615 /* Save and restore this--we are altering a buffer
616 but we don't want to deactivate the mark just for that.
617 No need for specbind, since errors deactivate the mark. */
618 save_deactivate_mark = Vdeactivate_mark;
619 /* GCPRO2 (object, save_deactivate_mark); */
620 abort_on_gc++;
622 printcharfun = Vprin1_to_string_buffer;
623 PRINTPREPARE;
624 print (object, printcharfun, NILP (noescape));
625 /* Make Vprin1_to_string_buffer be the default buffer after PRINTFINSH */
626 PRINTFINISH;
629 previous = current_buffer;
630 set_buffer_internal (XBUFFER (Vprin1_to_string_buffer));
631 object = Fbuffer_string ();
632 if (SBYTES (object) == SCHARS (object))
633 STRING_SET_UNIBYTE (object);
635 /* Note that this won't make prepare_to_modify_buffer call
636 ask-user-about-supersession-threat because this buffer
637 does not visit a file. */
638 Ferase_buffer ();
639 set_buffer_internal (previous);
641 Vdeactivate_mark = save_deactivate_mark;
642 /* UNGCPRO; */
644 abort_on_gc--;
645 return unbind_to (count, object);
648 DEFUN ("princ", Fprinc, Sprinc, 1, 2, 0,
649 doc: /* Output the printed representation of OBJECT, any Lisp object.
650 No quoting characters are used; no delimiters are printed around
651 the contents of strings.
653 OBJECT is any of the Lisp data types: a number, a string, a symbol,
654 a list, a buffer, a window, a frame, etc.
656 A printed representation of an object is text which describes that object.
658 Optional argument PRINTCHARFUN is the output stream, which can be one
659 of these:
661 - a buffer, in which case output is inserted into that buffer at point;
662 - a marker, in which case output is inserted at marker's position;
663 - a function, in which case that function is called once for each
664 character of OBJECT's printed representation;
665 - a symbol, in which case that symbol's function definition is called; or
666 - t, in which case the output is displayed in the echo area.
668 If PRINTCHARFUN is omitted, the value of `standard-output' (which see)
669 is used instead. */)
670 (Lisp_Object object, Lisp_Object printcharfun)
672 PRINTDECLARE;
674 if (NILP (printcharfun))
675 printcharfun = Vstandard_output;
676 PRINTPREPARE;
677 print (object, printcharfun, 0);
678 PRINTFINISH;
679 return object;
682 DEFUN ("print", Fprint, Sprint, 1, 2, 0,
683 doc: /* Output the printed representation of OBJECT, with newlines around it.
684 Quoting characters are printed when needed to make output that `read'
685 can handle, whenever this is possible. For complex objects, the behavior
686 is controlled by `print-level' and `print-length', which see.
688 OBJECT is any of the Lisp data types: a number, a string, a symbol,
689 a list, a buffer, a window, a frame, etc.
691 A printed representation of an object is text which describes that object.
693 Optional argument PRINTCHARFUN is the output stream, which can be one
694 of these:
696 - a buffer, in which case output is inserted into that buffer at point;
697 - a marker, in which case output is inserted at marker's position;
698 - a function, in which case that function is called once for each
699 character of OBJECT's printed representation;
700 - a symbol, in which case that symbol's function definition is called; or
701 - t, in which case the output is displayed in the echo area.
703 If PRINTCHARFUN is omitted, the value of `standard-output' (which see)
704 is used instead. */)
705 (Lisp_Object object, Lisp_Object printcharfun)
707 PRINTDECLARE;
708 struct gcpro gcpro1;
710 if (NILP (printcharfun))
711 printcharfun = Vstandard_output;
712 GCPRO1 (object);
713 PRINTPREPARE;
714 PRINTCHAR ('\n');
715 print (object, printcharfun, 1);
716 PRINTCHAR ('\n');
717 PRINTFINISH;
718 UNGCPRO;
719 return object;
722 /* The subroutine object for external-debugging-output is kept here
723 for the convenience of the debugger. */
724 Lisp_Object Qexternal_debugging_output;
726 DEFUN ("external-debugging-output", Fexternal_debugging_output, Sexternal_debugging_output, 1, 1, 0,
727 doc: /* Write CHARACTER to stderr.
728 You can call print while debugging emacs, and pass it this function
729 to make it write to the debugging output. */)
730 (Lisp_Object character)
732 CHECK_NUMBER (character);
733 putc ((int) XINT (character), stderr);
735 #ifdef WINDOWSNT
736 /* Send the output to a debugger (nothing happens if there isn't one). */
737 if (print_output_debug_flag)
739 char buf[2] = {(char) XINT (character), '\0'};
740 OutputDebugString (buf);
742 #endif
744 return character;
747 /* This function is never called. Its purpose is to prevent
748 print_output_debug_flag from being optimized away. */
750 extern void debug_output_compilation_hack (int) EXTERNALLY_VISIBLE;
751 void
752 debug_output_compilation_hack (int x)
754 print_output_debug_flag = x;
757 #if defined (GNU_LINUX)
759 /* This functionality is not vitally important in general, so we rely on
760 non-portable ability to use stderr as lvalue. */
762 #define WITH_REDIRECT_DEBUGGING_OUTPUT 1
764 static FILE *initial_stderr_stream = NULL;
766 DEFUN ("redirect-debugging-output", Fredirect_debugging_output, Sredirect_debugging_output,
767 1, 2,
768 "FDebug output file: \nP",
769 doc: /* Redirect debugging output (stderr stream) to file FILE.
770 If FILE is nil, reset target to the initial stderr stream.
771 Optional arg APPEND non-nil (interactively, with prefix arg) means
772 append to existing target file. */)
773 (Lisp_Object file, Lisp_Object append)
775 if (initial_stderr_stream != NULL)
777 BLOCK_INPUT;
778 fclose (stderr);
779 UNBLOCK_INPUT;
781 stderr = initial_stderr_stream;
782 initial_stderr_stream = NULL;
784 if (STRINGP (file))
786 file = Fexpand_file_name (file, Qnil);
787 initial_stderr_stream = stderr;
788 stderr = fopen (SSDATA (file), NILP (append) ? "w" : "a");
789 if (stderr == NULL)
791 stderr = initial_stderr_stream;
792 initial_stderr_stream = NULL;
793 report_file_error ("Cannot open debugging output stream",
794 Fcons (file, Qnil));
797 return Qnil;
799 #endif /* GNU_LINUX */
802 /* This is the interface for debugging printing. */
804 void
805 debug_print (Lisp_Object arg)
807 Fprin1 (arg, Qexternal_debugging_output);
808 fprintf (stderr, "\r\n");
811 void safe_debug_print (Lisp_Object) EXTERNALLY_VISIBLE;
812 void
813 safe_debug_print (Lisp_Object arg)
815 int valid = valid_lisp_object_p (arg);
817 if (valid > 0)
818 debug_print (arg);
819 else
820 fprintf (stderr, "#<%s_LISP_OBJECT 0x%08"pI"x>\r\n",
821 !valid ? "INVALID" : "SOME",
822 XHASH (arg));
826 DEFUN ("error-message-string", Ferror_message_string, Serror_message_string,
827 1, 1, 0,
828 doc: /* Convert an error value (ERROR-SYMBOL . DATA) to an error message.
829 See Info anchor `(elisp)Definition of signal' for some details on how this
830 error message is constructed. */)
831 (Lisp_Object obj)
833 struct buffer *old = current_buffer;
834 Lisp_Object value;
835 struct gcpro gcpro1;
837 /* If OBJ is (error STRING), just return STRING.
838 That is not only faster, it also avoids the need to allocate
839 space here when the error is due to memory full. */
840 if (CONSP (obj) && EQ (XCAR (obj), Qerror)
841 && CONSP (XCDR (obj))
842 && STRINGP (XCAR (XCDR (obj)))
843 && NILP (XCDR (XCDR (obj))))
844 return XCAR (XCDR (obj));
846 print_error_message (obj, Vprin1_to_string_buffer, 0, Qnil);
848 set_buffer_internal (XBUFFER (Vprin1_to_string_buffer));
849 value = Fbuffer_string ();
851 GCPRO1 (value);
852 Ferase_buffer ();
853 set_buffer_internal (old);
854 UNGCPRO;
856 return value;
859 /* Print an error message for the error DATA onto Lisp output stream
860 STREAM (suitable for the print functions).
861 CONTEXT is a C string describing the context of the error.
862 CALLER is the Lisp function inside which the error was signaled. */
864 void
865 print_error_message (Lisp_Object data, Lisp_Object stream, const char *context,
866 Lisp_Object caller)
868 Lisp_Object errname, errmsg, file_error, tail;
869 struct gcpro gcpro1;
870 int i;
872 if (context != 0)
873 write_string_1 (context, -1, stream);
875 /* If we know from where the error was signaled, show it in
876 *Messages*. */
877 if (!NILP (caller) && SYMBOLP (caller))
879 Lisp_Object cname = SYMBOL_NAME (caller);
880 char *name = alloca (SBYTES (cname));
881 memcpy (name, SDATA (cname), SBYTES (cname));
882 message_dolog (name, SBYTES (cname), 0, 0);
883 message_dolog (": ", 2, 0, 0);
886 errname = Fcar (data);
888 if (EQ (errname, Qerror))
890 data = Fcdr (data);
891 if (!CONSP (data))
892 data = Qnil;
893 errmsg = Fcar (data);
894 file_error = Qnil;
896 else
898 Lisp_Object error_conditions;
899 errmsg = Fget (errname, Qerror_message);
900 error_conditions = Fget (errname, Qerror_conditions);
901 file_error = Fmemq (Qfile_error, error_conditions);
904 /* Print an error message including the data items. */
906 tail = Fcdr_safe (data);
907 GCPRO1 (tail);
909 /* For file-error, make error message by concatenating
910 all the data items. They are all strings. */
911 if (!NILP (file_error) && CONSP (tail))
912 errmsg = XCAR (tail), tail = XCDR (tail);
914 if (STRINGP (errmsg))
915 Fprinc (errmsg, stream);
916 else
917 write_string_1 ("peculiar error", -1, stream);
919 for (i = 0; CONSP (tail); tail = XCDR (tail), i = 1)
921 Lisp_Object obj;
923 write_string_1 (i ? ", " : ": ", 2, stream);
924 obj = XCAR (tail);
925 if (!NILP (file_error) || EQ (errname, Qend_of_file))
926 Fprinc (obj, stream);
927 else
928 Fprin1 (obj, stream);
931 UNGCPRO;
937 * The buffer should be at least as large as the max string size of the
938 * largest float, printed in the biggest notation. This is undoubtedly
939 * 20d float_output_format, with the negative of the C-constant "HUGE"
940 * from <math.h>.
942 * On the vax the worst case is -1e38 in 20d format which takes 61 bytes.
944 * I assume that IEEE-754 format numbers can take 329 bytes for the worst
945 * case of -1e307 in 20d float_output_format. What is one to do (short of
946 * re-writing _doprnt to be more sane)?
947 * -wsr
948 * Given the above, the buffer must be least FLOAT_TO_STRING_BUFSIZE bytes.
951 void
952 float_to_string (char *buf, double data)
954 char *cp;
955 int width;
957 /* Check for plus infinity in a way that won't lose
958 if there is no plus infinity. */
959 if (data == data / 2 && data > 1.0)
961 strcpy (buf, "1.0e+INF");
962 return;
964 /* Likewise for minus infinity. */
965 if (data == data / 2 && data < -1.0)
967 strcpy (buf, "-1.0e+INF");
968 return;
970 /* Check for NaN in a way that won't fail if there are no NaNs. */
971 if (! (data * 0.0 >= 0.0))
973 /* Prepend "-" if the NaN's sign bit is negative.
974 The sign bit of a double is the bit that is 1 in -0.0. */
975 int i;
976 union { double d; char c[sizeof (double)]; } u_data, u_minus_zero;
977 u_data.d = data;
978 u_minus_zero.d = - 0.0;
979 for (i = 0; i < sizeof (double); i++)
980 if (u_data.c[i] & u_minus_zero.c[i])
982 *buf++ = '-';
983 break;
986 strcpy (buf, "0.0e+NaN");
987 return;
990 if (NILP (Vfloat_output_format)
991 || !STRINGP (Vfloat_output_format))
992 lose:
994 /* Generate the fewest number of digits that represent the
995 floating point value without losing information. */
996 dtoastr (buf, FLOAT_TO_STRING_BUFSIZE - 2, 0, 0, data);
997 /* The decimal point must be printed, or the byte compiler can
998 get confused (Bug#8033). */
999 width = 1;
1001 else /* oink oink */
1003 /* Check that the spec we have is fully valid.
1004 This means not only valid for printf,
1005 but meant for floats, and reasonable. */
1006 cp = SSDATA (Vfloat_output_format);
1008 if (cp[0] != '%')
1009 goto lose;
1010 if (cp[1] != '.')
1011 goto lose;
1013 cp += 2;
1015 /* Check the width specification. */
1016 width = -1;
1017 if ('0' <= *cp && *cp <= '9')
1019 width = 0;
1021 width = (width * 10) + (*cp++ - '0');
1022 while (*cp >= '0' && *cp <= '9');
1024 /* A precision of zero is valid only for %f. */
1025 if (width > DBL_DIG
1026 || (width == 0 && *cp != 'f'))
1027 goto lose;
1030 if (*cp != 'e' && *cp != 'f' && *cp != 'g')
1031 goto lose;
1033 if (cp[1] != 0)
1034 goto lose;
1036 sprintf (buf, SSDATA (Vfloat_output_format), data);
1039 /* Make sure there is a decimal point with digit after, or an
1040 exponent, so that the value is readable as a float. But don't do
1041 this with "%.0f"; it's valid for that not to produce a decimal
1042 point. Note that width can be 0 only for %.0f. */
1043 if (width != 0)
1045 for (cp = buf; *cp; cp++)
1046 if ((*cp < '0' || *cp > '9') && *cp != '-')
1047 break;
1049 if (*cp == '.' && cp[1] == 0)
1051 cp[1] = '0';
1052 cp[2] = 0;
1054 else if (*cp == 0)
1056 *cp++ = '.';
1057 *cp++ = '0';
1058 *cp++ = 0;
1064 static void
1065 print (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag)
1067 new_backquote_output = 0;
1069 /* Reset print_number_index and Vprint_number_table only when
1070 the variable Vprint_continuous_numbering is nil. Otherwise,
1071 the values of these variables will be kept between several
1072 print functions. */
1073 if (NILP (Vprint_continuous_numbering)
1074 || NILP (Vprint_number_table))
1076 print_number_index = 0;
1077 Vprint_number_table = Qnil;
1080 /* Construct Vprint_number_table for print-gensym and print-circle. */
1081 if (!NILP (Vprint_gensym) || !NILP (Vprint_circle))
1083 /* Construct Vprint_number_table.
1084 This increments print_number_index for the objects added. */
1085 print_depth = 0;
1086 print_preprocess (obj);
1088 if (HASH_TABLE_P (Vprint_number_table))
1089 { /* Remove unnecessary objects, which appear only once in OBJ;
1090 that is, whose status is Qt.
1091 Maybe a better way to do that is to copy elements to
1092 a new hash table. */
1093 struct Lisp_Hash_Table *h = XHASH_TABLE (Vprint_number_table);
1094 EMACS_INT i;
1096 for (i = 0; i < HASH_TABLE_SIZE (h); ++i)
1097 if (!NILP (HASH_HASH (h, i))
1098 && EQ (HASH_VALUE (h, i), Qt))
1099 Fremhash (HASH_KEY (h, i), Vprint_number_table);
1103 print_depth = 0;
1104 print_object (obj, printcharfun, escapeflag);
1107 #define PRINT_CIRCLE_CANDIDATE_P(obj) \
1108 (STRINGP (obj) || CONSP (obj) \
1109 || (VECTORLIKEP (obj) \
1110 && (VECTORP (obj) || COMPILEDP (obj) \
1111 || CHAR_TABLE_P (obj) || SUB_CHAR_TABLE_P (obj) \
1112 || HASH_TABLE_P (obj) || FONTP (obj))) \
1113 || (! NILP (Vprint_gensym) \
1114 && SYMBOLP (obj) \
1115 && !SYMBOL_INTERNED_P (obj)))
1117 /* Construct Vprint_number_table according to the structure of OBJ.
1118 OBJ itself and all its elements will be added to Vprint_number_table
1119 recursively if it is a list, vector, compiled function, char-table,
1120 string (its text properties will be traced), or a symbol that has
1121 no obarray (this is for the print-gensym feature).
1122 The status fields of Vprint_number_table mean whether each object appears
1123 more than once in OBJ: Qnil at the first time, and Qt after that . */
1124 static void
1125 print_preprocess (Lisp_Object obj)
1127 int i;
1128 EMACS_INT size;
1129 int loop_count = 0;
1130 Lisp_Object halftail;
1132 /* Give up if we go so deep that print_object will get an error. */
1133 /* See similar code in print_object. */
1134 if (print_depth >= PRINT_CIRCLE)
1135 error ("Apparently circular structure being printed");
1137 /* Avoid infinite recursion for circular nested structure
1138 in the case where Vprint_circle is nil. */
1139 if (NILP (Vprint_circle))
1141 for (i = 0; i < print_depth; i++)
1142 if (EQ (obj, being_printed[i]))
1143 return;
1144 being_printed[print_depth] = obj;
1147 print_depth++;
1148 halftail = obj;
1150 loop:
1151 if (PRINT_CIRCLE_CANDIDATE_P (obj))
1153 if (!HASH_TABLE_P (Vprint_number_table))
1155 Lisp_Object args[2];
1156 args[0] = QCtest;
1157 args[1] = Qeq;
1158 Vprint_number_table = Fmake_hash_table (2, args);
1161 /* In case print-circle is nil and print-gensym is t,
1162 add OBJ to Vprint_number_table only when OBJ is a symbol. */
1163 if (! NILP (Vprint_circle) || SYMBOLP (obj))
1165 Lisp_Object num = Fgethash (obj, Vprint_number_table, Qnil);
1166 if (!NILP (num)
1167 /* If Vprint_continuous_numbering is non-nil and OBJ is a gensym,
1168 always print the gensym with a number. This is a special for
1169 the lisp function byte-compile-output-docform. */
1170 || (!NILP (Vprint_continuous_numbering)
1171 && SYMBOLP (obj)
1172 && !SYMBOL_INTERNED_P (obj)))
1173 { /* OBJ appears more than once. Let's remember that. */
1174 if (!INTEGERP (num))
1176 print_number_index++;
1177 /* Negative number indicates it hasn't been printed yet. */
1178 Fputhash (obj, make_number (- print_number_index),
1179 Vprint_number_table);
1181 print_depth--;
1182 return;
1184 else
1185 /* OBJ is not yet recorded. Let's add to the table. */
1186 Fputhash (obj, Qt, Vprint_number_table);
1189 switch (XTYPE (obj))
1191 case Lisp_String:
1192 /* A string may have text properties, which can be circular. */
1193 traverse_intervals_noorder (STRING_INTERVALS (obj),
1194 print_preprocess_string, Qnil);
1195 break;
1197 case Lisp_Cons:
1198 /* Use HALFTAIL and LOOP_COUNT to detect circular lists,
1199 just as in print_object. */
1200 if (loop_count && EQ (obj, halftail))
1201 break;
1202 print_preprocess (XCAR (obj));
1203 obj = XCDR (obj);
1204 loop_count++;
1205 if (!(loop_count & 1))
1206 halftail = XCDR (halftail);
1207 goto loop;
1209 case Lisp_Vectorlike:
1210 size = ASIZE (obj);
1211 if (size & PSEUDOVECTOR_FLAG)
1212 size &= PSEUDOVECTOR_SIZE_MASK;
1213 for (i = 0; i < size; i++)
1214 print_preprocess (XVECTOR (obj)->contents[i]);
1215 if (HASH_TABLE_P (obj))
1216 { /* For hash tables, the key_and_value slot is past
1217 `size' because it needs to be marked specially in case
1218 the table is weak. */
1219 struct Lisp_Hash_Table *h = XHASH_TABLE (obj);
1220 print_preprocess (h->key_and_value);
1222 break;
1224 default:
1225 break;
1228 print_depth--;
1231 static void
1232 print_preprocess_string (INTERVAL interval, Lisp_Object arg)
1234 print_preprocess (interval->plist);
1237 static void print_check_string_charset_prop (INTERVAL interval, Lisp_Object string);
1239 #define PRINT_STRING_NON_CHARSET_FOUND 1
1240 #define PRINT_STRING_UNSAFE_CHARSET_FOUND 2
1242 /* Bitwise or of the above macros. */
1243 static int print_check_string_result;
1245 static void
1246 print_check_string_charset_prop (INTERVAL interval, Lisp_Object string)
1248 Lisp_Object val;
1250 if (NILP (interval->plist)
1251 || (print_check_string_result == (PRINT_STRING_NON_CHARSET_FOUND
1252 | PRINT_STRING_UNSAFE_CHARSET_FOUND)))
1253 return;
1254 for (val = interval->plist; CONSP (val) && ! EQ (XCAR (val), Qcharset);
1255 val = XCDR (XCDR (val)));
1256 if (! CONSP (val))
1258 print_check_string_result |= PRINT_STRING_NON_CHARSET_FOUND;
1259 return;
1261 if (! (print_check_string_result & PRINT_STRING_NON_CHARSET_FOUND))
1263 if (! EQ (val, interval->plist)
1264 || CONSP (XCDR (XCDR (val))))
1265 print_check_string_result |= PRINT_STRING_NON_CHARSET_FOUND;
1267 if (NILP (Vprint_charset_text_property)
1268 || ! (print_check_string_result & PRINT_STRING_UNSAFE_CHARSET_FOUND))
1270 int i, c;
1271 EMACS_INT charpos = interval->position;
1272 EMACS_INT bytepos = string_char_to_byte (string, charpos);
1273 Lisp_Object charset;
1275 charset = XCAR (XCDR (val));
1276 for (i = 0; i < LENGTH (interval); i++)
1278 FETCH_STRING_CHAR_ADVANCE (c, string, charpos, bytepos);
1279 if (! ASCII_CHAR_P (c)
1280 && ! EQ (CHARSET_NAME (CHAR_CHARSET (c)), charset))
1282 print_check_string_result |= PRINT_STRING_UNSAFE_CHARSET_FOUND;
1283 break;
1289 /* The value is (charset . nil). */
1290 static Lisp_Object print_prune_charset_plist;
1292 static Lisp_Object
1293 print_prune_string_charset (Lisp_Object string)
1295 print_check_string_result = 0;
1296 traverse_intervals (STRING_INTERVALS (string), 0,
1297 print_check_string_charset_prop, string);
1298 if (! (print_check_string_result & PRINT_STRING_UNSAFE_CHARSET_FOUND))
1300 string = Fcopy_sequence (string);
1301 if (print_check_string_result & PRINT_STRING_NON_CHARSET_FOUND)
1303 if (NILP (print_prune_charset_plist))
1304 print_prune_charset_plist = Fcons (Qcharset, Qnil);
1305 Fremove_text_properties (make_number (0),
1306 make_number (SCHARS (string)),
1307 print_prune_charset_plist, string);
1309 else
1310 Fset_text_properties (make_number (0), make_number (SCHARS (string)),
1311 Qnil, string);
1313 return string;
1316 static void
1317 print_object (Lisp_Object obj, register Lisp_Object printcharfun, int escapeflag)
1319 char buf[40];
1321 QUIT;
1323 /* See similar code in print_preprocess. */
1324 if (print_depth >= PRINT_CIRCLE)
1325 error ("Apparently circular structure being printed");
1327 /* Detect circularities and truncate them. */
1328 if (PRINT_CIRCLE_CANDIDATE_P (obj))
1330 if (NILP (Vprint_circle) && NILP (Vprint_gensym))
1332 /* Simple but incomplete way. */
1333 int i;
1334 for (i = 0; i < print_depth; i++)
1335 if (EQ (obj, being_printed[i]))
1337 sprintf (buf, "#%d", i);
1338 strout (buf, -1, -1, printcharfun);
1339 return;
1341 being_printed[print_depth] = obj;
1343 else
1345 /* With the print-circle feature. */
1346 Lisp_Object num = Fgethash (obj, Vprint_number_table, Qnil);
1347 if (INTEGERP (num))
1349 EMACS_INT n = XINT (num);
1350 if (n < 0)
1351 { /* Add a prefix #n= if OBJ has not yet been printed;
1352 that is, its status field is nil. */
1353 sprintf (buf, "#%"pI"d=", -n);
1354 strout (buf, -1, -1, printcharfun);
1355 /* OBJ is going to be printed. Remember that fact. */
1356 Fputhash (obj, make_number (- n), Vprint_number_table);
1358 else
1360 /* Just print #n# if OBJ has already been printed. */
1361 sprintf (buf, "#%"pI"d#", n);
1362 strout (buf, -1, -1, printcharfun);
1363 return;
1369 print_depth++;
1371 switch (XTYPE (obj))
1373 case_Lisp_Int:
1374 sprintf (buf, "%"pI"d", XINT (obj));
1375 strout (buf, -1, -1, printcharfun);
1376 break;
1378 case Lisp_Float:
1380 char pigbuf[FLOAT_TO_STRING_BUFSIZE];
1382 float_to_string (pigbuf, XFLOAT_DATA (obj));
1383 strout (pigbuf, -1, -1, printcharfun);
1385 break;
1387 case Lisp_String:
1388 if (!escapeflag)
1389 print_string (obj, printcharfun);
1390 else
1392 register EMACS_INT i_byte;
1393 struct gcpro gcpro1;
1394 unsigned char *str;
1395 EMACS_INT size_byte;
1396 /* 1 means we must ensure that the next character we output
1397 cannot be taken as part of a hex character escape. */
1398 int need_nonhex = 0;
1399 int multibyte = STRING_MULTIBYTE (obj);
1401 GCPRO1 (obj);
1403 if (! EQ (Vprint_charset_text_property, Qt))
1404 obj = print_prune_string_charset (obj);
1406 if (!NULL_INTERVAL_P (STRING_INTERVALS (obj)))
1408 PRINTCHAR ('#');
1409 PRINTCHAR ('(');
1412 PRINTCHAR ('\"');
1413 str = SDATA (obj);
1414 size_byte = SBYTES (obj);
1416 for (i_byte = 0; i_byte < size_byte;)
1418 /* Here, we must convert each multi-byte form to the
1419 corresponding character code before handing it to PRINTCHAR. */
1420 int len;
1421 int c;
1423 if (multibyte)
1425 c = STRING_CHAR_AND_LENGTH (str + i_byte, len);
1426 i_byte += len;
1428 else
1429 c = str[i_byte++];
1431 QUIT;
1433 if (c == '\n' && print_escape_newlines)
1435 PRINTCHAR ('\\');
1436 PRINTCHAR ('n');
1438 else if (c == '\f' && print_escape_newlines)
1440 PRINTCHAR ('\\');
1441 PRINTCHAR ('f');
1443 else if (multibyte
1444 && (CHAR_BYTE8_P (c)
1445 || (! ASCII_CHAR_P (c) && print_escape_multibyte)))
1447 /* When multibyte is disabled,
1448 print multibyte string chars using hex escapes.
1449 For a char code that could be in a unibyte string,
1450 when found in a multibyte string, always use a hex escape
1451 so it reads back as multibyte. */
1452 char outbuf[50];
1454 if (CHAR_BYTE8_P (c))
1455 sprintf (outbuf, "\\%03o", CHAR_TO_BYTE8 (c));
1456 else
1458 sprintf (outbuf, "\\x%04x", c);
1459 need_nonhex = 1;
1461 strout (outbuf, -1, -1, printcharfun);
1463 else if (! multibyte
1464 && SINGLE_BYTE_CHAR_P (c) && ! ASCII_BYTE_P (c)
1465 && print_escape_nonascii)
1467 /* When printing in a multibyte buffer
1468 or when explicitly requested,
1469 print single-byte non-ASCII string chars
1470 using octal escapes. */
1471 char outbuf[5];
1472 sprintf (outbuf, "\\%03o", c);
1473 strout (outbuf, -1, -1, printcharfun);
1475 else
1477 /* If we just had a hex escape, and this character
1478 could be taken as part of it,
1479 output `\ ' to prevent that. */
1480 if (need_nonhex)
1482 need_nonhex = 0;
1483 if ((c >= 'a' && c <= 'f')
1484 || (c >= 'A' && c <= 'F')
1485 || (c >= '0' && c <= '9'))
1486 strout ("\\ ", -1, -1, printcharfun);
1489 if (c == '\"' || c == '\\')
1490 PRINTCHAR ('\\');
1491 PRINTCHAR (c);
1494 PRINTCHAR ('\"');
1496 if (!NULL_INTERVAL_P (STRING_INTERVALS (obj)))
1498 traverse_intervals (STRING_INTERVALS (obj),
1499 0, print_interval, printcharfun);
1500 PRINTCHAR (')');
1503 UNGCPRO;
1505 break;
1507 case Lisp_Symbol:
1509 register int confusing;
1510 register unsigned char *p = SDATA (SYMBOL_NAME (obj));
1511 register unsigned char *end = p + SBYTES (SYMBOL_NAME (obj));
1512 register int c;
1513 int i, i_byte;
1514 EMACS_INT size_byte;
1515 Lisp_Object name;
1517 name = SYMBOL_NAME (obj);
1519 if (p != end && (*p == '-' || *p == '+')) p++;
1520 if (p == end)
1521 confusing = 0;
1522 /* If symbol name begins with a digit, and ends with a digit,
1523 and contains nothing but digits and `e', it could be treated
1524 as a number. So set CONFUSING.
1526 Symbols that contain periods could also be taken as numbers,
1527 but periods are always escaped, so we don't have to worry
1528 about them here. */
1529 else if (*p >= '0' && *p <= '9'
1530 && end[-1] >= '0' && end[-1] <= '9')
1532 while (p != end && ((*p >= '0' && *p <= '9')
1533 /* Needed for \2e10. */
1534 || *p == 'e' || *p == 'E'))
1535 p++;
1536 confusing = (end == p);
1538 else
1539 confusing = 0;
1541 size_byte = SBYTES (name);
1543 if (! NILP (Vprint_gensym) && !SYMBOL_INTERNED_P (obj))
1545 PRINTCHAR ('#');
1546 PRINTCHAR (':');
1548 else if (size_byte == 0)
1550 PRINTCHAR ('#');
1551 PRINTCHAR ('#');
1552 break;
1555 for (i = 0, i_byte = 0; i_byte < size_byte;)
1557 /* Here, we must convert each multi-byte form to the
1558 corresponding character code before handing it to PRINTCHAR. */
1559 FETCH_STRING_CHAR_ADVANCE (c, name, i, i_byte);
1560 QUIT;
1562 if (escapeflag)
1564 if (c == '\"' || c == '\\' || c == '\''
1565 || c == ';' || c == '#' || c == '(' || c == ')'
1566 || c == ',' || c == '.' || c == '`'
1567 || c == '[' || c == ']' || c == '?' || c <= 040
1568 || confusing)
1569 PRINTCHAR ('\\'), confusing = 0;
1571 PRINTCHAR (c);
1574 break;
1576 case Lisp_Cons:
1577 /* If deeper than spec'd depth, print placeholder. */
1578 if (INTEGERP (Vprint_level)
1579 && print_depth > XINT (Vprint_level))
1580 strout ("...", -1, -1, printcharfun);
1581 else if (print_quoted && CONSP (XCDR (obj)) && NILP (XCDR (XCDR (obj)))
1582 && (EQ (XCAR (obj), Qquote)))
1584 PRINTCHAR ('\'');
1585 print_object (XCAR (XCDR (obj)), printcharfun, escapeflag);
1587 else if (print_quoted && CONSP (XCDR (obj)) && NILP (XCDR (XCDR (obj)))
1588 && (EQ (XCAR (obj), Qfunction)))
1590 PRINTCHAR ('#');
1591 PRINTCHAR ('\'');
1592 print_object (XCAR (XCDR (obj)), printcharfun, escapeflag);
1594 else if (print_quoted && CONSP (XCDR (obj)) && NILP (XCDR (XCDR (obj)))
1595 && ((EQ (XCAR (obj), Qbackquote))))
1597 print_object (XCAR (obj), printcharfun, 0);
1598 new_backquote_output++;
1599 print_object (XCAR (XCDR (obj)), printcharfun, escapeflag);
1600 new_backquote_output--;
1602 else if (print_quoted && CONSP (XCDR (obj)) && NILP (XCDR (XCDR (obj)))
1603 && new_backquote_output
1604 && ((EQ (XCAR (obj), Qbackquote)
1605 || EQ (XCAR (obj), Qcomma)
1606 || EQ (XCAR (obj), Qcomma_at)
1607 || EQ (XCAR (obj), Qcomma_dot))))
1609 print_object (XCAR (obj), printcharfun, 0);
1610 new_backquote_output--;
1611 print_object (XCAR (XCDR (obj)), printcharfun, escapeflag);
1612 new_backquote_output++;
1614 else
1616 PRINTCHAR ('(');
1619 EMACS_INT print_length;
1620 int i;
1621 Lisp_Object halftail = obj;
1623 /* Negative values of print-length are invalid in CL.
1624 Treat them like nil, as CMUCL does. */
1625 if (NATNUMP (Vprint_length))
1626 print_length = XFASTINT (Vprint_length);
1627 else
1628 print_length = 0;
1630 i = 0;
1631 while (CONSP (obj))
1633 /* Detect circular list. */
1634 if (NILP (Vprint_circle))
1636 /* Simple but imcomplete way. */
1637 if (i != 0 && EQ (obj, halftail))
1639 sprintf (buf, " . #%d", i / 2);
1640 strout (buf, -1, -1, printcharfun);
1641 goto end_of_list;
1644 else
1646 /* With the print-circle feature. */
1647 if (i != 0)
1649 Lisp_Object num = Fgethash (obj, Vprint_number_table, Qnil);
1650 if (INTEGERP (num))
1652 strout (" . ", 3, 3, printcharfun);
1653 print_object (obj, printcharfun, escapeflag);
1654 goto end_of_list;
1659 if (i++)
1660 PRINTCHAR (' ');
1662 if (print_length && i > print_length)
1664 strout ("...", 3, 3, printcharfun);
1665 goto end_of_list;
1668 print_object (XCAR (obj), printcharfun, escapeflag);
1670 obj = XCDR (obj);
1671 if (!(i & 1))
1672 halftail = XCDR (halftail);
1676 /* OBJ non-nil here means it's the end of a dotted list. */
1677 if (!NILP (obj))
1679 strout (" . ", 3, 3, printcharfun);
1680 print_object (obj, printcharfun, escapeflag);
1683 end_of_list:
1684 PRINTCHAR (')');
1686 break;
1688 case Lisp_Vectorlike:
1689 if (PROCESSP (obj))
1691 if (escapeflag)
1693 strout ("#<process ", -1, -1, printcharfun);
1694 print_string (XPROCESS (obj)->name, printcharfun);
1695 PRINTCHAR ('>');
1697 else
1698 print_string (XPROCESS (obj)->name, printcharfun);
1700 else if (BOOL_VECTOR_P (obj))
1702 register int i;
1703 register unsigned char c;
1704 struct gcpro gcpro1;
1705 EMACS_INT size_in_chars
1706 = ((XBOOL_VECTOR (obj)->size + BOOL_VECTOR_BITS_PER_CHAR - 1)
1707 / BOOL_VECTOR_BITS_PER_CHAR);
1709 GCPRO1 (obj);
1711 PRINTCHAR ('#');
1712 PRINTCHAR ('&');
1713 sprintf (buf, "%"pI"d", XBOOL_VECTOR (obj)->size);
1714 strout (buf, -1, -1, printcharfun);
1715 PRINTCHAR ('\"');
1717 /* Don't print more characters than the specified maximum.
1718 Negative values of print-length are invalid. Treat them
1719 like a print-length of nil. */
1720 if (NATNUMP (Vprint_length)
1721 && XFASTINT (Vprint_length) < size_in_chars)
1722 size_in_chars = XFASTINT (Vprint_length);
1724 for (i = 0; i < size_in_chars; i++)
1726 QUIT;
1727 c = XBOOL_VECTOR (obj)->data[i];
1728 if (c == '\n' && print_escape_newlines)
1730 PRINTCHAR ('\\');
1731 PRINTCHAR ('n');
1733 else if (c == '\f' && print_escape_newlines)
1735 PRINTCHAR ('\\');
1736 PRINTCHAR ('f');
1738 else if (c > '\177')
1740 /* Use octal escapes to avoid encoding issues. */
1741 PRINTCHAR ('\\');
1742 PRINTCHAR ('0' + ((c >> 6) & 3));
1743 PRINTCHAR ('0' + ((c >> 3) & 7));
1744 PRINTCHAR ('0' + (c & 7));
1746 else
1748 if (c == '\"' || c == '\\')
1749 PRINTCHAR ('\\');
1750 PRINTCHAR (c);
1753 PRINTCHAR ('\"');
1755 UNGCPRO;
1757 else if (SUBRP (obj))
1759 strout ("#<subr ", -1, -1, printcharfun);
1760 strout (XSUBR (obj)->symbol_name, -1, -1, printcharfun);
1761 PRINTCHAR ('>');
1763 #ifdef HAVE_XWIDGETS
1764 else if (XXWIDGETP (obj))
1766 strout ("#<xwidget ", -1, -1, printcharfun);
1767 PRINTCHAR ('>');
1769 #endif
1770 else if (WINDOWP (obj))
1772 strout ("#<window ", -1, -1, printcharfun);
1773 sprintf (buf, "%"pI"d", XFASTINT (XWINDOW (obj)->sequence_number));
1774 strout (buf, -1, -1, printcharfun);
1775 if (!NILP (XWINDOW (obj)->buffer))
1777 strout (" on ", -1, -1, printcharfun);
1778 print_string (BVAR (XBUFFER (XWINDOW (obj)->buffer), name), printcharfun);
1780 PRINTCHAR ('>');
1782 else if (TERMINALP (obj))
1784 struct terminal *t = XTERMINAL (obj);
1785 strout ("#<terminal ", -1, -1, printcharfun);
1786 sprintf (buf, "%d", t->id);
1787 strout (buf, -1, -1, printcharfun);
1788 if (t->name)
1790 strout (" on ", -1, -1, printcharfun);
1791 strout (t->name, -1, -1, printcharfun);
1793 PRINTCHAR ('>');
1795 else if (HASH_TABLE_P (obj))
1797 struct Lisp_Hash_Table *h = XHASH_TABLE (obj);
1798 int i;
1799 EMACS_INT real_size, size;
1800 #if 0
1801 strout ("#<hash-table", -1, -1, printcharfun);
1802 if (SYMBOLP (h->test))
1804 PRINTCHAR (' ');
1805 PRINTCHAR ('\'');
1806 strout (SDATA (SYMBOL_NAME (h->test)), -1, -1, printcharfun);
1807 PRINTCHAR (' ');
1808 strout (SDATA (SYMBOL_NAME (h->weak)), -1, -1, printcharfun);
1809 PRINTCHAR (' ');
1810 sprintf (buf, "%ld/%ld", (long) h->count,
1811 (long) ASIZE (h->next));
1812 strout (buf, -1, -1, printcharfun);
1814 sprintf (buf, " 0x%lx", (unsigned long) h);
1815 strout (buf, -1, -1, printcharfun);
1816 PRINTCHAR ('>');
1817 #endif
1818 /* Implement a readable output, e.g.:
1819 #s(hash-table size 2 test equal data (k1 v1 k2 v2)) */
1820 /* Always print the size. */
1821 sprintf (buf, "#s(hash-table size %ld",
1822 (long) ASIZE (h->next));
1823 strout (buf, -1, -1, printcharfun);
1825 if (!NILP (h->test))
1827 strout (" test ", -1, -1, printcharfun);
1828 print_object (h->test, printcharfun, escapeflag);
1831 if (!NILP (h->weak))
1833 strout (" weakness ", -1, -1, printcharfun);
1834 print_object (h->weak, printcharfun, escapeflag);
1837 if (!NILP (h->rehash_size))
1839 strout (" rehash-size ", -1, -1, printcharfun);
1840 print_object (h->rehash_size, printcharfun, escapeflag);
1843 if (!NILP (h->rehash_threshold))
1845 strout (" rehash-threshold ", -1, -1, printcharfun);
1846 print_object (h->rehash_threshold, printcharfun, escapeflag);
1849 strout (" data ", -1, -1, printcharfun);
1851 /* Print the data here as a plist. */
1852 real_size = HASH_TABLE_SIZE (h);
1853 size = real_size;
1855 /* Don't print more elements than the specified maximum. */
1856 if (NATNUMP (Vprint_length)
1857 && XFASTINT (Vprint_length) < size)
1858 size = XFASTINT (Vprint_length);
1860 PRINTCHAR ('(');
1861 for (i = 0; i < size; i++)
1862 if (!NILP (HASH_HASH (h, i)))
1864 if (i) PRINTCHAR (' ');
1865 print_object (HASH_KEY (h, i), printcharfun, escapeflag);
1866 PRINTCHAR (' ');
1867 print_object (HASH_VALUE (h, i), printcharfun, escapeflag);
1870 if (size < real_size)
1871 strout (" ...", 4, 4, printcharfun);
1873 PRINTCHAR (')');
1874 PRINTCHAR (')');
1877 else if (BUFFERP (obj))
1879 if (NILP (BVAR (XBUFFER (obj), name)))
1880 strout ("#<killed buffer>", -1, -1, printcharfun);
1881 else if (escapeflag)
1883 strout ("#<buffer ", -1, -1, printcharfun);
1884 print_string (BVAR (XBUFFER (obj), name), printcharfun);
1885 PRINTCHAR ('>');
1887 else
1888 print_string (BVAR (XBUFFER (obj), name), printcharfun);
1890 else if (WINDOW_CONFIGURATIONP (obj))
1892 strout ("#<window-configuration>", -1, -1, printcharfun);
1894 else if (FRAMEP (obj))
1896 strout ((FRAME_LIVE_P (XFRAME (obj))
1897 ? "#<frame " : "#<dead frame "),
1898 -1, -1, printcharfun);
1899 print_string (XFRAME (obj)->name, printcharfun);
1900 sprintf (buf, " %p", XFRAME (obj));
1901 strout (buf, -1, -1, printcharfun);
1902 PRINTCHAR ('>');
1904 else if (FONTP (obj))
1906 EMACS_INT i;
1908 if (! FONT_OBJECT_P (obj))
1910 if (FONT_SPEC_P (obj))
1911 strout ("#<font-spec", -1, -1, printcharfun);
1912 else
1913 strout ("#<font-entity", -1, -1, printcharfun);
1914 for (i = 0; i < FONT_SPEC_MAX; i++)
1916 PRINTCHAR (' ');
1917 if (i < FONT_WEIGHT_INDEX || i > FONT_WIDTH_INDEX)
1918 print_object (AREF (obj, i), printcharfun, escapeflag);
1919 else
1920 print_object (font_style_symbolic (obj, i, 0),
1921 printcharfun, escapeflag);
1924 else
1926 strout ("#<font-object ", -1, -1, printcharfun);
1927 print_object (AREF (obj, FONT_NAME_INDEX), printcharfun,
1928 escapeflag);
1930 PRINTCHAR ('>');
1932 else
1934 EMACS_INT size = ASIZE (obj);
1935 if (COMPILEDP (obj))
1937 PRINTCHAR ('#');
1938 size &= PSEUDOVECTOR_SIZE_MASK;
1940 if (CHAR_TABLE_P (obj) || SUB_CHAR_TABLE_P (obj))
1942 /* We print a char-table as if it were a vector,
1943 lumping the parent and default slots in with the
1944 character slots. But we add #^ as a prefix. */
1946 /* Make each lowest sub_char_table start a new line.
1947 Otherwise we'll make a line extremely long, which
1948 results in slow redisplay. */
1949 if (SUB_CHAR_TABLE_P (obj)
1950 && XINT (XSUB_CHAR_TABLE (obj)->depth) == 3)
1951 PRINTCHAR ('\n');
1952 PRINTCHAR ('#');
1953 PRINTCHAR ('^');
1954 if (SUB_CHAR_TABLE_P (obj))
1955 PRINTCHAR ('^');
1956 size &= PSEUDOVECTOR_SIZE_MASK;
1958 if (size & PSEUDOVECTOR_FLAG)
1959 goto badtype;
1961 PRINTCHAR ('[');
1963 register int i;
1964 register Lisp_Object tem;
1965 EMACS_INT real_size = size;
1967 /* Don't print more elements than the specified maximum. */
1968 if (NATNUMP (Vprint_length)
1969 && XFASTINT (Vprint_length) < size)
1970 size = XFASTINT (Vprint_length);
1972 for (i = 0; i < size; i++)
1974 if (i) PRINTCHAR (' ');
1975 tem = XVECTOR (obj)->contents[i];
1976 print_object (tem, printcharfun, escapeflag);
1978 if (size < real_size)
1979 strout (" ...", 4, 4, printcharfun);
1981 PRINTCHAR (']');
1983 break;
1985 case Lisp_Misc:
1986 switch (XMISCTYPE (obj))
1988 case Lisp_Misc_Marker:
1989 strout ("#<marker ", -1, -1, printcharfun);
1990 /* Do you think this is necessary? */
1991 if (XMARKER (obj)->insertion_type != 0)
1992 strout ("(moves after insertion) ", -1, -1, printcharfun);
1993 if (! XMARKER (obj)->buffer)
1994 strout ("in no buffer", -1, -1, printcharfun);
1995 else
1997 sprintf (buf, "at %"pI"d", marker_position (obj));
1998 strout (buf, -1, -1, printcharfun);
1999 strout (" in ", -1, -1, printcharfun);
2000 print_string (BVAR (XMARKER (obj)->buffer, name), printcharfun);
2002 PRINTCHAR ('>');
2003 break;
2005 case Lisp_Misc_Overlay:
2006 strout ("#<overlay ", -1, -1, printcharfun);
2007 if (! XMARKER (OVERLAY_START (obj))->buffer)
2008 strout ("in no buffer", -1, -1, printcharfun);
2009 else
2011 sprintf (buf, "from %"pI"d to %"pI"d in ",
2012 marker_position (OVERLAY_START (obj)),
2013 marker_position (OVERLAY_END (obj)));
2014 strout (buf, -1, -1, printcharfun);
2015 print_string (BVAR (XMARKER (OVERLAY_START (obj))->buffer, name),
2016 printcharfun);
2018 PRINTCHAR ('>');
2019 break;
2021 /* Remaining cases shouldn't happen in normal usage, but let's print
2022 them anyway for the benefit of the debugger. */
2023 case Lisp_Misc_Free:
2024 strout ("#<misc free cell>", -1, -1, printcharfun);
2025 break;
2027 case Lisp_Misc_Save_Value:
2028 strout ("#<save_value ", -1, -1, printcharfun);
2029 sprintf(buf, "ptr=%p int=%"pD"d",
2030 XSAVE_VALUE (obj)->pointer,
2031 XSAVE_VALUE (obj)->integer);
2032 strout (buf, -1, -1, printcharfun);
2033 PRINTCHAR ('>');
2034 break;
2036 default:
2037 goto badtype;
2039 break;
2041 default:
2042 badtype:
2044 /* We're in trouble if this happens!
2045 Probably should just abort () */
2046 strout ("#<EMACS BUG: INVALID DATATYPE ", -1, -1, printcharfun);
2047 if (MISCP (obj))
2048 sprintf (buf, "(MISC 0x%04x)", (int) XMISCTYPE (obj));
2049 else if (VECTORLIKEP (obj))
2050 sprintf (buf, "(PVEC 0x%08lx)", (unsigned long) ASIZE (obj));
2051 else
2052 sprintf (buf, "(0x%02x)", (int) XTYPE (obj));
2053 strout (buf, -1, -1, printcharfun);
2054 strout (" Save your buffers immediately and please report this bug>",
2055 -1, -1, printcharfun);
2059 print_depth--;
2063 /* Print a description of INTERVAL using PRINTCHARFUN.
2064 This is part of printing a string that has text properties. */
2066 void
2067 print_interval (INTERVAL interval, Lisp_Object printcharfun)
2069 if (NILP (interval->plist))
2070 return;
2071 PRINTCHAR (' ');
2072 print_object (make_number (interval->position), printcharfun, 1);
2073 PRINTCHAR (' ');
2074 print_object (make_number (interval->position + LENGTH (interval)),
2075 printcharfun, 1);
2076 PRINTCHAR (' ');
2077 print_object (interval->plist, printcharfun, 1);
2081 void
2082 syms_of_print (void)
2084 DEFSYM (Qtemp_buffer_setup_hook, "temp-buffer-setup-hook");
2086 DEFVAR_LISP ("standard-output", Vstandard_output,
2087 doc: /* Output stream `print' uses by default for outputting a character.
2088 This may be any function of one argument.
2089 It may also be a buffer (output is inserted before point)
2090 or a marker (output is inserted and the marker is advanced)
2091 or the symbol t (output appears in the echo area). */);
2092 Vstandard_output = Qt;
2093 DEFSYM (Qstandard_output, "standard-output");
2095 DEFVAR_LISP ("float-output-format", Vfloat_output_format,
2096 doc: /* The format descriptor string used to print floats.
2097 This is a %-spec like those accepted by `printf' in C,
2098 but with some restrictions. It must start with the two characters `%.'.
2099 After that comes an integer precision specification,
2100 and then a letter which controls the format.
2101 The letters allowed are `e', `f' and `g'.
2102 Use `e' for exponential notation \"DIG.DIGITSeEXPT\"
2103 Use `f' for decimal point notation \"DIGITS.DIGITS\".
2104 Use `g' to choose the shorter of those two formats for the number at hand.
2105 The precision in any of these cases is the number of digits following
2106 the decimal point. With `f', a precision of 0 means to omit the
2107 decimal point. 0 is not allowed with `e' or `g'.
2109 A value of nil means to use the shortest notation
2110 that represents the number without losing information. */);
2111 Vfloat_output_format = Qnil;
2112 DEFSYM (Qfloat_output_format, "float-output-format");
2114 DEFVAR_LISP ("print-length", Vprint_length,
2115 doc: /* Maximum length of list to print before abbreviating.
2116 A value of nil means no limit. See also `eval-expression-print-length'. */);
2117 Vprint_length = Qnil;
2119 DEFVAR_LISP ("print-level", Vprint_level,
2120 doc: /* Maximum depth of list nesting to print before abbreviating.
2121 A value of nil means no limit. See also `eval-expression-print-level'. */);
2122 Vprint_level = Qnil;
2124 DEFVAR_BOOL ("print-escape-newlines", print_escape_newlines,
2125 doc: /* Non-nil means print newlines in strings as `\\n'.
2126 Also print formfeeds as `\\f'. */);
2127 print_escape_newlines = 0;
2129 DEFVAR_BOOL ("print-escape-nonascii", print_escape_nonascii,
2130 doc: /* Non-nil means print unibyte non-ASCII chars in strings as \\OOO.
2131 \(OOO is the octal representation of the character code.)
2132 Only single-byte characters are affected, and only in `prin1'.
2133 When the output goes in a multibyte buffer, this feature is
2134 enabled regardless of the value of the variable. */);
2135 print_escape_nonascii = 0;
2137 DEFVAR_BOOL ("print-escape-multibyte", print_escape_multibyte,
2138 doc: /* Non-nil means print multibyte characters in strings as \\xXXXX.
2139 \(XXXX is the hex representation of the character code.)
2140 This affects only `prin1'. */);
2141 print_escape_multibyte = 0;
2143 DEFVAR_BOOL ("print-quoted", print_quoted,
2144 doc: /* Non-nil means print quoted forms with reader syntax.
2145 I.e., (quote foo) prints as 'foo, (function foo) as #'foo. */);
2146 print_quoted = 0;
2148 DEFVAR_LISP ("print-gensym", Vprint_gensym,
2149 doc: /* Non-nil means print uninterned symbols so they will read as uninterned.
2150 I.e., the value of (make-symbol \"foobar\") prints as #:foobar.
2151 When the uninterned symbol appears within a recursive data structure,
2152 and the symbol appears more than once, in addition use the #N# and #N=
2153 constructs as needed, so that multiple references to the same symbol are
2154 shared once again when the text is read back. */);
2155 Vprint_gensym = Qnil;
2157 DEFVAR_LISP ("print-circle", Vprint_circle,
2158 doc: /* *Non-nil means print recursive structures using #N= and #N# syntax.
2159 If nil, printing proceeds recursively and may lead to
2160 `max-lisp-eval-depth' being exceeded or an error may occur:
2161 \"Apparently circular structure being printed.\" Also see
2162 `print-length' and `print-level'.
2163 If non-nil, shared substructures anywhere in the structure are printed
2164 with `#N=' before the first occurrence (in the order of the print
2165 representation) and `#N#' in place of each subsequent occurrence,
2166 where N is a positive decimal integer. */);
2167 Vprint_circle = Qnil;
2169 DEFVAR_LISP ("print-continuous-numbering", Vprint_continuous_numbering,
2170 doc: /* *Non-nil means number continuously across print calls.
2171 This affects the numbers printed for #N= labels and #M# references.
2172 See also `print-circle', `print-gensym', and `print-number-table'.
2173 This variable should not be set with `setq'; bind it with a `let' instead. */);
2174 Vprint_continuous_numbering = Qnil;
2176 DEFVAR_LISP ("print-number-table", Vprint_number_table,
2177 doc: /* A vector used internally to produce `#N=' labels and `#N#' references.
2178 The Lisp printer uses this vector to detect Lisp objects referenced more
2179 than once.
2181 When you bind `print-continuous-numbering' to t, you should probably
2182 also bind `print-number-table' to nil. This ensures that the value of
2183 `print-number-table' can be garbage-collected once the printing is
2184 done. If all elements of `print-number-table' are nil, it means that
2185 the printing done so far has not found any shared structure or objects
2186 that need to be recorded in the table. */);
2187 Vprint_number_table = Qnil;
2189 DEFVAR_LISP ("print-charset-text-property", Vprint_charset_text_property,
2190 doc: /* A flag to control printing of `charset' text property on printing a string.
2191 The value must be nil, t, or `default'.
2193 If the value is nil, don't print the text property `charset'.
2195 If the value is t, always print the text property `charset'.
2197 If the value is `default', print the text property `charset' only when
2198 the value is different from what is guessed in the current charset
2199 priorities. */);
2200 Vprint_charset_text_property = Qdefault;
2202 /* prin1_to_string_buffer initialized in init_buffer_once in buffer.c */
2203 staticpro (&Vprin1_to_string_buffer);
2205 defsubr (&Sprin1);
2206 defsubr (&Sprin1_to_string);
2207 defsubr (&Serror_message_string);
2208 defsubr (&Sprinc);
2209 defsubr (&Sprint);
2210 defsubr (&Sterpri);
2211 defsubr (&Swrite_char);
2212 defsubr (&Sexternal_debugging_output);
2213 #ifdef WITH_REDIRECT_DEBUGGING_OUTPUT
2214 defsubr (&Sredirect_debugging_output);
2215 #endif
2217 DEFSYM (Qexternal_debugging_output, "external-debugging-output");
2218 DEFSYM (Qprint_escape_newlines, "print-escape-newlines");
2219 DEFSYM (Qprint_escape_multibyte, "print-escape-multibyte");
2220 DEFSYM (Qprint_escape_nonascii, "print-escape-nonascii");
2222 print_prune_charset_plist = Qnil;
2223 staticpro (&print_prune_charset_plist);