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