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