(move_it_in_display_line_to): Make type consistent with declaration.
[bpt/emacs.git] / src / print.c
CommitLineData
38010d50 1/* Lisp object printing and output streams.
9dffd511
RS
2 Copyright (C) 1985, 86, 88, 93, 94, 95, 97, 1998
3 Free Software Foundation, Inc.
38010d50
JB
4
5This file is part of GNU Emacs.
6
7GNU Emacs is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
4746118a 9the Free Software Foundation; either version 2, or (at your option)
38010d50
JB
10any later version.
11
12GNU Emacs is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU Emacs; see the file COPYING. If not, write to
3b7ad313
EN
19the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA. */
38010d50
JB
21
22
18160b98 23#include <config.h>
38010d50 24#include <stdio.h>
38010d50 25#include "lisp.h"
38010d50 26#include "buffer.h"
087e3c46 27#include "charset.h"
0137dbf7 28#include "frame.h"
38010d50
JB
29#include "window.h"
30#include "process.h"
31#include "dispextern.h"
32#include "termchar.h"
077d751f 33#include "keyboard.h"
38010d50 34
7651e1f5
RS
35#ifdef USE_TEXT_PROPERTIES
36#include "intervals.h"
37#endif
38
38010d50
JB
39Lisp_Object Vstandard_output, Qstandard_output;
40
d9c21094
RS
41Lisp_Object Qtemp_buffer_setup_hook;
42
2f100b5c
EN
43/* These are used to print like we read. */
44extern Lisp_Object Qbackquote, Qcomma, Qcomma_at, Qcomma_dot, Qfunction;
45
38010d50
JB
46#ifdef LISP_FLOAT_TYPE
47Lisp_Object Vfloat_output_format, Qfloat_output_format;
f356c3fb
PE
48
49/* Work around a problem that happens because math.h on hpux 7
50 defines two static variables--which, in Emacs, are not really static,
51 because `static' is defined as nothing. The problem is that they are
52 defined both here and in lread.c.
53 These macros prevent the name conflict. */
54#if defined (HPUX) && !defined (HPUX8)
55#define _MAXLDBL print_maxldbl
56#define _NMAXLDBL print_nmaxldbl
57#endif
58
59#include <math.h>
60
61#if STDC_HEADERS
62#include <float.h>
63#include <stdlib.h>
64#endif
65
66/* Default to values appropriate for IEEE floating point. */
67#ifndef FLT_RADIX
68#define FLT_RADIX 2
69#endif
70#ifndef DBL_MANT_DIG
71#define DBL_MANT_DIG 53
72#endif
73#ifndef DBL_DIG
74#define DBL_DIG 15
75#endif
b0a1044b
PE
76#ifndef DBL_MIN
77#define DBL_MIN 2.2250738585072014e-308
78#endif
79
80#ifdef DBL_MIN_REPLACEMENT
81#undef DBL_MIN
82#define DBL_MIN DBL_MIN_REPLACEMENT
83#endif
f356c3fb
PE
84
85/* Define DOUBLE_DIGITS_BOUND, an upper bound on the number of decimal digits
86 needed to express a float without losing information.
87 The general-case formula is valid for the usual case, IEEE floating point,
88 but many compilers can't optimize the formula to an integer constant,
89 so make a special case for it. */
90#if FLT_RADIX == 2 && DBL_MANT_DIG == 53
91#define DOUBLE_DIGITS_BOUND 17 /* IEEE floating point */
92#else
93#define DOUBLE_DIGITS_BOUND ((int) ceil (log10 (pow (FLT_RADIX, DBL_MANT_DIG))))
94#endif
95
38010d50
JB
96#endif /* LISP_FLOAT_TYPE */
97
98/* Avoid actual stack overflow in print. */
99int print_depth;
100
ec838c39
RS
101/* Detect most circularities to print finite output. */
102#define PRINT_CIRCLE 200
103Lisp_Object being_printed[PRINT_CIRCLE];
104
6fec5601
RS
105/* When printing into a buffer, first we put the text in this
106 block, then insert it all at once. */
107char *print_buffer;
108
109/* Size allocated in print_buffer. */
110int print_buffer_size;
dc2a0b79 111/* Chars stored in print_buffer. */
6fec5601 112int print_buffer_pos;
dc2a0b79
RS
113/* Bytes stored in print_buffer. */
114int print_buffer_pos_byte;
6fec5601 115
38010d50
JB
116/* Maximum length of list to print in full; noninteger means
117 effectively infinity */
118
119Lisp_Object Vprint_length;
120
121/* Maximum depth of list to print in full; noninteger means
122 effectively infinity. */
123
124Lisp_Object Vprint_level;
125
126/* Nonzero means print newlines in strings as \n. */
127
128int print_escape_newlines;
129
38940e93
RS
130/* Nonzero means to print single-byte non-ascii characters in strings as
131 octal escapes. */
132
133int print_escape_nonascii;
134
835d0be6
RS
135/* Nonzero means to print multibyte characters in strings as hex escapes. */
136
137int print_escape_multibyte;
138
139Lisp_Object Qprint_escape_newlines;
140Lisp_Object Qprint_escape_multibyte, Qprint_escape_nonascii;
141
2f100b5c
EN
142/* Nonzero means print (quote foo) forms as 'foo, etc. */
143
144int print_quoted;
145
e0f69431
RS
146/* Non-nil means print #: before uninterned symbols.
147 Neither t nor nil means so that and don't clear Vprint_gensym_alist
148 on entry to and exit from print functions. */
081e0581 149
e0f69431 150Lisp_Object Vprint_gensym;
081e0581
EN
151
152/* Association list of certain objects that are `eq' in the form being
153 printed and which should be `eq' when read back in, using the #n=object
154 and #n# reader forms. Each element has the form (object . n). */
155
e0f69431 156Lisp_Object Vprint_gensym_alist;
2f100b5c 157
5259c737 158/* Nonzero means print newline to stdout before next minibuffer message.
38010d50
JB
159 Defined in xdisp.c */
160
161extern int noninteractive_need_newline;
5259c737 162
aec2b95b
RS
163extern int minibuffer_auto_raise;
164
38010d50
JB
165#ifdef MAX_PRINT_CHARS
166static int print_chars;
167static int max_print;
168#endif /* MAX_PRINT_CHARS */
7651e1f5
RS
169
170void print_interval ();
38010d50 171
38010d50 172\f
eb8c3be9 173/* Low level output routines for characters and strings */
38010d50
JB
174
175/* Lisp functions to do output using a stream
081e0581
EN
176 must have the stream in a variable called printcharfun
177 and must start with PRINTPREPARE, end with PRINTFINISH,
178 and use PRINTDECLARE to declare common variables.
179 Use PRINTCHAR to output one character,
0788646c
GM
180 or call strout to output a block of characters. */
181
182#define PRINTDECLARE \
183 struct buffer *old = current_buffer; \
184 int old_point = -1, start_point; \
185 int old_point_byte, start_point_byte; \
186 int specpdl_count = specpdl_ptr - specpdl; \
187 int free_print_buffer = 0; \
188 int multibyte = !NILP (current_buffer->enable_multibyte_characters); \
081e0581
EN
189 Lisp_Object original
190
0788646c
GM
191#define PRINTPREPARE \
192 original = printcharfun; \
193 if (NILP (printcharfun)) printcharfun = Qt; \
194 if (BUFFERP (printcharfun)) \
195 { \
196 if (XBUFFER (printcharfun) != current_buffer) \
197 Fset_buffer (printcharfun); \
198 printcharfun = Qnil; \
199 } \
200 if (MARKERP (printcharfun)) \
201 { \
202 if (!(XMARKER (original)->buffer)) \
203 error ("Marker does not point anywhere"); \
204 if (XMARKER (original)->buffer != current_buffer) \
205 set_buffer_internal (XMARKER (original)->buffer); \
206 old_point = PT; \
207 old_point_byte = PT_BYTE; \
208 SET_PT_BOTH (marker_position (printcharfun), \
209 marker_byte_position (printcharfun)); \
210 start_point = PT; \
211 start_point_byte = PT_BYTE; \
212 printcharfun = Qnil; \
213 } \
214 if (NILP (printcharfun)) \
215 { \
216 Lisp_Object string; \
217 if (NILP (current_buffer->enable_multibyte_characters) \
218 && ! print_escape_multibyte) \
219 specbind (Qprint_escape_multibyte, Qt); \
220 if (! NILP (current_buffer->enable_multibyte_characters) \
221 && ! print_escape_nonascii) \
222 specbind (Qprint_escape_nonascii, Qt); \
223 if (print_buffer != 0) \
224 { \
225 string = make_string_from_bytes (print_buffer, \
226 print_buffer_pos, \
227 print_buffer_pos_byte); \
228 record_unwind_protect (print_unwind, string); \
229 } \
230 else \
231 { \
232 print_buffer_size = 1000; \
233 print_buffer = (char *) xmalloc (print_buffer_size); \
234 free_print_buffer = 1; \
235 } \
236 print_buffer_pos = 0; \
237 print_buffer_pos_byte = 0; \
238 } \
239 if (EQ (printcharfun, Qt)) \
240 setup_echo_area_for_printing (multibyte); \
241 if (!CONSP (Vprint_gensym)) \
e0f69431 242 Vprint_gensym_alist = Qnil
38010d50 243
8a2ab0c6
RS
244#define PRINTFINISH \
245 if (NILP (printcharfun)) \
246 { \
247 if (print_buffer_pos != print_buffer_pos_byte \
248 && NILP (current_buffer->enable_multibyte_characters)) \
249 { \
250 unsigned char *temp \
251 = (unsigned char *) alloca (print_buffer_pos + 1); \
252 copy_text (print_buffer, temp, print_buffer_pos_byte, \
253 1, 0); \
254 insert_1_both (temp, print_buffer_pos, \
255 print_buffer_pos, 0, 1, 0); \
256 } \
257 else \
258 insert_1_both (print_buffer, print_buffer_pos, \
259 print_buffer_pos_byte, 0, 1, 0); \
260 } \
261 if (free_print_buffer) \
262 { \
263 xfree (print_buffer); \
264 print_buffer = 0; \
265 } \
266 unbind_to (specpdl_count, Qnil); \
267 if (MARKERP (original)) \
268 set_marker_both (original, Qnil, PT, PT_BYTE); \
269 if (old_point >= 0) \
270 SET_PT_BOTH (old_point + (old_point >= start_point \
271 ? PT - start_point : 0), \
6ddd6eee
RS
272 old_point_byte + (old_point_byte >= start_point_byte \
273 ? PT_BYTE - start_point_byte : 0)); \
8a2ab0c6
RS
274 if (old != current_buffer) \
275 set_buffer_internal (old); \
276 if (!CONSP (Vprint_gensym)) \
e0f69431 277 Vprint_gensym_alist = Qnil
38010d50
JB
278
279#define PRINTCHAR(ch) printchar (ch, printcharfun)
280
09eddb56
RS
281/* Nonzero if there is no room to print any more characters
282 so print might as well return right away. */
283
284#define PRINTFULLP() \
285 (EQ (printcharfun, Qt) && !noninteractive \
286 && printbufidx >= FRAME_WIDTH (XFRAME (WINDOW_FRAME (XWINDOW (minibuf_window)))))
287
08e8d297
RS
288/* This is used to restore the saved contents of print_buffer
289 when there is a recursive call to print. */
0788646c 290
08e8d297
RS
291static Lisp_Object
292print_unwind (saved_text)
293 Lisp_Object saved_text;
294{
295 bcopy (XSTRING (saved_text)->data, print_buffer, XSTRING (saved_text)->size);
296}
297
0788646c
GM
298
299/* Print character CH using method FUN. FUN nil means print to
300 print_buffer. FUN t means print to echo area or stdout if
301 non-interactive. If FUN is neither nil nor t, call FUN with CH as
302 argument. */
38010d50
JB
303
304static void
305printchar (ch, fun)
087e3c46 306 unsigned int ch;
38010d50
JB
307 Lisp_Object fun;
308{
38010d50
JB
309#ifdef MAX_PRINT_CHARS
310 if (max_print)
311 print_chars++;
312#endif /* MAX_PRINT_CHARS */
38010d50 313
0788646c
GM
314 if (!NILP (fun) && !EQ (fun, Qt))
315 call1 (fun, make_number (ch));
316 else
38010d50 317 {
087e3c46
KH
318 unsigned char work[4], *str;
319 int len = CHAR_STRING (ch, work, str);
0788646c 320
09eddb56 321 QUIT;
0788646c
GM
322
323 if (NILP (fun))
9a4d01d8 324 {
0788646c
GM
325 if (print_buffer_pos_byte + len >= print_buffer_size)
326 print_buffer = (char *) xrealloc (print_buffer,
327 print_buffer_size *= 2);
328 bcopy (str, print_buffer + print_buffer_pos_byte, len);
329 print_buffer_pos += 1;
330 print_buffer_pos_byte += len;
9a4d01d8 331 }
0788646c 332 else if (noninteractive)
1134b854 333 {
0788646c
GM
334 fwrite (str, 1, len, stdout);
335 noninteractive_need_newline = 1;
1134b854 336 }
0788646c 337 else
d366d2e4 338 {
0788646c
GM
339 int multibyte_p
340 = !NILP (current_buffer->enable_multibyte_characters);
341
342 if (!message_buf_print)
343 setup_echo_area_for_printing (multibyte_p);
344
345 insert_char (ch);
346 message_dolog (str, len, 0, multibyte_p);
d366d2e4 347 }
38010d50 348 }
38010d50
JB
349}
350
0788646c
GM
351
352/* Output SIZE characters, SIZE_BYTE bytes from string PTR using
353 method PRINTCHARFUN. If SIZE < 0, use the string length of PTR for
354 both SIZE and SIZE_BYTE. PRINTCHARFUN nil means output to
355 print_buffer. PRINTCHARFUN t means output to the echo area or to
356 stdout if non-interactive. If neither nil nor t, call Lisp
357 function PRINTCHARFUN for each character printed. MULTIBYTE
358 non-zero means PTR contains multibyte characters. */
359
38010d50 360static void
dc2a0b79 361strout (ptr, size, size_byte, printcharfun, multibyte)
38010d50 362 char *ptr;
dc2a0b79 363 int size, size_byte;
38010d50 364 Lisp_Object printcharfun;
dc2a0b79 365 int multibyte;
38010d50 366{
087e3c46 367 if (size < 0)
dc2a0b79 368 size_byte = size = strlen (ptr);
087e3c46 369
0788646c 370 if (NILP (printcharfun))
38010d50 371 {
dc2a0b79 372 if (print_buffer_pos_byte + size_byte > print_buffer_size)
6fec5601 373 {
dc2a0b79 374 print_buffer_size = print_buffer_size * 2 + size_byte;
6fec5601
RS
375 print_buffer = (char *) xrealloc (print_buffer,
376 print_buffer_size);
377 }
dc2a0b79 378 bcopy (ptr, print_buffer + print_buffer_pos_byte, size_byte);
6fec5601 379 print_buffer_pos += size;
dc2a0b79 380 print_buffer_pos_byte += size_byte;
6fec5601 381
38010d50
JB
382#ifdef MAX_PRINT_CHARS
383 if (max_print)
6fec5601 384 print_chars += size;
38010d50 385#endif /* MAX_PRINT_CHARS */
38010d50 386 }
0788646c 387 else if (noninteractive)
38010d50 388 {
0788646c
GM
389 fwrite (ptr, 1, size_byte, stdout);
390 noninteractive_need_newline = 1;
391 }
392 else if (EQ (printcharfun, Qt))
393 {
394 /* Output to echo area. We're trying to avoid a little overhead
395 here, that's the reason we don't call printchar to do the
396 job. */
397 int i;
398 int multibyte_p
399 = !NILP (current_buffer->enable_multibyte_characters);
400
401 if (!message_buf_print)
402 setup_echo_area_for_printing (multibyte_p);
403
404 message_dolog (ptr, size_byte, 0, multibyte_p);
405
406 if (size == size_byte)
38010d50 407 {
0788646c
GM
408 for (i = 0; i < size; ++i)
409 insert_char (*ptr++);
38010d50 410 }
0788646c 411 else
38010d50 412 {
0788646c
GM
413 int len;
414 for (i = 0; i < size_byte; i += len)
aec2b95b 415 {
0788646c
GM
416 int ch = STRING_CHAR_AND_LENGTH (ptr + i, size_byte - i, len);
417 insert_char (ch);
aec2b95b 418 }
38010d50 419 }
0788646c
GM
420
421#ifdef MAX_PRINT_CHARS
422 if (max_print)
423 print_chars += size;
424#endif /* MAX_PRINT_CHARS */
425 }
426 else
427 {
428 /* PRINTCHARFUN is a Lisp function. */
429 int i = 0;
38010d50 430
0788646c 431 if (size == size_byte)
4ad8bb20 432 {
0788646c 433 while (i < size_byte)
4ad8bb20 434 {
0788646c
GM
435 int ch = ptr[i++];
436 PRINTCHAR (ch);
4ad8bb20 437 }
4ad8bb20 438 }
0788646c 439 else
087e3c46 440 {
0788646c
GM
441 while (i < size_byte)
442 {
443 /* Here, we must convert each multi-byte form to the
444 corresponding character code before handing it to
445 PRINTCHAR. */
446 int len;
447 int ch = STRING_CHAR_AND_LENGTH (ptr + i, size_byte - i, len);
448 PRINTCHAR (ch);
449 i += len;
450 }
087e3c46 451 }
38010d50 452 }
38010d50
JB
453}
454
455/* Print the contents of a string STRING using PRINTCHARFUN.
ed2c35ef
RS
456 It isn't safe to use strout in many cases,
457 because printing one char can relocate. */
38010d50 458
dc2a0b79 459static void
38010d50
JB
460print_string (string, printcharfun)
461 Lisp_Object string;
462 Lisp_Object printcharfun;
463{
6fec5601 464 if (EQ (printcharfun, Qt) || NILP (printcharfun))
375fcc09
KH
465 {
466 int chars;
467
468 if (STRING_MULTIBYTE (string))
469 chars = XSTRING (string)->size;
470 else if (EQ (printcharfun, Qt)
471 ? ! NILP (buffer_defaults.enable_multibyte_characters)
472 : ! NILP (current_buffer->enable_multibyte_characters))
473 chars = multibyte_chars_in_text (XSTRING (string)->data,
474 STRING_BYTES (XSTRING (string)));
475 else
476 chars = STRING_BYTES (XSTRING (string));
477
478 /* strout is safe for output to a frame (echo area) or to print_buffer. */
479 strout (XSTRING (string)->data,
480 chars, STRING_BYTES (XSTRING (string)),
481 printcharfun, STRING_MULTIBYTE (string));
482 }
38010d50
JB
483 else
484 {
dc2a0b79
RS
485 /* Otherwise, string may be relocated by printing one char.
486 So re-fetch the string address for each character. */
38010d50
JB
487 int i;
488 int size = XSTRING (string)->size;
fc932ac6 489 int size_byte = STRING_BYTES (XSTRING (string));
38010d50
JB
490 struct gcpro gcpro1;
491 GCPRO1 (string);
dc2a0b79
RS
492 if (size == size_byte)
493 for (i = 0; i < size; i++)
494 PRINTCHAR (XSTRING (string)->data[i]);
495 else
496 for (i = 0; i < size_byte; i++)
497 {
498 /* Here, we must convert each multi-byte form to the
499 corresponding character code before handing it to PRINTCHAR. */
500 int len;
765fe1d0
KH
501 int ch = STRING_CHAR_AND_LENGTH (XSTRING (string)->data + i,
502 size_byte - i, len);
da1ad4e7
KH
503 if (!CHAR_VALID_P (ch, 0))
504 {
505 ch = XSTRING (string)->data[i];
506 len = 1;
507 }
dc2a0b79
RS
508 PRINTCHAR (ch);
509 i += len;
510 }
38010d50
JB
511 UNGCPRO;
512 }
513}
514\f
515DEFUN ("write-char", Fwrite_char, Swrite_char, 1, 2, 0,
3738a371 516 "Output character CHARACTER to stream PRINTCHARFUN.\n\
57c9eb68 517PRINTCHARFUN defaults to the value of `standard-output' (which see).")
3738a371
EN
518 (character, printcharfun)
519 Lisp_Object character, printcharfun;
38010d50 520{
081e0581 521 PRINTDECLARE;
38010d50 522
10eebdbb 523 if (NILP (printcharfun))
38010d50 524 printcharfun = Vstandard_output;
3738a371 525 CHECK_NUMBER (character, 0);
38010d50 526 PRINTPREPARE;
3738a371 527 PRINTCHAR (XINT (character));
38010d50 528 PRINTFINISH;
3738a371 529 return character;
38010d50
JB
530}
531
dc2a0b79
RS
532/* Used from outside of print.c to print a block of SIZE
533 single-byte chars at DATA on the default output stream.
38010d50
JB
534 Do not use this on the contents of a Lisp string. */
535
dc22f25e 536void
38010d50
JB
537write_string (data, size)
538 char *data;
539 int size;
540{
081e0581 541 PRINTDECLARE;
38010d50 542 Lisp_Object printcharfun;
38010d50
JB
543
544 printcharfun = Vstandard_output;
545
546 PRINTPREPARE;
dc2a0b79 547 strout (data, size, size, printcharfun, 0);
38010d50
JB
548 PRINTFINISH;
549}
550
dc2a0b79
RS
551/* Used from outside of print.c to print a block of SIZE
552 single-byte chars at DATA on a specified stream PRINTCHARFUN.
38010d50
JB
553 Do not use this on the contents of a Lisp string. */
554
dc22f25e 555void
38010d50
JB
556write_string_1 (data, size, printcharfun)
557 char *data;
558 int size;
559 Lisp_Object printcharfun;
560{
081e0581 561 PRINTDECLARE;
38010d50
JB
562
563 PRINTPREPARE;
dc2a0b79 564 strout (data, size, size, printcharfun, 0);
38010d50
JB
565 PRINTFINISH;
566}
567
568
38010d50
JB
569void
570temp_output_buffer_setup (bufname)
571 char *bufname;
572{
d9c21094 573 int count = specpdl_ptr - specpdl;
38010d50
JB
574 register struct buffer *old = current_buffer;
575 register Lisp_Object buf;
576
d9c21094
RS
577 record_unwind_protect (set_buffer_if_live, Fcurrent_buffer ());
578
38010d50
JB
579 Fset_buffer (Fget_buffer_create (build_string (bufname)));
580
2a1c968a 581 current_buffer->directory = old->directory;
38010d50 582 current_buffer->read_only = Qnil;
c5c6d57c
KH
583 current_buffer->filename = Qnil;
584 current_buffer->undo_list = Qt;
585 current_buffer->overlays_before = Qnil;
586 current_buffer->overlays_after = Qnil;
587 current_buffer->enable_multibyte_characters
588 = buffer_defaults.enable_multibyte_characters;
38010d50 589 Ferase_buffer ();
633307b5 590 XSETBUFFER (buf, current_buffer);
38010d50 591
d9c21094
RS
592 call1 (Vrun_hooks, Qtemp_buffer_setup_hook);
593
594 unbind_to (count, Qnil);
595
596 specbind (Qstandard_output, buf);
38010d50
JB
597}
598
599Lisp_Object
600internal_with_output_to_temp_buffer (bufname, function, args)
601 char *bufname;
dfcf069d 602 Lisp_Object (*function) P_ ((Lisp_Object));
38010d50
JB
603 Lisp_Object args;
604{
605 int count = specpdl_ptr - specpdl;
606 Lisp_Object buf, val;
0ab39c81 607 struct gcpro gcpro1;
38010d50 608
0ab39c81 609 GCPRO1 (args);
38010d50
JB
610 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
611 temp_output_buffer_setup (bufname);
612 buf = Vstandard_output;
0ab39c81 613 UNGCPRO;
38010d50
JB
614
615 val = (*function) (args);
616
0ab39c81 617 GCPRO1 (val);
38010d50 618 temp_output_buffer_show (buf);
0ab39c81 619 UNGCPRO;
38010d50
JB
620
621 return unbind_to (count, val);
622}
623
624DEFUN ("with-output-to-temp-buffer", Fwith_output_to_temp_buffer, Swith_output_to_temp_buffer,
625 1, UNEVALLED, 0,
626 "Bind `standard-output' to buffer BUFNAME, eval BODY, then show that buffer.\n\
627The buffer is cleared out initially, and marked as unmodified when done.\n\
628All output done by BODY is inserted in that buffer by default.\n\
629The buffer is displayed in another window, but not selected.\n\
630The value of the last form in BODY is returned.\n\
d9c21094
RS
631If BODY does not finish normally, the buffer BUFNAME is not displayed.\n\
632\n\
633The hook `temp-buffer-setup-hook' is run before BODY,\n\
634with the buffer BUFNAME temporarily current.\n\
635The hook `temp-buffer-show-hook' is run after the buffer is displayed,\n\
636with the buffer temporarily current, and the window that was used\n\
637to display it temporarily selected.\n\
638\n\
483288d7 639If variable `temp-buffer-show-function' is non-nil, call it at the end\n\
451f7df8
DL
640to get the buffer displayed instead of just displaying the non-selected\n\
641buffer and calling the hook. It gets one argument, the buffer to display.")
38010d50
JB
642 (args)
643 Lisp_Object args;
644{
645 struct gcpro gcpro1;
646 Lisp_Object name;
647 int count = specpdl_ptr - specpdl;
648 Lisp_Object buf, val;
649
650 GCPRO1(args);
651 name = Feval (Fcar (args));
652 UNGCPRO;
653
654 CHECK_STRING (name, 0);
655 temp_output_buffer_setup (XSTRING (name)->data);
656 buf = Vstandard_output;
657
658 val = Fprogn (Fcdr (args));
659
660 temp_output_buffer_show (buf);
661
662 return unbind_to (count, val);
663}
0788646c 664
38010d50
JB
665\f
666static void print ();
667
668DEFUN ("terpri", Fterpri, Sterpri, 0, 1, 0,
57c9eb68
KH
669 "Output a newline to stream PRINTCHARFUN.\n\
670If PRINTCHARFUN is omitted or nil, the value of `standard-output' is used.")
38010d50
JB
671 (printcharfun)
672 Lisp_Object printcharfun;
673{
081e0581 674 PRINTDECLARE;
38010d50 675
10eebdbb 676 if (NILP (printcharfun))
38010d50
JB
677 printcharfun = Vstandard_output;
678 PRINTPREPARE;
679 PRINTCHAR ('\n');
680 PRINTFINISH;
681 return Qt;
682}
683
684DEFUN ("prin1", Fprin1, Sprin1, 1, 2, 0,
685 "Output the printed representation of OBJECT, any Lisp object.\n\
686Quoting characters are printed when needed to make output that `read'\n\
687can handle, whenever this is possible.\n\
57c9eb68 688Output stream is PRINTCHARFUN, or value of `standard-output' (which see).")
3738a371
EN
689 (object, printcharfun)
690 Lisp_Object object, printcharfun;
38010d50 691{
081e0581 692 PRINTDECLARE;
38010d50
JB
693
694#ifdef MAX_PRINT_CHARS
695 max_print = 0;
696#endif /* MAX_PRINT_CHARS */
10eebdbb 697 if (NILP (printcharfun))
38010d50
JB
698 printcharfun = Vstandard_output;
699 PRINTPREPARE;
700 print_depth = 0;
3738a371 701 print (object, printcharfun, 1);
38010d50 702 PRINTFINISH;
3738a371 703 return object;
38010d50
JB
704}
705
706/* a buffer which is used to hold output being built by prin1-to-string */
707Lisp_Object Vprin1_to_string_buffer;
708
709DEFUN ("prin1-to-string", Fprin1_to_string, Sprin1_to_string, 1, 2, 0,
710 "Return a string containing the printed representation of OBJECT,\n\
711any Lisp object. Quoting characters are used when needed to make output\n\
712that `read' can handle, whenever this is possible, unless the optional\n\
713second argument NOESCAPE is non-nil.")
3738a371
EN
714 (object, noescape)
715 Lisp_Object object, noescape;
38010d50 716{
081e0581
EN
717 PRINTDECLARE;
718 Lisp_Object printcharfun;
2a42e8f6
KH
719 struct gcpro gcpro1, gcpro2;
720 Lisp_Object tem;
721
722 /* Save and restore this--we are altering a buffer
723 but we don't want to deactivate the mark just for that.
724 No need for specbind, since errors deactivate the mark. */
725 tem = Vdeactivate_mark;
726 GCPRO2 (object, tem);
38010d50
JB
727
728 printcharfun = Vprin1_to_string_buffer;
729 PRINTPREPARE;
730 print_depth = 0;
3738a371 731 print (object, printcharfun, NILP (noescape));
38010d50
JB
732 /* Make Vprin1_to_string_buffer be the default buffer after PRINTFINSH */
733 PRINTFINISH;
734 set_buffer_internal (XBUFFER (Vprin1_to_string_buffer));
3738a371 735 object = Fbuffer_string ();
38010d50 736
38010d50
JB
737 Ferase_buffer ();
738 set_buffer_internal (old);
2a42e8f6
KH
739
740 Vdeactivate_mark = tem;
38010d50
JB
741 UNGCPRO;
742
3738a371 743 return object;
38010d50
JB
744}
745
746DEFUN ("princ", Fprinc, Sprinc, 1, 2, 0,
747 "Output the printed representation of OBJECT, any Lisp object.\n\
748No quoting characters are used; no delimiters are printed around\n\
749the contents of strings.\n\
57c9eb68 750Output stream is PRINTCHARFUN, or value of standard-output (which see).")
3738a371
EN
751 (object, printcharfun)
752 Lisp_Object object, printcharfun;
38010d50 753{
081e0581 754 PRINTDECLARE;
38010d50 755
10eebdbb 756 if (NILP (printcharfun))
38010d50
JB
757 printcharfun = Vstandard_output;
758 PRINTPREPARE;
759 print_depth = 0;
3738a371 760 print (object, printcharfun, 0);
38010d50 761 PRINTFINISH;
3738a371 762 return object;
38010d50
JB
763}
764
765DEFUN ("print", Fprint, Sprint, 1, 2, 0,
766 "Output the printed representation of OBJECT, with newlines around it.\n\
767Quoting characters are printed when needed to make output that `read'\n\
768can handle, whenever this is possible.\n\
57c9eb68 769Output stream is PRINTCHARFUN, or value of `standard-output' (which see).")
3738a371
EN
770 (object, printcharfun)
771 Lisp_Object object, printcharfun;
38010d50 772{
081e0581 773 PRINTDECLARE;
38010d50
JB
774 struct gcpro gcpro1;
775
776#ifdef MAX_PRINT_CHARS
777 print_chars = 0;
778 max_print = MAX_PRINT_CHARS;
779#endif /* MAX_PRINT_CHARS */
10eebdbb 780 if (NILP (printcharfun))
38010d50 781 printcharfun = Vstandard_output;
3738a371 782 GCPRO1 (object);
38010d50
JB
783 PRINTPREPARE;
784 print_depth = 0;
785 PRINTCHAR ('\n');
3738a371 786 print (object, printcharfun, 1);
38010d50
JB
787 PRINTCHAR ('\n');
788 PRINTFINISH;
789#ifdef MAX_PRINT_CHARS
790 max_print = 0;
791 print_chars = 0;
792#endif /* MAX_PRINT_CHARS */
793 UNGCPRO;
3738a371 794 return object;
38010d50
JB
795}
796
797/* The subroutine object for external-debugging-output is kept here
798 for the convenience of the debugger. */
799Lisp_Object Qexternal_debugging_output;
800
4746118a
JB
801DEFUN ("external-debugging-output", Fexternal_debugging_output, Sexternal_debugging_output, 1, 1, 0,
802 "Write CHARACTER to stderr.\n\
38010d50
JB
803You can call print while debugging emacs, and pass it this function\n\
804to make it write to the debugging output.\n")
4746118a
JB
805 (character)
806 Lisp_Object character;
38010d50
JB
807{
808 CHECK_NUMBER (character, 0);
809 putc (XINT (character), stderr);
cd22039d
RS
810
811#ifdef WINDOWSNT
812 /* Send the output to a debugger (nothing happens if there isn't one). */
813 {
814 char buf[2] = {(char) XINT (character), '\0'};
815 OutputDebugString (buf);
816 }
817#endif
818
38010d50
JB
819 return character;
820}
cf1bb91b
RS
821
822/* This is the interface for debugging printing. */
823
824void
825debug_print (arg)
826 Lisp_Object arg;
827{
828 Fprin1 (arg, Qexternal_debugging_output);
3684eb78 829 fprintf (stderr, "\r\n");
cf1bb91b 830}
38010d50 831\f
113620cc
KH
832DEFUN ("error-message-string", Ferror_message_string, Serror_message_string,
833 1, 1, 0,
834 "Convert an error value (ERROR-SYMBOL . DATA) to an error message.")
835 (obj)
836 Lisp_Object obj;
837{
838 struct buffer *old = current_buffer;
839 Lisp_Object original, printcharfun, value;
840 struct gcpro gcpro1;
841
0872e11f
RS
842 /* If OBJ is (error STRING), just return STRING.
843 That is not only faster, it also avoids the need to allocate
844 space here when the error is due to memory full. */
845 if (CONSP (obj) && EQ (XCONS (obj)->car, Qerror)
846 && CONSP (XCONS (obj)->cdr)
847 && STRINGP (XCONS (XCONS (obj)->cdr)->car)
848 && NILP (XCONS (XCONS (obj)->cdr)->cdr))
849 return XCONS (XCONS (obj)->cdr)->car;
850
dc22f25e 851 print_error_message (obj, Vprin1_to_string_buffer);
113620cc
KH
852
853 set_buffer_internal (XBUFFER (Vprin1_to_string_buffer));
854 value = Fbuffer_string ();
855
856 GCPRO1 (value);
857 Ferase_buffer ();
858 set_buffer_internal (old);
859 UNGCPRO;
860
861 return value;
862}
863
864/* Print an error message for the error DATA
865 onto Lisp output stream STREAM (suitable for the print functions). */
866
dc22f25e 867void
113620cc
KH
868print_error_message (data, stream)
869 Lisp_Object data, stream;
870{
871 Lisp_Object errname, errmsg, file_error, tail;
872 struct gcpro gcpro1;
873 int i;
874
875 errname = Fcar (data);
876
877 if (EQ (errname, Qerror))
878 {
879 data = Fcdr (data);
880 if (!CONSP (data)) data = Qnil;
881 errmsg = Fcar (data);
882 file_error = Qnil;
883 }
884 else
885 {
886 errmsg = Fget (errname, Qerror_message);
887 file_error = Fmemq (Qfile_error,
888 Fget (errname, Qerror_conditions));
889 }
890
891 /* Print an error message including the data items. */
892
893 tail = Fcdr_safe (data);
894 GCPRO1 (tail);
895
896 /* For file-error, make error message by concatenating
897 all the data items. They are all strings. */
8c29413d 898 if (!NILP (file_error) && CONSP (tail))
113620cc
KH
899 errmsg = XCONS (tail)->car, tail = XCONS (tail)->cdr;
900
901 if (STRINGP (errmsg))
902 Fprinc (errmsg, stream);
903 else
904 write_string_1 ("peculiar error", -1, stream);
905
906 for (i = 0; CONSP (tail); tail = Fcdr (tail), i++)
907 {
908 write_string_1 (i ? ", " : ": ", 2, stream);
909 if (!NILP (file_error))
910 Fprinc (Fcar (tail), stream);
911 else
912 Fprin1 (Fcar (tail), stream);
913 }
914 UNGCPRO;
915}
916\f
38010d50
JB
917#ifdef LISP_FLOAT_TYPE
918
38010d50 919/*
edb2a707 920 * The buffer should be at least as large as the max string size of the
8e6208c5 921 * largest float, printed in the biggest notation. This is undoubtedly
38010d50
JB
922 * 20d float_output_format, with the negative of the C-constant "HUGE"
923 * from <math.h>.
924 *
925 * On the vax the worst case is -1e38 in 20d format which takes 61 bytes.
926 *
927 * I assume that IEEE-754 format numbers can take 329 bytes for the worst
928 * case of -1e307 in 20d float_output_format. What is one to do (short of
929 * re-writing _doprnt to be more sane)?
930 * -wsr
931 */
edb2a707
RS
932
933void
934float_to_string (buf, data)
8b24d146 935 unsigned char *buf;
38010d50
JB
936 double data;
937{
c7b14277 938 unsigned char *cp;
322890c4 939 int width;
38010d50 940
7f45de2d
RS
941 /* Check for plus infinity in a way that won't lose
942 if there is no plus infinity. */
943 if (data == data / 2 && data > 1.0)
944 {
945 strcpy (buf, "1.0e+INF");
946 return;
947 }
948 /* Likewise for minus infinity. */
949 if (data == data / 2 && data < -1.0)
950 {
951 strcpy (buf, "-1.0e+INF");
952 return;
953 }
954 /* Check for NaN in a way that won't fail if there are no NaNs. */
955 if (! (data * 0.0 >= 0.0))
956 {
957 strcpy (buf, "0.0e+NaN");
958 return;
959 }
960
10eebdbb 961 if (NILP (Vfloat_output_format)
d4ae1f7e 962 || !STRINGP (Vfloat_output_format))
38010d50 963 lose:
322890c4 964 {
f356c3fb
PE
965 /* Generate the fewest number of digits that represent the
966 floating point value without losing information.
967 The following method is simple but a bit slow.
968 For ideas about speeding things up, please see:
969
970 Guy L Steele Jr & Jon L White, How to print floating-point numbers
971 accurately. SIGPLAN notices 25, 6 (June 1990), 112-126.
972
973 Robert G Burger & R Kent Dybvig, Printing floating point numbers
974 quickly and accurately, SIGPLAN notices 31, 5 (May 1996), 108-116. */
975
976 width = fabs (data) < DBL_MIN ? 1 : DBL_DIG;
977 do
978 sprintf (buf, "%.*g", width, data);
979 while (width++ < DOUBLE_DIGITS_BOUND && atof (buf) != data);
322890c4 980 }
38010d50
JB
981 else /* oink oink */
982 {
983 /* Check that the spec we have is fully valid.
984 This means not only valid for printf,
985 but meant for floats, and reasonable. */
986 cp = XSTRING (Vfloat_output_format)->data;
987
988 if (cp[0] != '%')
989 goto lose;
990 if (cp[1] != '.')
991 goto lose;
992
993 cp += 2;
c7b14277
JB
994
995 /* Check the width specification. */
322890c4 996 width = -1;
c7b14277 997 if ('0' <= *cp && *cp <= '9')
381cd4bb
KH
998 {
999 width = 0;
1000 do
1001 width = (width * 10) + (*cp++ - '0');
1002 while (*cp >= '0' && *cp <= '9');
1003
1004 /* A precision of zero is valid only for %f. */
1005 if (width > DBL_DIG
1006 || (width == 0 && *cp != 'f'))
1007 goto lose;
1008 }
38010d50
JB
1009
1010 if (*cp != 'e' && *cp != 'f' && *cp != 'g')
1011 goto lose;
1012
38010d50
JB
1013 if (cp[1] != 0)
1014 goto lose;
1015
1016 sprintf (buf, XSTRING (Vfloat_output_format)->data, data);
1017 }
edb2a707 1018
c7b14277
JB
1019 /* Make sure there is a decimal point with digit after, or an
1020 exponent, so that the value is readable as a float. But don't do
322890c4
RS
1021 this with "%.0f"; it's valid for that not to produce a decimal
1022 point. Note that width can be 0 only for %.0f. */
1023 if (width != 0)
0601fd3d 1024 {
c7b14277
JB
1025 for (cp = buf; *cp; cp++)
1026 if ((*cp < '0' || *cp > '9') && *cp != '-')
1027 break;
0601fd3d 1028
c7b14277
JB
1029 if (*cp == '.' && cp[1] == 0)
1030 {
1031 cp[1] = '0';
1032 cp[2] = 0;
1033 }
1034
1035 if (*cp == 0)
1036 {
1037 *cp++ = '.';
1038 *cp++ = '0';
1039 *cp++ = 0;
1040 }
edb2a707 1041 }
38010d50
JB
1042}
1043#endif /* LISP_FLOAT_TYPE */
1044\f
1045static void
1046print (obj, printcharfun, escapeflag)
38010d50 1047 Lisp_Object obj;
38010d50
JB
1048 register Lisp_Object printcharfun;
1049 int escapeflag;
1050{
1051 char buf[30];
1052
1053 QUIT;
1054
ec838c39
RS
1055#if 1 /* I'm not sure this is really worth doing. */
1056 /* Detect circularities and truncate them.
1057 No need to offer any alternative--this is better than an error. */
d4ae1f7e 1058 if (CONSP (obj) || VECTORP (obj) || COMPILEDP (obj))
ec838c39
RS
1059 {
1060 int i;
1061 for (i = 0; i < print_depth; i++)
1062 if (EQ (obj, being_printed[i]))
1063 {
1064 sprintf (buf, "#%d", i);
dc2a0b79 1065 strout (buf, -1, -1, printcharfun, 0);
ec838c39
RS
1066 return;
1067 }
1068 }
1069#endif
1070
1071 being_printed[print_depth] = obj;
38010d50
JB
1072 print_depth++;
1073
ec838c39 1074 if (print_depth > PRINT_CIRCLE)
38010d50
JB
1075 error ("Apparently circular structure being printed");
1076#ifdef MAX_PRINT_CHARS
1077 if (max_print && print_chars > max_print)
1078 {
1079 PRINTCHAR ('\n');
1080 print_chars = 0;
1081 }
1082#endif /* MAX_PRINT_CHARS */
1083
ca0569ad 1084 switch (XGCTYPE (obj))
38010d50 1085 {
ca0569ad 1086 case Lisp_Int:
b8180922
RS
1087 if (sizeof (int) == sizeof (EMACS_INT))
1088 sprintf (buf, "%d", XINT (obj));
1089 else if (sizeof (long) == sizeof (EMACS_INT))
1090 sprintf (buf, "%ld", XINT (obj));
1091 else
1092 abort ();
dc2a0b79 1093 strout (buf, -1, -1, printcharfun, 0);
ca0569ad
RS
1094 break;
1095
e0f93814 1096#ifdef LISP_FLOAT_TYPE
ca0569ad
RS
1097 case Lisp_Float:
1098 {
1099 char pigbuf[350]; /* see comments in float_to_string */
38010d50 1100
ca0569ad 1101 float_to_string (pigbuf, XFLOAT(obj)->data);
dc2a0b79 1102 strout (pigbuf, -1, -1, printcharfun, 0);
ca0569ad
RS
1103 }
1104 break;
e0f93814 1105#endif
ca0569ad
RS
1106
1107 case Lisp_String:
38010d50
JB
1108 if (!escapeflag)
1109 print_string (obj, printcharfun);
1110 else
1111 {
dc2a0b79 1112 register int i, i_byte;
38010d50 1113 register unsigned char c;
38010d50 1114 struct gcpro gcpro1;
872a36d2 1115 unsigned char *str;
dc2a0b79 1116 int size_byte;
453fa987
RS
1117 /* 1 means we must ensure that the next character we output
1118 cannot be taken as part of a hex character escape. */
1119 int need_nonhex = 0;
38010d50 1120
7651e1f5
RS
1121 GCPRO1 (obj);
1122
1123#ifdef USE_TEXT_PROPERTIES
1124 if (!NULL_INTERVAL_P (XSTRING (obj)->intervals))
1125 {
1126 PRINTCHAR ('#');
1127 PRINTCHAR ('(');
1128 }
1129#endif
38010d50
JB
1130
1131 PRINTCHAR ('\"');
872a36d2 1132 str = XSTRING (obj)->data;
fc932ac6 1133 size_byte = STRING_BYTES (XSTRING (obj));
dc2a0b79
RS
1134
1135 for (i = 0, i_byte = 0; i_byte < size_byte;)
38010d50 1136 {
6ddd6eee
RS
1137 /* Here, we must convert each multi-byte form to the
1138 corresponding character code before handing it to PRINTCHAR. */
1139 int len;
dc2a0b79
RS
1140 int c;
1141
1142 if (STRING_MULTIBYTE (obj))
872a36d2 1143 {
765fe1d0
KH
1144 c = STRING_CHAR_AND_LENGTH (str + i_byte,
1145 size_byte - i_byte, len);
da1ad4e7
KH
1146 if (CHAR_VALID_P (c, 0))
1147 i_byte += len;
1148 else
1149 c = str[i_byte++];
872a36d2 1150 }
dc2a0b79 1151 else
872a36d2 1152 c = str[i_byte++];
dc2a0b79 1153
38010d50 1154 QUIT;
6ddd6eee 1155
38010d50
JB
1156 if (c == '\n' && print_escape_newlines)
1157 {
1158 PRINTCHAR ('\\');
1159 PRINTCHAR ('n');
1160 }
c6f7982f
RM
1161 else if (c == '\f' && print_escape_newlines)
1162 {
1163 PRINTCHAR ('\\');
1164 PRINTCHAR ('f');
1165 }
835d0be6 1166 else if (! SINGLE_BYTE_CHAR_P (c) && print_escape_multibyte)
dc2a0b79
RS
1167 {
1168 /* When multibyte is disabled,
1169 print multibyte string chars using hex escapes. */
1170 unsigned char outbuf[50];
1171 sprintf (outbuf, "\\x%x", c);
1172 strout (outbuf, -1, -1, printcharfun, 0);
453fa987 1173 need_nonhex = 1;
dc2a0b79 1174 }
835d0be6
RS
1175 else if (SINGLE_BYTE_CHAR_P (c) && ! ASCII_BYTE_P (c)
1176 && print_escape_nonascii)
974a6ff5 1177 {
835d0be6
RS
1178 /* When printing in a multibyte buffer
1179 or when explicitly requested,
974a6ff5
KH
1180 print single-byte non-ASCII string chars
1181 using octal escapes. */
1182 unsigned char outbuf[5];
1183 sprintf (outbuf, "\\%03o", c);
1184 strout (outbuf, -1, -1, printcharfun, 0);
1185 }
38010d50
JB
1186 else
1187 {
453fa987
RS
1188 /* If we just had a hex escape, and this character
1189 could be taken as part of it,
1190 output `\ ' to prevent that. */
1b62edd6
KH
1191 if (need_nonhex)
1192 {
1193 need_nonhex = 0;
1194 if ((c >= 'a' && c <= 'f')
453fa987 1195 || (c >= 'A' && c <= 'F')
1b62edd6
KH
1196 || (c >= '0' && c <= '9'))
1197 strout ("\\ ", -1, -1, printcharfun, 0);
1198 }
453fa987 1199
38010d50
JB
1200 if (c == '\"' || c == '\\')
1201 PRINTCHAR ('\\');
1202 PRINTCHAR (c);
1203 }
1204 }
1205 PRINTCHAR ('\"');
7651e1f5
RS
1206
1207#ifdef USE_TEXT_PROPERTIES
1208 if (!NULL_INTERVAL_P (XSTRING (obj)->intervals))
1209 {
7651e1f5
RS
1210 traverse_intervals (XSTRING (obj)->intervals,
1211 0, 0, print_interval, printcharfun);
1212 PRINTCHAR (')');
1213 }
1214#endif
1215
38010d50
JB
1216 UNGCPRO;
1217 }
ca0569ad 1218 break;
38010d50 1219
ca0569ad
RS
1220 case Lisp_Symbol:
1221 {
1222 register int confusing;
1223 register unsigned char *p = XSYMBOL (obj)->name->data;
fc932ac6 1224 register unsigned char *end = p + STRING_BYTES (XSYMBOL (obj)->name);
2190a05e 1225 register int c;
dc2a0b79
RS
1226 int i, i_byte, size_byte;
1227 Lisp_Object name;
1228
1229 XSETSTRING (name, XSYMBOL (obj)->name);
ca0569ad
RS
1230
1231 if (p != end && (*p == '-' || *p == '+')) p++;
1232 if (p == end)
1233 confusing = 0;
d27497e3
RS
1234 /* If symbol name begins with a digit, and ends with a digit,
1235 and contains nothing but digits and `e', it could be treated
1236 as a number. So set CONFUSING.
1237
1238 Symbols that contain periods could also be taken as numbers,
1239 but periods are always escaped, so we don't have to worry
1240 about them here. */
1241 else if (*p >= '0' && *p <= '9'
1242 && end[-1] >= '0' && end[-1] <= '9')
ca0569ad 1243 {
e837058b
RS
1244 while (p != end && ((*p >= '0' && *p <= '9')
1245 /* Needed for \2e10. */
1246 || *p == 'e'))
ca0569ad
RS
1247 p++;
1248 confusing = (end == p);
1249 }
d27497e3
RS
1250 else
1251 confusing = 0;
ca0569ad 1252
081e0581
EN
1253 /* If we print an uninterned symbol as part of a complex object and
1254 the flag print-gensym is non-nil, prefix it with #n= to read the
1255 object back with the #n# reader syntax later if needed. */
e0f69431 1256 if (! NILP (Vprint_gensym) && NILP (XSYMBOL (obj)->obarray))
081e0581
EN
1257 {
1258 if (print_depth > 1)
1259 {
1260 Lisp_Object tem;
e0f69431 1261 tem = Fassq (obj, Vprint_gensym_alist);
081e0581
EN
1262 if (CONSP (tem))
1263 {
1264 PRINTCHAR ('#');
1265 print (XCDR (tem), printcharfun, escapeflag);
1266 PRINTCHAR ('#');
1267 break;
1268 }
1269 else
1270 {
e0f69431
RS
1271 if (CONSP (Vprint_gensym_alist))
1272 XSETFASTINT (tem, XFASTINT (XCDR (XCAR (Vprint_gensym_alist))) + 1);
081e0581
EN
1273 else
1274 XSETFASTINT (tem, 1);
e0f69431 1275 Vprint_gensym_alist = Fcons (Fcons (obj, tem), Vprint_gensym_alist);
081e0581
EN
1276
1277 PRINTCHAR ('#');
1278 print (tem, printcharfun, escapeflag);
1279 PRINTCHAR ('=');
1280 }
1281 }
1282 PRINTCHAR ('#');
1283 PRINTCHAR (':');
1284 }
1285
fc932ac6 1286 size_byte = STRING_BYTES (XSTRING (name));
dc2a0b79
RS
1287
1288 for (i = 0, i_byte = 0; i_byte < size_byte;)
ca0569ad 1289 {
6ddd6eee
RS
1290 /* Here, we must convert each multi-byte form to the
1291 corresponding character code before handing it to PRINTCHAR. */
dc2a0b79
RS
1292
1293 if (STRING_MULTIBYTE (name))
1294 FETCH_STRING_CHAR_ADVANCE (c, name, i, i_byte);
1295 else
1296 c = XSTRING (name)->data[i_byte++];
1297
ca0569ad 1298 QUIT;
09eddb56 1299
ca0569ad
RS
1300 if (escapeflag)
1301 {
09eddb56
RS
1302 if (c == '\"' || c == '\\' || c == '\''
1303 || c == ';' || c == '#' || c == '(' || c == ')'
1304 || c == ',' || c =='.' || c == '`'
1305 || c == '[' || c == ']' || c == '?' || c <= 040
1306 || confusing)
ca0569ad
RS
1307 PRINTCHAR ('\\'), confusing = 0;
1308 }
1309 PRINTCHAR (c);
1310 }
1311 }
1312 break;
1313
1314 case Lisp_Cons:
38010d50 1315 /* If deeper than spec'd depth, print placeholder. */
d4ae1f7e 1316 if (INTEGERP (Vprint_level)
38010d50 1317 && print_depth > XINT (Vprint_level))
dc2a0b79 1318 strout ("...", -1, -1, printcharfun, 0);
2f100b5c
EN
1319 else if (print_quoted && CONSP (XCDR (obj)) && NILP (XCDR (XCDR (obj)))
1320 && (EQ (XCAR (obj), Qquote)))
1321 {
1322 PRINTCHAR ('\'');
1323 print (XCAR (XCDR (obj)), printcharfun, escapeflag);
1324 }
1325 else if (print_quoted && CONSP (XCDR (obj)) && NILP (XCDR (XCDR (obj)))
1326 && (EQ (XCAR (obj), Qfunction)))
1327 {
1328 PRINTCHAR ('#');
1329 PRINTCHAR ('\'');
1330 print (XCAR (XCDR (obj)), printcharfun, escapeflag);
1331 }
1332 else if (print_quoted && CONSP (XCDR (obj)) && NILP (XCDR (XCDR (obj)))
1333 && ((EQ (XCAR (obj), Qbackquote)
1334 || EQ (XCAR (obj), Qcomma)
1335 || EQ (XCAR (obj), Qcomma_at)
1336 || EQ (XCAR (obj), Qcomma_dot))))
1337 {
1338 print (XCAR (obj), printcharfun, 0);
1339 print (XCAR (XCDR (obj)), printcharfun, escapeflag);
1340 }
e0f93814 1341 else
38010d50 1342 {
e0f93814 1343 PRINTCHAR ('(');
38010d50 1344 {
e0f93814 1345 register int i = 0;
f4fe72d5 1346 register int print_length = 0;
1eab22b5 1347 Lisp_Object halftail = obj;
e0f93814
KH
1348
1349 if (INTEGERP (Vprint_length))
f4fe72d5 1350 print_length = XINT (Vprint_length);
e0f93814 1351 while (CONSP (obj))
38010d50 1352 {
1eab22b5
RS
1353 /* Detect circular list. */
1354 if (i != 0 && EQ (obj, halftail))
1355 {
1356 sprintf (buf, " . #%d", i / 2);
1357 strout (buf, -1, -1, printcharfun, 0);
1358 obj = Qnil;
1359 break;
1360 }
e0f93814
KH
1361 if (i++)
1362 PRINTCHAR (' ');
f4fe72d5 1363 if (print_length && i > print_length)
e0f93814 1364 {
dc2a0b79 1365 strout ("...", 3, 3, printcharfun, 0);
e0f93814
KH
1366 break;
1367 }
2f100b5c
EN
1368 print (XCAR (obj), printcharfun, escapeflag);
1369 obj = XCDR (obj);
1eab22b5
RS
1370 if (!(i & 1))
1371 halftail = XCDR (halftail);
38010d50 1372 }
38010d50 1373 }
2f100b5c 1374 if (!NILP (obj))
e0f93814 1375 {
dc2a0b79 1376 strout (" . ", 3, 3, printcharfun, 0);
e0f93814
KH
1377 print (obj, printcharfun, escapeflag);
1378 }
1379 PRINTCHAR (')');
38010d50 1380 }
ca0569ad
RS
1381 break;
1382
1383 case Lisp_Vectorlike:
1384 if (PROCESSP (obj))
1385 {
1386 if (escapeflag)
1387 {
dc2a0b79 1388 strout ("#<process ", -1, -1, printcharfun, 0);
ca0569ad
RS
1389 print_string (XPROCESS (obj)->name, printcharfun);
1390 PRINTCHAR ('>');
1391 }
1392 else
1393 print_string (XPROCESS (obj)->name, printcharfun);
1394 }
ed2c35ef
RS
1395 else if (BOOL_VECTOR_P (obj))
1396 {
1397 register int i;
1398 register unsigned char c;
1399 struct gcpro gcpro1;
ed2c35ef 1400 int size_in_chars
1bad7c59 1401 = (XBOOL_VECTOR (obj)->size + BITS_PER_CHAR - 1) / BITS_PER_CHAR;
ed2c35ef
RS
1402
1403 GCPRO1 (obj);
1404
1405 PRINTCHAR ('#');
1406 PRINTCHAR ('&');
1407 sprintf (buf, "%d", XBOOL_VECTOR (obj)->size);
dc2a0b79 1408 strout (buf, -1, -1, printcharfun, 0);
ed2c35ef 1409 PRINTCHAR ('\"');
a40384bc
RS
1410
1411 /* Don't print more characters than the specified maximum. */
1412 if (INTEGERP (Vprint_length)
1413 && XINT (Vprint_length) < size_in_chars)
1414 size_in_chars = XINT (Vprint_length);
1415
ed2c35ef
RS
1416 for (i = 0; i < size_in_chars; i++)
1417 {
1418 QUIT;
1419 c = XBOOL_VECTOR (obj)->data[i];
1420 if (c == '\n' && print_escape_newlines)
1421 {
1422 PRINTCHAR ('\\');
1423 PRINTCHAR ('n');
1424 }
1425 else if (c == '\f' && print_escape_newlines)
1426 {
1427 PRINTCHAR ('\\');
1428 PRINTCHAR ('f');
1429 }
1430 else
1431 {
1432 if (c == '\"' || c == '\\')
1433 PRINTCHAR ('\\');
1434 PRINTCHAR (c);
1435 }
1436 }
1437 PRINTCHAR ('\"');
1438
1439 UNGCPRO;
1440 }
ca0569ad
RS
1441 else if (SUBRP (obj))
1442 {
dc2a0b79
RS
1443 strout ("#<subr ", -1, -1, printcharfun, 0);
1444 strout (XSUBR (obj)->symbol_name, -1, -1, printcharfun, 0);
ca0569ad
RS
1445 PRINTCHAR ('>');
1446 }
ca0569ad
RS
1447 else if (WINDOWP (obj))
1448 {
dc2a0b79 1449 strout ("#<window ", -1, -1, printcharfun, 0);
ca0569ad 1450 sprintf (buf, "%d", XFASTINT (XWINDOW (obj)->sequence_number));
dc2a0b79 1451 strout (buf, -1, -1, printcharfun, 0);
ca0569ad
RS
1452 if (!NILP (XWINDOW (obj)->buffer))
1453 {
dc2a0b79 1454 strout (" on ", -1, -1, printcharfun, 0);
ca0569ad
RS
1455 print_string (XBUFFER (XWINDOW (obj)->buffer)->name, printcharfun);
1456 }
1457 PRINTCHAR ('>');
1458 }
7eb03302
GM
1459 else if (HASH_TABLE_P (obj))
1460 {
1461 struct Lisp_Hash_Table *h = XHASH_TABLE (obj);
1462 strout ("#<hash-table", -1, -1, printcharfun, 0);
1463 if (SYMBOLP (h->test))
1464 {
1465 PRINTCHAR (' ');
1466 PRINTCHAR ('\'');
1467 strout (XSYMBOL (h->test)->name->data, -1, -1, printcharfun, 0);
1468 PRINTCHAR (' ');
1469 strout (XSYMBOL (h->weak)->name->data, -1, -1, printcharfun, 0);
1470 PRINTCHAR (' ');
1471 sprintf (buf, "%d/%d", XFASTINT (h->count),
1472 XVECTOR (h->next)->size);
1473 strout (buf, -1, -1, printcharfun, 0);
1474 }
1475 sprintf (buf, " 0x%lx", (unsigned long) h);
1476 strout (buf, -1, -1, printcharfun, 0);
1477 PRINTCHAR ('>');
1478 }
908b0ae5
RS
1479 else if (BUFFERP (obj))
1480 {
1481 if (NILP (XBUFFER (obj)->name))
dc2a0b79 1482 strout ("#<killed buffer>", -1, -1, printcharfun, 0);
908b0ae5
RS
1483 else if (escapeflag)
1484 {
dc2a0b79 1485 strout ("#<buffer ", -1, -1, printcharfun, 0);
908b0ae5
RS
1486 print_string (XBUFFER (obj)->name, printcharfun);
1487 PRINTCHAR ('>');
1488 }
1489 else
1490 print_string (XBUFFER (obj)->name, printcharfun);
1491 }
ca0569ad
RS
1492 else if (WINDOW_CONFIGURATIONP (obj))
1493 {
dc2a0b79 1494 strout ("#<window-configuration>", -1, -1, printcharfun, 0);
ca0569ad 1495 }
ca0569ad
RS
1496 else if (FRAMEP (obj))
1497 {
1498 strout ((FRAME_LIVE_P (XFRAME (obj))
1499 ? "#<frame " : "#<dead frame "),
dc2a0b79 1500 -1, -1, printcharfun, 0);
ca0569ad 1501 print_string (XFRAME (obj)->name, printcharfun);
dc2a0b79
RS
1502 sprintf (buf, " 0x%lx\\ ", (unsigned long) (XFRAME (obj)));
1503 strout (buf, -1, -1, printcharfun, 0);
ca0569ad
RS
1504 PRINTCHAR ('>');
1505 }
ca0569ad
RS
1506 else
1507 {
1508 int size = XVECTOR (obj)->size;
1509 if (COMPILEDP (obj))
1510 {
1511 PRINTCHAR ('#');
1512 size &= PSEUDOVECTOR_SIZE_MASK;
1513 }
ed2c35ef
RS
1514 if (CHAR_TABLE_P (obj))
1515 {
1516 /* We print a char-table as if it were a vector,
1517 lumping the parent and default slots in with the
1518 character slots. But we add #^ as a prefix. */
1519 PRINTCHAR ('#');
1520 PRINTCHAR ('^');
3701b5de
KH
1521 if (SUB_CHAR_TABLE_P (obj))
1522 PRINTCHAR ('^');
ed2c35ef
RS
1523 size &= PSEUDOVECTOR_SIZE_MASK;
1524 }
00d76abc
KH
1525 if (size & PSEUDOVECTOR_FLAG)
1526 goto badtype;
ca0569ad
RS
1527
1528 PRINTCHAR ('[');
38010d50 1529 {
ca0569ad
RS
1530 register int i;
1531 register Lisp_Object tem;
a40384bc
RS
1532
1533 /* Don't print more elements than the specified maximum. */
1534 if (INTEGERP (Vprint_length)
1535 && XINT (Vprint_length) < size)
1536 size = XINT (Vprint_length);
1537
ca0569ad
RS
1538 for (i = 0; i < size; i++)
1539 {
1540 if (i) PRINTCHAR (' ');
1541 tem = XVECTOR (obj)->contents[i];
1542 print (tem, printcharfun, escapeflag);
1543 }
38010d50 1544 }
ca0569ad
RS
1545 PRINTCHAR (']');
1546 }
1547 break;
1548
ca0569ad 1549 case Lisp_Misc:
5db20f08 1550 switch (XMISCTYPE (obj))
38010d50 1551 {
00d76abc 1552 case Lisp_Misc_Marker:
dc2a0b79 1553 strout ("#<marker ", -1, -1, printcharfun, 0);
087e3c46
KH
1554 /* Do you think this is necessary? */
1555 if (XMARKER (obj)->insertion_type != 0)
dc2a0b79 1556 strout ("(before-insertion) ", -1, -1, printcharfun, 0);
ca0569ad 1557 if (!(XMARKER (obj)->buffer))
dc2a0b79 1558 strout ("in no buffer", -1, -1, printcharfun, 0);
ca0569ad
RS
1559 else
1560 {
1561 sprintf (buf, "at %d", marker_position (obj));
dc2a0b79
RS
1562 strout (buf, -1, -1, printcharfun, 0);
1563 strout (" in ", -1, -1, printcharfun, 0);
ca0569ad
RS
1564 print_string (XMARKER (obj)->buffer->name, printcharfun);
1565 }
38010d50 1566 PRINTCHAR ('>');
908b0ae5 1567 break;
00d76abc
KH
1568
1569 case Lisp_Misc_Overlay:
dc2a0b79 1570 strout ("#<overlay ", -1, -1, printcharfun, 0);
ca0569ad 1571 if (!(XMARKER (OVERLAY_START (obj))->buffer))
dc2a0b79 1572 strout ("in no buffer", -1, -1, printcharfun, 0);
ca0569ad
RS
1573 else
1574 {
1575 sprintf (buf, "from %d to %d in ",
1576 marker_position (OVERLAY_START (obj)),
1577 marker_position (OVERLAY_END (obj)));
dc2a0b79 1578 strout (buf, -1, -1, printcharfun, 0);
ca0569ad
RS
1579 print_string (XMARKER (OVERLAY_START (obj))->buffer->name,
1580 printcharfun);
1581 }
1582 PRINTCHAR ('>');
908b0ae5 1583 break;
00d76abc
KH
1584
1585 /* Remaining cases shouldn't happen in normal usage, but let's print
1586 them anyway for the benefit of the debugger. */
1587 case Lisp_Misc_Free:
dc2a0b79 1588 strout ("#<misc free cell>", -1, -1, printcharfun, 0);
00d76abc
KH
1589 break;
1590
1591 case Lisp_Misc_Intfwd:
1592 sprintf (buf, "#<intfwd to %d>", *XINTFWD (obj)->intvar);
dc2a0b79 1593 strout (buf, -1, -1, printcharfun, 0);
00d76abc
KH
1594 break;
1595
1596 case Lisp_Misc_Boolfwd:
1597 sprintf (buf, "#<boolfwd to %s>",
1598 (*XBOOLFWD (obj)->boolvar ? "t" : "nil"));
dc2a0b79 1599 strout (buf, -1, -1, printcharfun, 0);
00d76abc
KH
1600 break;
1601
1602 case Lisp_Misc_Objfwd:
dc2a0b79 1603 strout ("#<objfwd to ", -1, -1, printcharfun, 0);
00d76abc
KH
1604 print (*XOBJFWD (obj)->objvar, printcharfun, escapeflag);
1605 PRINTCHAR ('>');
1606 break;
1607
1608 case Lisp_Misc_Buffer_Objfwd:
dc2a0b79 1609 strout ("#<buffer_objfwd to ", -1, -1, printcharfun, 0);
3ac613c1
KH
1610 print (*(Lisp_Object *)((char *)current_buffer
1611 + XBUFFER_OBJFWD (obj)->offset),
1612 printcharfun, escapeflag);
1613 PRINTCHAR ('>');
1614 break;
1615
fb917148 1616 case Lisp_Misc_Kboard_Objfwd:
dc2a0b79 1617 strout ("#<kboard_objfwd to ", -1, -1, printcharfun, 0);
fb917148
KH
1618 print (*(Lisp_Object *)((char *) current_kboard
1619 + XKBOARD_OBJFWD (obj)->offset),
7ae137a9 1620 printcharfun, escapeflag);
00d76abc
KH
1621 PRINTCHAR ('>');
1622 break;
1623
1624 case Lisp_Misc_Buffer_Local_Value:
dc2a0b79 1625 strout ("#<buffer_local_value ", -1, -1, printcharfun, 0);
00d76abc
KH
1626 goto do_buffer_local;
1627 case Lisp_Misc_Some_Buffer_Local_Value:
dc2a0b79 1628 strout ("#<some_buffer_local_value ", -1, -1, printcharfun, 0);
00d76abc 1629 do_buffer_local:
dc2a0b79 1630 strout ("[realvalue] ", -1, -1, printcharfun, 0);
03153771
RS
1631 print (XBUFFER_LOCAL_VALUE (obj)->realvalue, printcharfun, escapeflag);
1632 if (XBUFFER_LOCAL_VALUE (obj)->found_for_buffer)
1633 strout ("[local in buffer] ", -1, -1, printcharfun, 0);
1634 else
1635 strout ("[buffer] ", -1, -1, printcharfun, 0);
1636 print (XBUFFER_LOCAL_VALUE (obj)->buffer,
00d76abc 1637 printcharfun, escapeflag);
03153771
RS
1638 if (XBUFFER_LOCAL_VALUE (obj)->check_frame)
1639 {
1640 if (XBUFFER_LOCAL_VALUE (obj)->found_for_frame)
1641 strout ("[local in frame] ", -1, -1, printcharfun, 0);
1642 else
1643 strout ("[frame] ", -1, -1, printcharfun, 0);
1644 print (XBUFFER_LOCAL_VALUE (obj)->frame,
1645 printcharfun, escapeflag);
1646 }
dc2a0b79 1647 strout ("[alist-elt] ", -1, -1, printcharfun, 0);
03153771 1648 print (XCONS (XBUFFER_LOCAL_VALUE (obj)->cdr)->car,
00d76abc 1649 printcharfun, escapeflag);
dc2a0b79 1650 strout ("[default-value] ", -1, -1, printcharfun, 0);
03153771 1651 print (XCONS (XBUFFER_LOCAL_VALUE (obj)->cdr)->cdr,
00d76abc
KH
1652 printcharfun, escapeflag);
1653 PRINTCHAR ('>');
1654 break;
1655
1656 default:
1657 goto badtype;
e0f93814 1658 }
00d76abc 1659 break;
ca0569ad
RS
1660
1661 default:
00d76abc 1662 badtype:
ca0569ad
RS
1663 {
1664 /* We're in trouble if this happens!
1665 Probably should just abort () */
dc2a0b79 1666 strout ("#<EMACS BUG: INVALID DATATYPE ", -1, -1, printcharfun, 0);
00d76abc 1667 if (MISCP (obj))
5db20f08 1668 sprintf (buf, "(MISC 0x%04x)", (int) XMISCTYPE (obj));
00d76abc
KH
1669 else if (VECTORLIKEP (obj))
1670 sprintf (buf, "(PVEC 0x%08x)", (int) XVECTOR (obj)->size);
1671 else
1672 sprintf (buf, "(0x%02x)", (int) XTYPE (obj));
dc2a0b79 1673 strout (buf, -1, -1, printcharfun, 0);
ca0569ad 1674 strout (" Save your buffers immediately and please report this bug>",
dc2a0b79 1675 -1, -1, printcharfun, 0);
ca0569ad 1676 }
38010d50
JB
1677 }
1678
1679 print_depth--;
1680}
1681\f
7651e1f5
RS
1682#ifdef USE_TEXT_PROPERTIES
1683
1684/* Print a description of INTERVAL using PRINTCHARFUN.
1685 This is part of printing a string that has text properties. */
1686
1687void
1688print_interval (interval, printcharfun)
1689 INTERVAL interval;
1690 Lisp_Object printcharfun;
1691{
30503c0b 1692 PRINTCHAR (' ');
7651e1f5
RS
1693 print (make_number (interval->position), printcharfun, 1);
1694 PRINTCHAR (' ');
1695 print (make_number (interval->position + LENGTH (interval)),
1696 printcharfun, 1);
1697 PRINTCHAR (' ');
1698 print (interval->plist, printcharfun, 1);
7651e1f5
RS
1699}
1700
1701#endif /* USE_TEXT_PROPERTIES */
1702\f
38010d50
JB
1703void
1704syms_of_print ()
1705{
d9c21094
RS
1706 Qtemp_buffer_setup_hook = intern ("temp-buffer-setup-hook");
1707 staticpro (&Qtemp_buffer_setup_hook);
1708
38010d50
JB
1709 DEFVAR_LISP ("standard-output", &Vstandard_output,
1710 "Output stream `print' uses by default for outputting a character.\n\
1711This may be any function of one argument.\n\
1712It may also be a buffer (output is inserted before point)\n\
1713or a marker (output is inserted and the marker is advanced)\n\
113620cc 1714or the symbol t (output appears in the echo area).");
38010d50
JB
1715 Vstandard_output = Qt;
1716 Qstandard_output = intern ("standard-output");
1717 staticpro (&Qstandard_output);
1718
1719#ifdef LISP_FLOAT_TYPE
1720 DEFVAR_LISP ("float-output-format", &Vfloat_output_format,
06ef7355 1721 "The format descriptor string used to print floats.\n\
38010d50
JB
1722This is a %-spec like those accepted by `printf' in C,\n\
1723but with some restrictions. It must start with the two characters `%.'.\n\
1724After that comes an integer precision specification,\n\
1725and then a letter which controls the format.\n\
1726The letters allowed are `e', `f' and `g'.\n\
1727Use `e' for exponential notation \"DIG.DIGITSeEXPT\"\n\
1728Use `f' for decimal point notation \"DIGITS.DIGITS\".\n\
1729Use `g' to choose the shorter of those two formats for the number at hand.\n\
1730The precision in any of these cases is the number of digits following\n\
1731the decimal point. With `f', a precision of 0 means to omit the\n\
c7b14277 1732decimal point. 0 is not allowed with `e' or `g'.\n\n\
f356c3fb
PE
1733A value of nil means to use the shortest notation\n\
1734that represents the number without losing information.");
38010d50
JB
1735 Vfloat_output_format = Qnil;
1736 Qfloat_output_format = intern ("float-output-format");
1737 staticpro (&Qfloat_output_format);
1738#endif /* LISP_FLOAT_TYPE */
1739
1740 DEFVAR_LISP ("print-length", &Vprint_length,
aa734e17 1741 "Maximum length of list to print before abbreviating.\n\
38010d50
JB
1742A value of nil means no limit.");
1743 Vprint_length = Qnil;
1744
1745 DEFVAR_LISP ("print-level", &Vprint_level,
aa734e17 1746 "Maximum depth of list nesting to print before abbreviating.\n\
38010d50
JB
1747A value of nil means no limit.");
1748 Vprint_level = Qnil;
1749
1750 DEFVAR_BOOL ("print-escape-newlines", &print_escape_newlines,
a8920a17 1751 "Non-nil means print newlines in strings as backslash-n.\n\
c6f7982f 1752Also print formfeeds as backslash-f.");
38010d50
JB
1753 print_escape_newlines = 0;
1754
38940e93 1755 DEFVAR_BOOL ("print-escape-nonascii", &print_escape_nonascii,
835d0be6
RS
1756 "Non-nil means print unibyte non-ASCII chars in strings as \\OOO.\n\
1757\(OOO is the octal representation of the character code.)\n\
96aab770 1758Only single-byte characters are affected, and only in `prin1'.");
38940e93
RS
1759 print_escape_nonascii = 0;
1760
835d0be6
RS
1761 DEFVAR_BOOL ("print-escape-multibyte", &print_escape_multibyte,
1762 "Non-nil means print multibyte characters in strings as \\xXXXX.\n\
1763\(XXX is the hex representation of the character code.)\n\
1764This affects only `prin1'.");
1765 print_escape_multibyte = 0;
1766
2f100b5c
EN
1767 DEFVAR_BOOL ("print-quoted", &print_quoted,
1768 "Non-nil means print quoted forms with reader syntax.\n\
1769I.e., (quote foo) prints as 'foo, (function foo) as #'foo, and, backquoted\n\
1770forms print in the new syntax.");
1771 print_quoted = 0;
1772
e0f69431 1773 DEFVAR_LISP ("print-gensym", &Vprint_gensym,
081e0581 1774 "Non-nil means print uninterned symbols so they will read as uninterned.\n\
265375e7 1775I.e., the value of (make-symbol \"foobar\") prints as #:foobar.\n\
e0f69431
RS
1776When the uninterned symbol appears within a larger data structure,\n\
1777in addition use the #...# and #...= constructs as needed,\n\
1778so that multiple references to the same symbol are shared once again\n\
1779when the text is read back.\n\
1780\n\
1781If the value of `print-gensym' is a cons cell, then in addition refrain from\n\
1782clearing `print-gensym-alist' on entry to and exit from printing functions,\n\
1783so that the use of #...# and #...= can carry over for several separately\n\
1784printed objects.");
1785 Vprint_gensym = Qnil;
1786
1787 DEFVAR_LISP ("print-gensym-alist", &Vprint_gensym_alist,
1788 "Association list of elements (GENSYM . N) to guide use of #N# and #N=.\n\
1789In each element, GENSYM is an uninterned symbol that has been associated\n\
1790with #N= for the specified value of N.");
1791 Vprint_gensym_alist = Qnil;
081e0581 1792
38010d50
JB
1793 /* prin1_to_string_buffer initialized in init_buffer_once in buffer.c */
1794 staticpro (&Vprin1_to_string_buffer);
1795
1796 defsubr (&Sprin1);
1797 defsubr (&Sprin1_to_string);
113620cc 1798 defsubr (&Serror_message_string);
38010d50
JB
1799 defsubr (&Sprinc);
1800 defsubr (&Sprint);
1801 defsubr (&Sterpri);
1802 defsubr (&Swrite_char);
1803 defsubr (&Sexternal_debugging_output);
1804
1805 Qexternal_debugging_output = intern ("external-debugging-output");
1806 staticpro (&Qexternal_debugging_output);
1807
2f100b5c
EN
1808 Qprint_escape_newlines = intern ("print-escape-newlines");
1809 staticpro (&Qprint_escape_newlines);
1810
835d0be6
RS
1811 Qprint_escape_multibyte = intern ("print-escape-multibyte");
1812 staticpro (&Qprint_escape_multibyte);
1813
1814 Qprint_escape_nonascii = intern ("print-escape-nonascii");
1815 staticpro (&Qprint_escape_nonascii);
1816
38010d50 1817 defsubr (&Swith_output_to_temp_buffer);
38010d50 1818}