]> code.delx.au - gnu-emacs/blob - src/print.c
(calendar-location-name): Doc fix.
[gnu-emacs] / 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 #ifdef WINDOWSNT
736 /* Send the output to a debugger (nothing happens if there isn't one). */
737 {
738 char buf[2] = {(char) XINT (character), '\0'};
739 OutputDebugString (buf);
740 }
741 #endif
742
743 return character;
744 }
745
746 /* This is the interface for debugging printing. */
747
748 void
749 debug_print (arg)
750 Lisp_Object arg;
751 {
752 Fprin1 (arg, Qexternal_debugging_output);
753 fprintf (stderr, "\r\n");
754 }
755 \f
756 DEFUN ("error-message-string", Ferror_message_string, Serror_message_string,
757 1, 1, 0,
758 "Convert an error value (ERROR-SYMBOL . DATA) to an error message.")
759 (obj)
760 Lisp_Object obj;
761 {
762 struct buffer *old = current_buffer;
763 Lisp_Object original, printcharfun, value;
764 struct gcpro gcpro1;
765
766 /* If OBJ is (error STRING), just return STRING.
767 That is not only faster, it also avoids the need to allocate
768 space here when the error is due to memory full. */
769 if (CONSP (obj) && EQ (XCONS (obj)->car, Qerror)
770 && CONSP (XCONS (obj)->cdr)
771 && STRINGP (XCONS (XCONS (obj)->cdr)->car)
772 && NILP (XCONS (XCONS (obj)->cdr)->cdr))
773 return XCONS (XCONS (obj)->cdr)->car;
774
775 print_error_message (obj, Vprin1_to_string_buffer, NULL);
776
777 set_buffer_internal (XBUFFER (Vprin1_to_string_buffer));
778 value = Fbuffer_string ();
779
780 GCPRO1 (value);
781 Ferase_buffer ();
782 set_buffer_internal (old);
783 UNGCPRO;
784
785 return value;
786 }
787
788 /* Print an error message for the error DATA
789 onto Lisp output stream STREAM (suitable for the print functions). */
790
791 print_error_message (data, stream)
792 Lisp_Object data, stream;
793 {
794 Lisp_Object errname, errmsg, file_error, tail;
795 struct gcpro gcpro1;
796 int i;
797
798 errname = Fcar (data);
799
800 if (EQ (errname, Qerror))
801 {
802 data = Fcdr (data);
803 if (!CONSP (data)) data = Qnil;
804 errmsg = Fcar (data);
805 file_error = Qnil;
806 }
807 else
808 {
809 errmsg = Fget (errname, Qerror_message);
810 file_error = Fmemq (Qfile_error,
811 Fget (errname, Qerror_conditions));
812 }
813
814 /* Print an error message including the data items. */
815
816 tail = Fcdr_safe (data);
817 GCPRO1 (tail);
818
819 /* For file-error, make error message by concatenating
820 all the data items. They are all strings. */
821 if (!NILP (file_error) && !NILP (tail))
822 errmsg = XCONS (tail)->car, tail = XCONS (tail)->cdr;
823
824 if (STRINGP (errmsg))
825 Fprinc (errmsg, stream);
826 else
827 write_string_1 ("peculiar error", -1, stream);
828
829 for (i = 0; CONSP (tail); tail = Fcdr (tail), i++)
830 {
831 write_string_1 (i ? ", " : ": ", 2, stream);
832 if (!NILP (file_error))
833 Fprinc (Fcar (tail), stream);
834 else
835 Fprin1 (Fcar (tail), stream);
836 }
837 UNGCPRO;
838 }
839 \f
840 #ifdef LISP_FLOAT_TYPE
841
842 /*
843 * The buffer should be at least as large as the max string size of the
844 * largest float, printed in the biggest notation. This is undoubtedly
845 * 20d float_output_format, with the negative of the C-constant "HUGE"
846 * from <math.h>.
847 *
848 * On the vax the worst case is -1e38 in 20d format which takes 61 bytes.
849 *
850 * I assume that IEEE-754 format numbers can take 329 bytes for the worst
851 * case of -1e307 in 20d float_output_format. What is one to do (short of
852 * re-writing _doprnt to be more sane)?
853 * -wsr
854 */
855
856 void
857 float_to_string (buf, data)
858 unsigned char *buf;
859 double data;
860 {
861 unsigned char *cp;
862 int width;
863
864 if (NILP (Vfloat_output_format)
865 || !STRINGP (Vfloat_output_format))
866 lose:
867 {
868 sprintf (buf, "%.17g", data);
869 width = -1;
870 }
871 else /* oink oink */
872 {
873 /* Check that the spec we have is fully valid.
874 This means not only valid for printf,
875 but meant for floats, and reasonable. */
876 cp = XSTRING (Vfloat_output_format)->data;
877
878 if (cp[0] != '%')
879 goto lose;
880 if (cp[1] != '.')
881 goto lose;
882
883 cp += 2;
884
885 /* Check the width specification. */
886 width = -1;
887 if ('0' <= *cp && *cp <= '9')
888 {
889 width = 0;
890 do
891 width = (width * 10) + (*cp++ - '0');
892 while (*cp >= '0' && *cp <= '9');
893
894 /* A precision of zero is valid only for %f. */
895 if (width > DBL_DIG
896 || (width == 0 && *cp != 'f'))
897 goto lose;
898 }
899
900 if (*cp != 'e' && *cp != 'f' && *cp != 'g')
901 goto lose;
902
903 if (cp[1] != 0)
904 goto lose;
905
906 sprintf (buf, XSTRING (Vfloat_output_format)->data, data);
907 }
908
909 /* Make sure there is a decimal point with digit after, or an
910 exponent, so that the value is readable as a float. But don't do
911 this with "%.0f"; it's valid for that not to produce a decimal
912 point. Note that width can be 0 only for %.0f. */
913 if (width != 0)
914 {
915 for (cp = buf; *cp; cp++)
916 if ((*cp < '0' || *cp > '9') && *cp != '-')
917 break;
918
919 if (*cp == '.' && cp[1] == 0)
920 {
921 cp[1] = '0';
922 cp[2] = 0;
923 }
924
925 if (*cp == 0)
926 {
927 *cp++ = '.';
928 *cp++ = '0';
929 *cp++ = 0;
930 }
931 }
932 }
933 #endif /* LISP_FLOAT_TYPE */
934 \f
935 static void
936 print (obj, printcharfun, escapeflag)
937 Lisp_Object obj;
938 register Lisp_Object printcharfun;
939 int escapeflag;
940 {
941 char buf[30];
942
943 QUIT;
944
945 #if 1 /* I'm not sure this is really worth doing. */
946 /* Detect circularities and truncate them.
947 No need to offer any alternative--this is better than an error. */
948 if (CONSP (obj) || VECTORP (obj) || COMPILEDP (obj))
949 {
950 int i;
951 for (i = 0; i < print_depth; i++)
952 if (EQ (obj, being_printed[i]))
953 {
954 sprintf (buf, "#%d", i);
955 strout (buf, -1, printcharfun);
956 return;
957 }
958 }
959 #endif
960
961 being_printed[print_depth] = obj;
962 print_depth++;
963
964 if (print_depth > PRINT_CIRCLE)
965 error ("Apparently circular structure being printed");
966 #ifdef MAX_PRINT_CHARS
967 if (max_print && print_chars > max_print)
968 {
969 PRINTCHAR ('\n');
970 print_chars = 0;
971 }
972 #endif /* MAX_PRINT_CHARS */
973
974 switch (XGCTYPE (obj))
975 {
976 case Lisp_Int:
977 if (sizeof (int) == sizeof (EMACS_INT))
978 sprintf (buf, "%d", XINT (obj));
979 else if (sizeof (long) == sizeof (EMACS_INT))
980 sprintf (buf, "%ld", XINT (obj));
981 else
982 abort ();
983 strout (buf, -1, printcharfun);
984 break;
985
986 #ifdef LISP_FLOAT_TYPE
987 case Lisp_Float:
988 {
989 char pigbuf[350]; /* see comments in float_to_string */
990
991 float_to_string (pigbuf, XFLOAT(obj)->data);
992 strout (pigbuf, -1, printcharfun);
993 }
994 break;
995 #endif
996
997 case Lisp_String:
998 if (!escapeflag)
999 print_string (obj, printcharfun);
1000 else
1001 {
1002 register int i;
1003 register unsigned char c;
1004 struct gcpro gcpro1;
1005
1006 GCPRO1 (obj);
1007
1008 #ifdef USE_TEXT_PROPERTIES
1009 if (!NULL_INTERVAL_P (XSTRING (obj)->intervals))
1010 {
1011 PRINTCHAR ('#');
1012 PRINTCHAR ('(');
1013 }
1014 #endif
1015
1016 PRINTCHAR ('\"');
1017 for (i = 0; i < XSTRING (obj)->size; i++)
1018 {
1019 QUIT;
1020 c = XSTRING (obj)->data[i];
1021 if (c == '\n' && print_escape_newlines)
1022 {
1023 PRINTCHAR ('\\');
1024 PRINTCHAR ('n');
1025 }
1026 else if (c == '\f' && print_escape_newlines)
1027 {
1028 PRINTCHAR ('\\');
1029 PRINTCHAR ('f');
1030 }
1031 else
1032 {
1033 if (c == '\"' || c == '\\')
1034 PRINTCHAR ('\\');
1035 PRINTCHAR (c);
1036 }
1037 }
1038 PRINTCHAR ('\"');
1039
1040 #ifdef USE_TEXT_PROPERTIES
1041 if (!NULL_INTERVAL_P (XSTRING (obj)->intervals))
1042 {
1043 traverse_intervals (XSTRING (obj)->intervals,
1044 0, 0, print_interval, printcharfun);
1045 PRINTCHAR (')');
1046 }
1047 #endif
1048
1049 UNGCPRO;
1050 }
1051 break;
1052
1053 case Lisp_Symbol:
1054 {
1055 register int confusing;
1056 register unsigned char *p = XSYMBOL (obj)->name->data;
1057 register unsigned char *end = p + XSYMBOL (obj)->name->size;
1058 register unsigned char c;
1059 int i;
1060
1061 if (p != end && (*p == '-' || *p == '+')) p++;
1062 if (p == end)
1063 confusing = 0;
1064 /* If symbol name begins with a digit, and ends with a digit,
1065 and contains nothing but digits and `e', it could be treated
1066 as a number. So set CONFUSING.
1067
1068 Symbols that contain periods could also be taken as numbers,
1069 but periods are always escaped, so we don't have to worry
1070 about them here. */
1071 else if (*p >= '0' && *p <= '9'
1072 && end[-1] >= '0' && end[-1] <= '9')
1073 {
1074 while (p != end && ((*p >= '0' && *p <= '9')
1075 /* Needed for \2e10. */
1076 || *p == 'e'))
1077 p++;
1078 confusing = (end == p);
1079 }
1080 else
1081 confusing = 0;
1082
1083 /* If we print an uninterned symbol as part of a complex object and
1084 the flag print-gensym is non-nil, prefix it with #n= to read the
1085 object back with the #n# reader syntax later if needed. */
1086 if (! NILP (Vprint_gensym) && NILP (XSYMBOL (obj)->obarray))
1087 {
1088 if (print_depth > 1)
1089 {
1090 Lisp_Object tem;
1091 tem = Fassq (obj, Vprint_gensym_alist);
1092 if (CONSP (tem))
1093 {
1094 PRINTCHAR ('#');
1095 print (XCDR (tem), printcharfun, escapeflag);
1096 PRINTCHAR ('#');
1097 break;
1098 }
1099 else
1100 {
1101 if (CONSP (Vprint_gensym_alist))
1102 XSETFASTINT (tem, XFASTINT (XCDR (XCAR (Vprint_gensym_alist))) + 1);
1103 else
1104 XSETFASTINT (tem, 1);
1105 Vprint_gensym_alist = Fcons (Fcons (obj, tem), Vprint_gensym_alist);
1106
1107 PRINTCHAR ('#');
1108 print (tem, printcharfun, escapeflag);
1109 PRINTCHAR ('=');
1110 }
1111 }
1112 PRINTCHAR ('#');
1113 PRINTCHAR (':');
1114 }
1115
1116 for (i = 0; i < XSYMBOL (obj)->name->size; i++)
1117 {
1118 QUIT;
1119 c = XSYMBOL (obj)->name->data[i];
1120
1121 if (escapeflag)
1122 {
1123 if (c == '\"' || c == '\\' || c == '\''
1124 || c == ';' || c == '#' || c == '(' || c == ')'
1125 || c == ',' || c =='.' || c == '`'
1126 || c == '[' || c == ']' || c == '?' || c <= 040
1127 || confusing)
1128 PRINTCHAR ('\\'), confusing = 0;
1129 }
1130 PRINTCHAR (c);
1131 }
1132 }
1133 break;
1134
1135 case Lisp_Cons:
1136 /* If deeper than spec'd depth, print placeholder. */
1137 if (INTEGERP (Vprint_level)
1138 && print_depth > XINT (Vprint_level))
1139 strout ("...", -1, printcharfun);
1140 else if (print_quoted && CONSP (XCDR (obj)) && NILP (XCDR (XCDR (obj)))
1141 && (EQ (XCAR (obj), Qquote)))
1142 {
1143 PRINTCHAR ('\'');
1144 print (XCAR (XCDR (obj)), printcharfun, escapeflag);
1145 }
1146 else if (print_quoted && CONSP (XCDR (obj)) && NILP (XCDR (XCDR (obj)))
1147 && (EQ (XCAR (obj), Qfunction)))
1148 {
1149 PRINTCHAR ('#');
1150 PRINTCHAR ('\'');
1151 print (XCAR (XCDR (obj)), printcharfun, escapeflag);
1152 }
1153 else if (print_quoted && CONSP (XCDR (obj)) && NILP (XCDR (XCDR (obj)))
1154 && ((EQ (XCAR (obj), Qbackquote)
1155 || EQ (XCAR (obj), Qcomma)
1156 || EQ (XCAR (obj), Qcomma_at)
1157 || EQ (XCAR (obj), Qcomma_dot))))
1158 {
1159 print (XCAR (obj), printcharfun, 0);
1160 print (XCAR (XCDR (obj)), printcharfun, escapeflag);
1161 }
1162 else
1163 {
1164 PRINTCHAR ('(');
1165 {
1166 register int i = 0;
1167 register int max = 0;
1168
1169 if (INTEGERP (Vprint_length))
1170 max = XINT (Vprint_length);
1171 /* Could recognize circularities in cdrs here,
1172 but that would make printing of long lists quadratic.
1173 It's not worth doing. */
1174 while (CONSP (obj))
1175 {
1176 if (i++)
1177 PRINTCHAR (' ');
1178 if (max && i > max)
1179 {
1180 strout ("...", 3, printcharfun);
1181 break;
1182 }
1183 print (XCAR (obj), printcharfun, escapeflag);
1184 obj = XCDR (obj);
1185 }
1186 }
1187 if (!NILP (obj))
1188 {
1189 strout (" . ", 3, printcharfun);
1190 print (obj, printcharfun, escapeflag);
1191 }
1192 PRINTCHAR (')');
1193 }
1194 break;
1195
1196 case Lisp_Vectorlike:
1197 if (PROCESSP (obj))
1198 {
1199 if (escapeflag)
1200 {
1201 strout ("#<process ", -1, printcharfun);
1202 print_string (XPROCESS (obj)->name, printcharfun);
1203 PRINTCHAR ('>');
1204 }
1205 else
1206 print_string (XPROCESS (obj)->name, printcharfun);
1207 }
1208 else if (BOOL_VECTOR_P (obj))
1209 {
1210 register int i;
1211 register unsigned char c;
1212 struct gcpro gcpro1;
1213 int size_in_chars
1214 = (XBOOL_VECTOR (obj)->size + BITS_PER_CHAR - 1) / BITS_PER_CHAR;
1215
1216 GCPRO1 (obj);
1217
1218 PRINTCHAR ('#');
1219 PRINTCHAR ('&');
1220 sprintf (buf, "%d", XBOOL_VECTOR (obj)->size);
1221 strout (buf, -1, printcharfun);
1222 PRINTCHAR ('\"');
1223
1224 /* Don't print more characters than the specified maximum. */
1225 if (INTEGERP (Vprint_length)
1226 && XINT (Vprint_length) < size_in_chars)
1227 size_in_chars = XINT (Vprint_length);
1228
1229 for (i = 0; i < size_in_chars; i++)
1230 {
1231 QUIT;
1232 c = XBOOL_VECTOR (obj)->data[i];
1233 if (c == '\n' && print_escape_newlines)
1234 {
1235 PRINTCHAR ('\\');
1236 PRINTCHAR ('n');
1237 }
1238 else if (c == '\f' && print_escape_newlines)
1239 {
1240 PRINTCHAR ('\\');
1241 PRINTCHAR ('f');
1242 }
1243 else
1244 {
1245 if (c == '\"' || c == '\\')
1246 PRINTCHAR ('\\');
1247 PRINTCHAR (c);
1248 }
1249 }
1250 PRINTCHAR ('\"');
1251
1252 UNGCPRO;
1253 }
1254 else if (SUBRP (obj))
1255 {
1256 strout ("#<subr ", -1, printcharfun);
1257 strout (XSUBR (obj)->symbol_name, -1, printcharfun);
1258 PRINTCHAR ('>');
1259 }
1260 #ifndef standalone
1261 else if (WINDOWP (obj))
1262 {
1263 strout ("#<window ", -1, printcharfun);
1264 sprintf (buf, "%d", XFASTINT (XWINDOW (obj)->sequence_number));
1265 strout (buf, -1, printcharfun);
1266 if (!NILP (XWINDOW (obj)->buffer))
1267 {
1268 strout (" on ", -1, printcharfun);
1269 print_string (XBUFFER (XWINDOW (obj)->buffer)->name, printcharfun);
1270 }
1271 PRINTCHAR ('>');
1272 }
1273 else if (BUFFERP (obj))
1274 {
1275 if (NILP (XBUFFER (obj)->name))
1276 strout ("#<killed buffer>", -1, printcharfun);
1277 else if (escapeflag)
1278 {
1279 strout ("#<buffer ", -1, printcharfun);
1280 print_string (XBUFFER (obj)->name, printcharfun);
1281 PRINTCHAR ('>');
1282 }
1283 else
1284 print_string (XBUFFER (obj)->name, printcharfun);
1285 }
1286 else if (WINDOW_CONFIGURATIONP (obj))
1287 {
1288 strout ("#<window-configuration>", -1, printcharfun);
1289 }
1290 else if (FRAMEP (obj))
1291 {
1292 strout ((FRAME_LIVE_P (XFRAME (obj))
1293 ? "#<frame " : "#<dead frame "),
1294 -1, printcharfun);
1295 print_string (XFRAME (obj)->name, printcharfun);
1296 sprintf (buf, " 0x%lx", (unsigned long) (XFRAME (obj)));
1297 strout (buf, -1, printcharfun);
1298 PRINTCHAR ('>');
1299 }
1300 #endif /* not standalone */
1301 else
1302 {
1303 int size = XVECTOR (obj)->size;
1304 if (COMPILEDP (obj))
1305 {
1306 PRINTCHAR ('#');
1307 size &= PSEUDOVECTOR_SIZE_MASK;
1308 }
1309 if (CHAR_TABLE_P (obj))
1310 {
1311 /* We print a char-table as if it were a vector,
1312 lumping the parent and default slots in with the
1313 character slots. But we add #^ as a prefix. */
1314 PRINTCHAR ('#');
1315 PRINTCHAR ('^');
1316 if (SUB_CHAR_TABLE_P (obj))
1317 PRINTCHAR ('^');
1318 size &= PSEUDOVECTOR_SIZE_MASK;
1319 }
1320 if (size & PSEUDOVECTOR_FLAG)
1321 goto badtype;
1322
1323 PRINTCHAR ('[');
1324 {
1325 register int i;
1326 register Lisp_Object tem;
1327
1328 /* Don't print more elements than the specified maximum. */
1329 if (INTEGERP (Vprint_length)
1330 && XINT (Vprint_length) < size)
1331 size = XINT (Vprint_length);
1332
1333 for (i = 0; i < size; i++)
1334 {
1335 if (i) PRINTCHAR (' ');
1336 tem = XVECTOR (obj)->contents[i];
1337 print (tem, printcharfun, escapeflag);
1338 }
1339 }
1340 PRINTCHAR (']');
1341 }
1342 break;
1343
1344 #ifndef standalone
1345 case Lisp_Misc:
1346 switch (XMISCTYPE (obj))
1347 {
1348 case Lisp_Misc_Marker:
1349 strout ("#<marker ", -1, printcharfun);
1350 #if 0
1351 /* Do you think this is necessary? */
1352 if (XMARKER (obj)->insertion_type != 0)
1353 strout ("(before-insertion) ", -1, printcharfun);
1354 #endif /* 0 */
1355 if (!(XMARKER (obj)->buffer))
1356 strout ("in no buffer", -1, printcharfun);
1357 else
1358 {
1359 sprintf (buf, "at %d", marker_position (obj));
1360 strout (buf, -1, printcharfun);
1361 strout (" in ", -1, printcharfun);
1362 print_string (XMARKER (obj)->buffer->name, printcharfun);
1363 }
1364 PRINTCHAR ('>');
1365 break;
1366
1367 case Lisp_Misc_Overlay:
1368 strout ("#<overlay ", -1, printcharfun);
1369 if (!(XMARKER (OVERLAY_START (obj))->buffer))
1370 strout ("in no buffer", -1, printcharfun);
1371 else
1372 {
1373 sprintf (buf, "from %d to %d in ",
1374 marker_position (OVERLAY_START (obj)),
1375 marker_position (OVERLAY_END (obj)));
1376 strout (buf, -1, printcharfun);
1377 print_string (XMARKER (OVERLAY_START (obj))->buffer->name,
1378 printcharfun);
1379 }
1380 PRINTCHAR ('>');
1381 break;
1382
1383 /* Remaining cases shouldn't happen in normal usage, but let's print
1384 them anyway for the benefit of the debugger. */
1385 case Lisp_Misc_Free:
1386 strout ("#<misc free cell>", -1, printcharfun);
1387 break;
1388
1389 case Lisp_Misc_Intfwd:
1390 sprintf (buf, "#<intfwd to %d>", *XINTFWD (obj)->intvar);
1391 strout (buf, -1, printcharfun);
1392 break;
1393
1394 case Lisp_Misc_Boolfwd:
1395 sprintf (buf, "#<boolfwd to %s>",
1396 (*XBOOLFWD (obj)->boolvar ? "t" : "nil"));
1397 strout (buf, -1, printcharfun);
1398 break;
1399
1400 case Lisp_Misc_Objfwd:
1401 strout ("#<objfwd to ", -1, printcharfun);
1402 print (*XOBJFWD (obj)->objvar, printcharfun, escapeflag);
1403 PRINTCHAR ('>');
1404 break;
1405
1406 case Lisp_Misc_Buffer_Objfwd:
1407 strout ("#<buffer_objfwd to ", -1, printcharfun);
1408 print (*(Lisp_Object *)((char *)current_buffer
1409 + XBUFFER_OBJFWD (obj)->offset),
1410 printcharfun, escapeflag);
1411 PRINTCHAR ('>');
1412 break;
1413
1414 case Lisp_Misc_Kboard_Objfwd:
1415 strout ("#<kboard_objfwd to ", -1, printcharfun);
1416 print (*(Lisp_Object *)((char *) current_kboard
1417 + XKBOARD_OBJFWD (obj)->offset),
1418 printcharfun, escapeflag);
1419 PRINTCHAR ('>');
1420 break;
1421
1422 case Lisp_Misc_Buffer_Local_Value:
1423 strout ("#<buffer_local_value ", -1, printcharfun);
1424 goto do_buffer_local;
1425 case Lisp_Misc_Some_Buffer_Local_Value:
1426 strout ("#<some_buffer_local_value ", -1, printcharfun);
1427 do_buffer_local:
1428 strout ("[realvalue] ", -1, printcharfun);
1429 print (XBUFFER_LOCAL_VALUE (obj)->car, printcharfun, escapeflag);
1430 strout ("[buffer] ", -1, printcharfun);
1431 print (XCONS (XBUFFER_LOCAL_VALUE (obj)->cdr)->car,
1432 printcharfun, escapeflag);
1433 strout ("[alist-elt] ", -1, printcharfun);
1434 print (XCONS (XCONS (XBUFFER_LOCAL_VALUE (obj)->cdr)->cdr)->car,
1435 printcharfun, escapeflag);
1436 strout ("[default-value] ", -1, printcharfun);
1437 print (XCONS (XCONS (XBUFFER_LOCAL_VALUE (obj)->cdr)->cdr)->cdr,
1438 printcharfun, escapeflag);
1439 PRINTCHAR ('>');
1440 break;
1441
1442 default:
1443 goto badtype;
1444 }
1445 break;
1446 #endif /* standalone */
1447
1448 default:
1449 badtype:
1450 {
1451 /* We're in trouble if this happens!
1452 Probably should just abort () */
1453 strout ("#<EMACS BUG: INVALID DATATYPE ", -1, printcharfun);
1454 if (MISCP (obj))
1455 sprintf (buf, "(MISC 0x%04x)", (int) XMISCTYPE (obj));
1456 else if (VECTORLIKEP (obj))
1457 sprintf (buf, "(PVEC 0x%08x)", (int) XVECTOR (obj)->size);
1458 else
1459 sprintf (buf, "(0x%02x)", (int) XTYPE (obj));
1460 strout (buf, -1, printcharfun);
1461 strout (" Save your buffers immediately and please report this bug>",
1462 -1, printcharfun);
1463 }
1464 }
1465
1466 print_depth--;
1467 }
1468 \f
1469 #ifdef USE_TEXT_PROPERTIES
1470
1471 /* Print a description of INTERVAL using PRINTCHARFUN.
1472 This is part of printing a string that has text properties. */
1473
1474 void
1475 print_interval (interval, printcharfun)
1476 INTERVAL interval;
1477 Lisp_Object printcharfun;
1478 {
1479 PRINTCHAR (' ');
1480 print (make_number (interval->position), printcharfun, 1);
1481 PRINTCHAR (' ');
1482 print (make_number (interval->position + LENGTH (interval)),
1483 printcharfun, 1);
1484 PRINTCHAR (' ');
1485 print (interval->plist, printcharfun, 1);
1486 }
1487
1488 #endif /* USE_TEXT_PROPERTIES */
1489 \f
1490 void
1491 syms_of_print ()
1492 {
1493 DEFVAR_LISP ("standard-output", &Vstandard_output,
1494 "Output stream `print' uses by default for outputting a character.\n\
1495 This may be any function of one argument.\n\
1496 It may also be a buffer (output is inserted before point)\n\
1497 or a marker (output is inserted and the marker is advanced)\n\
1498 or the symbol t (output appears in the echo area).");
1499 Vstandard_output = Qt;
1500 Qstandard_output = intern ("standard-output");
1501 staticpro (&Qstandard_output);
1502
1503 #ifdef LISP_FLOAT_TYPE
1504 DEFVAR_LISP ("float-output-format", &Vfloat_output_format,
1505 "The format descriptor string used to print floats.\n\
1506 This is a %-spec like those accepted by `printf' in C,\n\
1507 but with some restrictions. It must start with the two characters `%.'.\n\
1508 After that comes an integer precision specification,\n\
1509 and then a letter which controls the format.\n\
1510 The letters allowed are `e', `f' and `g'.\n\
1511 Use `e' for exponential notation \"DIG.DIGITSeEXPT\"\n\
1512 Use `f' for decimal point notation \"DIGITS.DIGITS\".\n\
1513 Use `g' to choose the shorter of those two formats for the number at hand.\n\
1514 The precision in any of these cases is the number of digits following\n\
1515 the decimal point. With `f', a precision of 0 means to omit the\n\
1516 decimal point. 0 is not allowed with `e' or `g'.\n\n\
1517 A value of nil means to use `%.17g'.");
1518 Vfloat_output_format = Qnil;
1519 Qfloat_output_format = intern ("float-output-format");
1520 staticpro (&Qfloat_output_format);
1521 #endif /* LISP_FLOAT_TYPE */
1522
1523 DEFVAR_LISP ("print-length", &Vprint_length,
1524 "Maximum length of list to print before abbreviating.\n\
1525 A value of nil means no limit.");
1526 Vprint_length = Qnil;
1527
1528 DEFVAR_LISP ("print-level", &Vprint_level,
1529 "Maximum depth of list nesting to print before abbreviating.\n\
1530 A value of nil means no limit.");
1531 Vprint_level = Qnil;
1532
1533 DEFVAR_BOOL ("print-escape-newlines", &print_escape_newlines,
1534 "Non-nil means print newlines in strings as backslash-n.\n\
1535 Also print formfeeds as backslash-f.");
1536 print_escape_newlines = 0;
1537
1538 DEFVAR_BOOL ("print-quoted", &print_quoted,
1539 "Non-nil means print quoted forms with reader syntax.\n\
1540 I.e., (quote foo) prints as 'foo, (function foo) as #'foo, and, backquoted\n\
1541 forms print in the new syntax.");
1542 print_quoted = 0;
1543
1544 DEFVAR_LISP ("print-gensym", &Vprint_gensym,
1545 "Non-nil means print uninterned symbols so they will read as uninterned.\n\
1546 I.e., the value of (make-symbol "foobar") prints as #:foobar.\n\
1547 When the uninterned symbol appears within a larger data structure,\n\
1548 in addition use the #...# and #...= constructs as needed,\n\
1549 so that multiple references to the same symbol are shared once again\n\
1550 when the text is read back.\n\
1551 \n\
1552 If the value of `print-gensym' is a cons cell, then in addition refrain from\n\
1553 clearing `print-gensym-alist' on entry to and exit from printing functions,\n\
1554 so that the use of #...# and #...= can carry over for several separately\n\
1555 printed objects.");
1556 Vprint_gensym = Qnil;
1557
1558 DEFVAR_LISP ("print-gensym-alist", &Vprint_gensym_alist,
1559 "Association list of elements (GENSYM . N) to guide use of #N# and #N=.\n\
1560 In each element, GENSYM is an uninterned symbol that has been associated\n\
1561 with #N= for the specified value of N.");
1562 Vprint_gensym_alist = Qnil;
1563
1564 /* prin1_to_string_buffer initialized in init_buffer_once in buffer.c */
1565 staticpro (&Vprin1_to_string_buffer);
1566
1567 defsubr (&Sprin1);
1568 defsubr (&Sprin1_to_string);
1569 defsubr (&Serror_message_string);
1570 defsubr (&Sprinc);
1571 defsubr (&Sprint);
1572 defsubr (&Sterpri);
1573 defsubr (&Swrite_char);
1574 defsubr (&Sexternal_debugging_output);
1575
1576 Qexternal_debugging_output = intern ("external-debugging-output");
1577 staticpro (&Qexternal_debugging_output);
1578
1579 Qprint_escape_newlines = intern ("print-escape-newlines");
1580 staticpro (&Qprint_escape_newlines);
1581
1582 #ifndef standalone
1583 defsubr (&Swith_output_to_temp_buffer);
1584 #endif /* not standalone */
1585 }