1 /* Lisp object printing and output streams.
2 Copyright (C) 1985, 86, 88, 93, 94, 95 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
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)
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.
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. */
31 #include "dispextern.h"
34 #endif /* not standalone */
36 #ifdef USE_TEXT_PROPERTIES
37 #include "intervals.h"
40 Lisp_Object Vstandard_output
, Qstandard_output
;
42 /* These are used to print like we read. */
43 extern Lisp_Object Qbackquote
, Qcomma
, Qcomma_at
, Qcomma_dot
, Qfunction
;
45 #ifdef LISP_FLOAT_TYPE
46 Lisp_Object Vfloat_output_format
, Qfloat_output_format
;
47 #endif /* LISP_FLOAT_TYPE */
49 /* Avoid actual stack overflow in print. */
52 /* Detect most circularities to print finite output. */
53 #define PRINT_CIRCLE 200
54 Lisp_Object being_printed
[PRINT_CIRCLE
];
56 /* When printing into a buffer, first we put the text in this
57 block, then insert it all at once. */
60 /* Size allocated in print_buffer. */
61 int print_buffer_size
;
62 /* Size used in print_buffer. */
65 /* Maximum length of list to print in full; noninteger means
66 effectively infinity */
68 Lisp_Object Vprint_length
;
70 /* Maximum depth of list to print in full; noninteger means
71 effectively infinity. */
73 Lisp_Object Vprint_level
;
75 /* Nonzero means print newlines in strings as \n. */
77 int print_escape_newlines
;
79 Lisp_Object Qprint_escape_newlines
;
81 /* Nonzero means print (quote foo) forms as 'foo, etc. */
85 /* Nonzero means print #: before uninterned symbols. */
89 /* Association list of certain objects that are `eq' in the form being
90 printed and which should be `eq' when read back in, using the #n=object
91 and #n# reader forms. Each element has the form (object . n). */
93 Lisp_Object printed_gensyms
;
95 /* Nonzero means print newline to stdout before next minibuffer message.
98 extern int noninteractive_need_newline
;
100 #ifdef MAX_PRINT_CHARS
101 static int print_chars
;
102 static int max_print
;
103 #endif /* MAX_PRINT_CHARS */
105 void print_interval ();
108 /* Convert between chars and GLYPHs */
112 register GLYPH
*glyphs
;
122 str_to_glyph_cpy (str
, glyphs
)
126 register GLYPH
*gp
= glyphs
;
127 register char *cp
= str
;
134 str_to_glyph_ncpy (str
, glyphs
, n
)
139 register GLYPH
*gp
= glyphs
;
140 register char *cp
= str
;
147 glyph_to_str_cpy (glyphs
, str
)
151 register GLYPH
*gp
= glyphs
;
152 register char *cp
= str
;
155 *str
++ = *gp
++ & 0377;
159 /* Low level output routines for characters and strings */
161 /* Lisp functions to do output using a stream
162 must have the stream in a variable called printcharfun
163 and must start with PRINTPREPARE, end with PRINTFINISH,
164 and use PRINTDECLARE to declare common variables.
165 Use PRINTCHAR to output one character,
166 or call strout to output a block of characters.
169 #define PRINTDECLARE \
170 struct buffer *old = current_buffer; \
171 int old_point = -1, start_point; \
172 int specpdl_count = specpdl_ptr - specpdl; \
173 int free_print_buffer = 0; \
176 #define PRINTPREPARE \
177 original = printcharfun; \
178 if (NILP (printcharfun)) printcharfun = Qt; \
179 if (BUFFERP (printcharfun)) \
181 if (XBUFFER (printcharfun) != current_buffer) \
182 Fset_buffer (printcharfun); \
183 printcharfun = Qnil; \
185 if (MARKERP (printcharfun)) \
187 if (!(XMARKER (original)->buffer)) \
188 error ("Marker does not point anywhere"); \
189 if (XMARKER (original)->buffer != current_buffer) \
190 set_buffer_internal (XMARKER (original)->buffer); \
192 SET_PT (marker_position (printcharfun)); \
194 printcharfun = Qnil; \
196 if (NILP (printcharfun)) \
198 if (print_buffer != 0) \
199 record_unwind_protect (print_unwind, \
200 make_string (print_buffer, \
201 print_buffer_pos)); \
204 print_buffer_size = 1000; \
205 print_buffer = (char *) xmalloc (print_buffer_size); \
206 free_print_buffer = 1; \
208 print_buffer_pos = 0; \
210 printed_gensyms = Qnil
212 #define PRINTFINISH \
213 if (NILP (printcharfun)) \
214 insert (print_buffer, print_buffer_pos); \
215 if (free_print_buffer) \
217 xfree (print_buffer); \
220 unbind_to (specpdl_count, Qnil); \
221 if (MARKERP (original)) \
222 Fset_marker (original, make_number (PT), Qnil); \
223 if (old_point >= 0) \
224 SET_PT (old_point + (old_point >= start_point \
225 ? PT - start_point : 0)); \
226 if (old != current_buffer) \
227 set_buffer_internal (old); \
228 printed_gensyms = Qnil
230 #define PRINTCHAR(ch) printchar (ch, printcharfun)
232 /* Nonzero if there is no room to print any more characters
233 so print might as well return right away. */
235 #define PRINTFULLP() \
236 (EQ (printcharfun, Qt) && !noninteractive \
237 && printbufidx >= FRAME_WIDTH (XFRAME (WINDOW_FRAME (XWINDOW (minibuf_window)))))
239 /* This is used to restore the saved contents of print_buffer
240 when there is a recursive call to print. */
242 print_unwind (saved_text
)
243 Lisp_Object saved_text
;
245 bcopy (XSTRING (saved_text
)->data
, print_buffer
, XSTRING (saved_text
)->size
);
248 /* Index of first unused element of FRAME_MESSAGE_BUF (mini_frame). */
249 static int printbufidx
;
258 #ifdef MAX_PRINT_CHARS
261 #endif /* MAX_PRINT_CHARS */
266 if (print_buffer_pos
== print_buffer_size
)
267 print_buffer
= (char *) xrealloc (print_buffer
,
268 print_buffer_size
*= 2);
269 print_buffer
[print_buffer_pos
++] = ch
;
276 = XFRAME (WINDOW_FRAME (XWINDOW (minibuf_window
)));
283 noninteractive_need_newline
= 1;
287 if (echo_area_glyphs
!= FRAME_MESSAGE_BUF (mini_frame
)
288 || !message_buf_print
)
290 message_log_maybe_newline ();
291 echo_area_glyphs
= FRAME_MESSAGE_BUF (mini_frame
);
293 echo_area_glyphs_length
= 0;
294 message_buf_print
= 1;
297 message_dolog (&ch
, 1, 0);
298 if (printbufidx
< FRAME_WIDTH (mini_frame
) - 1)
299 FRAME_MESSAGE_BUF (mini_frame
)[printbufidx
++] = ch
;
300 FRAME_MESSAGE_BUF (mini_frame
)[printbufidx
] = 0;
301 echo_area_glyphs_length
= printbufidx
;
305 #endif /* not standalone */
307 XSETFASTINT (ch1
, ch
);
312 strout (ptr
, size
, printcharfun
)
315 Lisp_Object printcharfun
;
319 if (EQ (printcharfun
, Qnil
))
324 if (print_buffer_pos
+ size
> print_buffer_size
)
326 print_buffer_size
= print_buffer_size
* 2 + size
;
327 print_buffer
= (char *) xrealloc (print_buffer
,
330 bcopy (ptr
, print_buffer
+ print_buffer_pos
, size
);
331 print_buffer_pos
+= size
;
333 #ifdef MAX_PRINT_CHARS
336 #endif /* MAX_PRINT_CHARS */
339 if (EQ (printcharfun
, Qt
))
342 = XFRAME (WINDOW_FRAME (XWINDOW (minibuf_window
)));
346 i
= size
>= 0 ? size
: strlen (ptr
);
347 #ifdef MAX_PRINT_CHARS
350 #endif /* MAX_PRINT_CHARS */
354 fwrite (ptr
, 1, i
, stdout
);
355 noninteractive_need_newline
= 1;
359 if (echo_area_glyphs
!= FRAME_MESSAGE_BUF (mini_frame
)
360 || !message_buf_print
)
362 message_log_maybe_newline ();
363 echo_area_glyphs
= FRAME_MESSAGE_BUF (mini_frame
);
365 echo_area_glyphs_length
= 0;
366 message_buf_print
= 1;
369 message_dolog (ptr
, i
, 0);
370 if (i
> FRAME_WIDTH (mini_frame
) - printbufidx
- 1)
371 i
= FRAME_WIDTH (mini_frame
) - printbufidx
- 1;
372 bcopy (ptr
, &FRAME_MESSAGE_BUF (mini_frame
) [printbufidx
], i
);
374 echo_area_glyphs_length
= printbufidx
;
375 FRAME_MESSAGE_BUF (mini_frame
) [printbufidx
] = 0;
382 PRINTCHAR (ptr
[i
++]);
385 PRINTCHAR (ptr
[i
++]);
388 /* Print the contents of a string STRING using PRINTCHARFUN.
389 It isn't safe to use strout in many cases,
390 because printing one char can relocate. */
392 print_string (string
, printcharfun
)
394 Lisp_Object printcharfun
;
396 if (EQ (printcharfun
, Qt
) || NILP (printcharfun
))
397 /* strout is safe for output to a frame (echo area) or to print_buffer. */
398 strout (XSTRING (string
)->data
, XSTRING (string
)->size
, printcharfun
);
401 /* Otherwise, fetch the string address for each character. */
403 int size
= XSTRING (string
)->size
;
406 for (i
= 0; i
< size
; i
++)
407 PRINTCHAR (XSTRING (string
)->data
[i
]);
412 DEFUN ("write-char", Fwrite_char
, Swrite_char
, 1, 2, 0,
413 "Output character CHARACTER to stream PRINTCHARFUN.\n\
414 PRINTCHARFUN defaults to the value of `standard-output' (which see).")
415 (character
, printcharfun
)
416 Lisp_Object character
, printcharfun
;
420 if (NILP (printcharfun
))
421 printcharfun
= Vstandard_output
;
422 CHECK_NUMBER (character
, 0);
424 PRINTCHAR (XINT (character
));
429 /* Used from outside of print.c to print a block of SIZE chars at DATA
430 on the default output stream.
431 Do not use this on the contents of a Lisp string. */
433 write_string (data
, size
)
438 Lisp_Object printcharfun
;
440 printcharfun
= Vstandard_output
;
443 strout (data
, size
, printcharfun
);
447 /* Used from outside of print.c to print a block of SIZE chars at DATA
448 on a specified stream PRINTCHARFUN.
449 Do not use this on the contents of a Lisp string. */
451 write_string_1 (data
, size
, printcharfun
)
454 Lisp_Object printcharfun
;
459 strout (data
, size
, printcharfun
);
467 temp_output_buffer_setup (bufname
)
470 register struct buffer
*old
= current_buffer
;
471 register Lisp_Object buf
;
473 Fset_buffer (Fget_buffer_create (build_string (bufname
)));
475 current_buffer
->directory
= old
->directory
;
476 current_buffer
->read_only
= Qnil
;
479 XSETBUFFER (buf
, current_buffer
);
480 specbind (Qstandard_output
, buf
);
482 set_buffer_internal (old
);
486 internal_with_output_to_temp_buffer (bufname
, function
, args
)
488 Lisp_Object (*function
) ();
491 int count
= specpdl_ptr
- specpdl
;
492 Lisp_Object buf
, val
;
496 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
497 temp_output_buffer_setup (bufname
);
498 buf
= Vstandard_output
;
501 val
= (*function
) (args
);
504 temp_output_buffer_show (buf
);
507 return unbind_to (count
, val
);
510 DEFUN ("with-output-to-temp-buffer", Fwith_output_to_temp_buffer
, Swith_output_to_temp_buffer
,
512 "Bind `standard-output' to buffer BUFNAME, eval BODY, then show that buffer.\n\
513 The buffer is cleared out initially, and marked as unmodified when done.\n\
514 All output done by BODY is inserted in that buffer by default.\n\
515 The buffer is displayed in another window, but not selected.\n\
516 The value of the last form in BODY is returned.\n\
517 If BODY does not finish normally, the buffer BUFNAME is not displayed.\n\n\
518 If variable `temp-buffer-show-function' is non-nil, call it at the end\n\
519 to get the buffer displayed. It gets one argument, the buffer to display.")
525 int count
= specpdl_ptr
- specpdl
;
526 Lisp_Object buf
, val
;
529 name
= Feval (Fcar (args
));
532 CHECK_STRING (name
, 0);
533 temp_output_buffer_setup (XSTRING (name
)->data
);
534 buf
= Vstandard_output
;
536 val
= Fprogn (Fcdr (args
));
538 temp_output_buffer_show (buf
);
540 return unbind_to (count
, val
);
542 #endif /* not standalone */
544 static void print ();
546 DEFUN ("terpri", Fterpri
, Sterpri
, 0, 1, 0,
547 "Output a newline to stream PRINTCHARFUN.\n\
548 If PRINTCHARFUN is omitted or nil, the value of `standard-output' is used.")
550 Lisp_Object printcharfun
;
554 if (NILP (printcharfun
))
555 printcharfun
= Vstandard_output
;
562 DEFUN ("prin1", Fprin1
, Sprin1
, 1, 2, 0,
563 "Output the printed representation of OBJECT, any Lisp object.\n\
564 Quoting characters are printed when needed to make output that `read'\n\
565 can handle, whenever this is possible.\n\
566 Output stream is PRINTCHARFUN, or value of `standard-output' (which see).")
567 (object
, printcharfun
)
568 Lisp_Object object
, printcharfun
;
572 #ifdef MAX_PRINT_CHARS
574 #endif /* MAX_PRINT_CHARS */
575 if (NILP (printcharfun
))
576 printcharfun
= Vstandard_output
;
579 print (object
, printcharfun
, 1);
584 /* a buffer which is used to hold output being built by prin1-to-string */
585 Lisp_Object Vprin1_to_string_buffer
;
587 DEFUN ("prin1-to-string", Fprin1_to_string
, Sprin1_to_string
, 1, 2, 0,
588 "Return a string containing the printed representation of OBJECT,\n\
589 any Lisp object. Quoting characters are used when needed to make output\n\
590 that `read' can handle, whenever this is possible, unless the optional\n\
591 second argument NOESCAPE is non-nil.")
593 Lisp_Object object
, noescape
;
596 Lisp_Object printcharfun
;
597 struct gcpro gcpro1
, gcpro2
;
600 /* Save and restore this--we are altering a buffer
601 but we don't want to deactivate the mark just for that.
602 No need for specbind, since errors deactivate the mark. */
603 tem
= Vdeactivate_mark
;
604 GCPRO2 (object
, tem
);
606 printcharfun
= Vprin1_to_string_buffer
;
609 print (object
, printcharfun
, NILP (noescape
));
610 /* Make Vprin1_to_string_buffer be the default buffer after PRINTFINSH */
612 set_buffer_internal (XBUFFER (Vprin1_to_string_buffer
));
613 object
= Fbuffer_string ();
616 set_buffer_internal (old
);
618 Vdeactivate_mark
= tem
;
624 DEFUN ("princ", Fprinc
, Sprinc
, 1, 2, 0,
625 "Output the printed representation of OBJECT, any Lisp object.\n\
626 No quoting characters are used; no delimiters are printed around\n\
627 the contents of strings.\n\
628 Output stream is PRINTCHARFUN, or value of standard-output (which see).")
629 (object
, printcharfun
)
630 Lisp_Object object
, printcharfun
;
634 if (NILP (printcharfun
))
635 printcharfun
= Vstandard_output
;
638 print (object
, printcharfun
, 0);
643 DEFUN ("print", Fprint
, Sprint
, 1, 2, 0,
644 "Output the printed representation of OBJECT, with newlines around it.\n\
645 Quoting characters are printed when needed to make output that `read'\n\
646 can handle, whenever this is possible.\n\
647 Output stream is PRINTCHARFUN, or value of `standard-output' (which see).")
648 (object
, printcharfun
)
649 Lisp_Object object
, printcharfun
;
654 #ifdef MAX_PRINT_CHARS
656 max_print
= MAX_PRINT_CHARS
;
657 #endif /* MAX_PRINT_CHARS */
658 if (NILP (printcharfun
))
659 printcharfun
= Vstandard_output
;
664 print (object
, printcharfun
, 1);
667 #ifdef MAX_PRINT_CHARS
670 #endif /* MAX_PRINT_CHARS */
675 /* The subroutine object for external-debugging-output is kept here
676 for the convenience of the debugger. */
677 Lisp_Object Qexternal_debugging_output
;
679 DEFUN ("external-debugging-output", Fexternal_debugging_output
, Sexternal_debugging_output
, 1, 1, 0,
680 "Write CHARACTER to stderr.\n\
681 You can call print while debugging emacs, and pass it this function\n\
682 to make it write to the debugging output.\n")
684 Lisp_Object character
;
686 CHECK_NUMBER (character
, 0);
687 putc (XINT (character
), stderr
);
692 /* This is the interface for debugging printing. */
698 Fprin1 (arg
, Qexternal_debugging_output
);
699 fprintf (stderr
, "\r\n");
702 DEFUN ("error-message-string", Ferror_message_string
, Serror_message_string
,
704 "Convert an error value (ERROR-SYMBOL . DATA) to an error message.")
708 struct buffer
*old
= current_buffer
;
709 Lisp_Object original
, printcharfun
, value
;
712 print_error_message (obj
, Vprin1_to_string_buffer
, NULL
);
714 set_buffer_internal (XBUFFER (Vprin1_to_string_buffer
));
715 value
= Fbuffer_string ();
719 set_buffer_internal (old
);
725 /* Print an error message for the error DATA
726 onto Lisp output stream STREAM (suitable for the print functions). */
728 print_error_message (data
, stream
)
729 Lisp_Object data
, stream
;
731 Lisp_Object errname
, errmsg
, file_error
, tail
;
735 errname
= Fcar (data
);
737 if (EQ (errname
, Qerror
))
740 if (!CONSP (data
)) data
= Qnil
;
741 errmsg
= Fcar (data
);
746 errmsg
= Fget (errname
, Qerror_message
);
747 file_error
= Fmemq (Qfile_error
,
748 Fget (errname
, Qerror_conditions
));
751 /* Print an error message including the data items. */
753 tail
= Fcdr_safe (data
);
756 /* For file-error, make error message by concatenating
757 all the data items. They are all strings. */
758 if (!NILP (file_error
) && !NILP (tail
))
759 errmsg
= XCONS (tail
)->car
, tail
= XCONS (tail
)->cdr
;
761 if (STRINGP (errmsg
))
762 Fprinc (errmsg
, stream
);
764 write_string_1 ("peculiar error", -1, stream
);
766 for (i
= 0; CONSP (tail
); tail
= Fcdr (tail
), i
++)
768 write_string_1 (i
? ", " : ": ", 2, stream
);
769 if (!NILP (file_error
))
770 Fprinc (Fcar (tail
), stream
);
772 Fprin1 (Fcar (tail
), stream
);
777 #ifdef LISP_FLOAT_TYPE
780 * The buffer should be at least as large as the max string size of the
781 * largest float, printed in the biggest notation. This is undoubtedly
782 * 20d float_output_format, with the negative of the C-constant "HUGE"
785 * On the vax the worst case is -1e38 in 20d format which takes 61 bytes.
787 * I assume that IEEE-754 format numbers can take 329 bytes for the worst
788 * case of -1e307 in 20d float_output_format. What is one to do (short of
789 * re-writing _doprnt to be more sane)?
794 float_to_string (buf
, data
)
801 if (NILP (Vfloat_output_format
)
802 || !STRINGP (Vfloat_output_format
))
805 sprintf (buf
, "%.17g", data
);
810 /* Check that the spec we have is fully valid.
811 This means not only valid for printf,
812 but meant for floats, and reasonable. */
813 cp
= XSTRING (Vfloat_output_format
)->data
;
822 /* Check the width specification. */
824 if ('0' <= *cp
&& *cp
<= '9')
828 width
= (width
* 10) + (*cp
++ - '0');
829 while (*cp
>= '0' && *cp
<= '9');
831 /* A precision of zero is valid only for %f. */
833 || (width
== 0 && *cp
!= 'f'))
837 if (*cp
!= 'e' && *cp
!= 'f' && *cp
!= 'g')
843 sprintf (buf
, XSTRING (Vfloat_output_format
)->data
, data
);
846 /* Make sure there is a decimal point with digit after, or an
847 exponent, so that the value is readable as a float. But don't do
848 this with "%.0f"; it's valid for that not to produce a decimal
849 point. Note that width can be 0 only for %.0f. */
852 for (cp
= buf
; *cp
; cp
++)
853 if ((*cp
< '0' || *cp
> '9') && *cp
!= '-')
856 if (*cp
== '.' && cp
[1] == 0)
870 #endif /* LISP_FLOAT_TYPE */
873 print (obj
, printcharfun
, escapeflag
)
875 register Lisp_Object printcharfun
;
882 #if 1 /* I'm not sure this is really worth doing. */
883 /* Detect circularities and truncate them.
884 No need to offer any alternative--this is better than an error. */
885 if (CONSP (obj
) || VECTORP (obj
) || COMPILEDP (obj
))
888 for (i
= 0; i
< print_depth
; i
++)
889 if (EQ (obj
, being_printed
[i
]))
891 sprintf (buf
, "#%d", i
);
892 strout (buf
, -1, printcharfun
);
898 being_printed
[print_depth
] = obj
;
901 if (print_depth
> PRINT_CIRCLE
)
902 error ("Apparently circular structure being printed");
903 #ifdef MAX_PRINT_CHARS
904 if (max_print
&& print_chars
> max_print
)
909 #endif /* MAX_PRINT_CHARS */
911 switch (XGCTYPE (obj
))
914 if (sizeof (int) == sizeof (EMACS_INT
))
915 sprintf (buf
, "%d", XINT (obj
));
916 else if (sizeof (long) == sizeof (EMACS_INT
))
917 sprintf (buf
, "%ld", XINT (obj
));
920 strout (buf
, -1, printcharfun
);
923 #ifdef LISP_FLOAT_TYPE
926 char pigbuf
[350]; /* see comments in float_to_string */
928 float_to_string (pigbuf
, XFLOAT(obj
)->data
);
929 strout (pigbuf
, -1, printcharfun
);
936 print_string (obj
, printcharfun
);
940 register unsigned char c
;
945 #ifdef USE_TEXT_PROPERTIES
946 if (!NULL_INTERVAL_P (XSTRING (obj
)->intervals
))
954 for (i
= 0; i
< XSTRING (obj
)->size
; i
++)
957 c
= XSTRING (obj
)->data
[i
];
958 if (c
== '\n' && print_escape_newlines
)
963 else if (c
== '\f' && print_escape_newlines
)
970 if (c
== '\"' || c
== '\\')
977 #ifdef USE_TEXT_PROPERTIES
978 if (!NULL_INTERVAL_P (XSTRING (obj
)->intervals
))
980 traverse_intervals (XSTRING (obj
)->intervals
,
981 0, 0, print_interval
, printcharfun
);
992 register int confusing
;
993 register unsigned char *p
= XSYMBOL (obj
)->name
->data
;
994 register unsigned char *end
= p
+ XSYMBOL (obj
)->name
->size
;
995 register unsigned char c
;
998 if (p
!= end
&& (*p
== '-' || *p
== '+')) p
++;
1003 while (p
!= end
&& *p
>= '0' && *p
<= '9')
1005 confusing
= (end
== p
);
1008 /* If we print an uninterned symbol as part of a complex object and
1009 the flag print-gensym is non-nil, prefix it with #n= to read the
1010 object back with the #n# reader syntax later if needed. */
1011 if (print_gensym
&& NILP (XSYMBOL (obj
)->obarray
))
1013 if (print_depth
> 1)
1016 tem
= Fassq (obj
, printed_gensyms
);
1020 print (XCDR (tem
), printcharfun
, escapeflag
);
1026 if (CONSP (printed_gensyms
))
1027 XSETFASTINT (tem
, XCDR (XCAR (printed_gensyms
)) + 1);
1029 XSETFASTINT (tem
, 1);
1030 printed_gensyms
= Fcons (Fcons (obj
, tem
), printed_gensyms
);
1033 print (tem
, printcharfun
, escapeflag
);
1041 for (i
= 0; i
< XSYMBOL (obj
)->name
->size
; i
++)
1044 c
= XSYMBOL (obj
)->name
->data
[i
];
1048 if (c
== '\"' || c
== '\\' || c
== '\''
1049 || c
== ';' || c
== '#' || c
== '(' || c
== ')'
1050 || c
== ',' || c
=='.' || c
== '`'
1051 || c
== '[' || c
== ']' || c
== '?' || c
<= 040
1053 PRINTCHAR ('\\'), confusing
= 0;
1061 /* If deeper than spec'd depth, print placeholder. */
1062 if (INTEGERP (Vprint_level
)
1063 && print_depth
> XINT (Vprint_level
))
1064 strout ("...", -1, printcharfun
);
1065 else if (print_quoted
&& CONSP (XCDR (obj
)) && NILP (XCDR (XCDR (obj
)))
1066 && (EQ (XCAR (obj
), Qquote
)))
1069 print (XCAR (XCDR (obj
)), printcharfun
, escapeflag
);
1071 else if (print_quoted
&& CONSP (XCDR (obj
)) && NILP (XCDR (XCDR (obj
)))
1072 && (EQ (XCAR (obj
), Qfunction
)))
1076 print (XCAR (XCDR (obj
)), printcharfun
, escapeflag
);
1078 else if (print_quoted
&& CONSP (XCDR (obj
)) && NILP (XCDR (XCDR (obj
)))
1079 && ((EQ (XCAR (obj
), Qbackquote
)
1080 || EQ (XCAR (obj
), Qcomma
)
1081 || EQ (XCAR (obj
), Qcomma_at
)
1082 || EQ (XCAR (obj
), Qcomma_dot
))))
1084 print (XCAR (obj
), printcharfun
, 0);
1085 print (XCAR (XCDR (obj
)), printcharfun
, escapeflag
);
1092 register int max
= 0;
1094 if (INTEGERP (Vprint_length
))
1095 max
= XINT (Vprint_length
);
1096 /* Could recognize circularities in cdrs here,
1097 but that would make printing of long lists quadratic.
1098 It's not worth doing. */
1105 strout ("...", 3, printcharfun
);
1108 print (XCAR (obj
), printcharfun
, escapeflag
);
1114 strout (" . ", 3, printcharfun
);
1115 print (obj
, printcharfun
, escapeflag
);
1121 case Lisp_Vectorlike
:
1126 strout ("#<process ", -1, printcharfun
);
1127 print_string (XPROCESS (obj
)->name
, printcharfun
);
1131 print_string (XPROCESS (obj
)->name
, printcharfun
);
1133 else if (BOOL_VECTOR_P (obj
))
1136 register unsigned char c
;
1137 struct gcpro gcpro1
;
1139 = (XBOOL_VECTOR (obj
)->size
+ BITS_PER_CHAR
- 1) / BITS_PER_CHAR
;
1145 sprintf (buf
, "%d", XBOOL_VECTOR (obj
)->size
);
1146 strout (buf
, -1, printcharfun
);
1149 /* Don't print more characters than the specified maximum. */
1150 if (INTEGERP (Vprint_length
)
1151 && XINT (Vprint_length
) < size_in_chars
)
1152 size_in_chars
= XINT (Vprint_length
);
1154 for (i
= 0; i
< size_in_chars
; i
++)
1157 c
= XBOOL_VECTOR (obj
)->data
[i
];
1158 if (c
== '\n' && print_escape_newlines
)
1163 else if (c
== '\f' && print_escape_newlines
)
1170 if (c
== '\"' || c
== '\\')
1179 else if (SUBRP (obj
))
1181 strout ("#<subr ", -1, printcharfun
);
1182 strout (XSUBR (obj
)->symbol_name
, -1, printcharfun
);
1186 else if (WINDOWP (obj
))
1188 strout ("#<window ", -1, printcharfun
);
1189 sprintf (buf
, "%d", XFASTINT (XWINDOW (obj
)->sequence_number
));
1190 strout (buf
, -1, printcharfun
);
1191 if (!NILP (XWINDOW (obj
)->buffer
))
1193 strout (" on ", -1, printcharfun
);
1194 print_string (XBUFFER (XWINDOW (obj
)->buffer
)->name
, printcharfun
);
1198 else if (BUFFERP (obj
))
1200 if (NILP (XBUFFER (obj
)->name
))
1201 strout ("#<killed buffer>", -1, printcharfun
);
1202 else if (escapeflag
)
1204 strout ("#<buffer ", -1, printcharfun
);
1205 print_string (XBUFFER (obj
)->name
, printcharfun
);
1209 print_string (XBUFFER (obj
)->name
, printcharfun
);
1211 else if (WINDOW_CONFIGURATIONP (obj
))
1213 strout ("#<window-configuration>", -1, printcharfun
);
1215 else if (FRAMEP (obj
))
1217 strout ((FRAME_LIVE_P (XFRAME (obj
))
1218 ? "#<frame " : "#<dead frame "),
1220 print_string (XFRAME (obj
)->name
, printcharfun
);
1221 sprintf (buf
, " 0x%lx", (unsigned long) (XFRAME (obj
)));
1222 strout (buf
, -1, printcharfun
);
1225 #endif /* not standalone */
1228 int size
= XVECTOR (obj
)->size
;
1229 if (COMPILEDP (obj
))
1232 size
&= PSEUDOVECTOR_SIZE_MASK
;
1234 if (CHAR_TABLE_P (obj
))
1236 /* We print a char-table as if it were a vector,
1237 lumping the parent and default slots in with the
1238 character slots. But we add #^ as a prefix. */
1241 size
&= PSEUDOVECTOR_SIZE_MASK
;
1243 if (size
& PSEUDOVECTOR_FLAG
)
1249 register Lisp_Object tem
;
1251 /* Don't print more elements than the specified maximum. */
1252 if (INTEGERP (Vprint_length
)
1253 && XINT (Vprint_length
) < size
)
1254 size
= XINT (Vprint_length
);
1256 for (i
= 0; i
< size
; i
++)
1258 if (i
) PRINTCHAR (' ');
1259 tem
= XVECTOR (obj
)->contents
[i
];
1260 print (tem
, printcharfun
, escapeflag
);
1269 switch (XMISCTYPE (obj
))
1271 case Lisp_Misc_Marker
:
1272 strout ("#<marker ", -1, printcharfun
);
1273 if (!(XMARKER (obj
)->buffer
))
1274 strout ("in no buffer", -1, printcharfun
);
1277 sprintf (buf
, "at %d", marker_position (obj
));
1278 strout (buf
, -1, printcharfun
);
1279 strout (" in ", -1, printcharfun
);
1280 print_string (XMARKER (obj
)->buffer
->name
, printcharfun
);
1285 case Lisp_Misc_Overlay
:
1286 strout ("#<overlay ", -1, printcharfun
);
1287 if (!(XMARKER (OVERLAY_START (obj
))->buffer
))
1288 strout ("in no buffer", -1, printcharfun
);
1291 sprintf (buf
, "from %d to %d in ",
1292 marker_position (OVERLAY_START (obj
)),
1293 marker_position (OVERLAY_END (obj
)));
1294 strout (buf
, -1, printcharfun
);
1295 print_string (XMARKER (OVERLAY_START (obj
))->buffer
->name
,
1301 /* Remaining cases shouldn't happen in normal usage, but let's print
1302 them anyway for the benefit of the debugger. */
1303 case Lisp_Misc_Free
:
1304 strout ("#<misc free cell>", -1, printcharfun
);
1307 case Lisp_Misc_Intfwd
:
1308 sprintf (buf
, "#<intfwd to %d>", *XINTFWD (obj
)->intvar
);
1309 strout (buf
, -1, printcharfun
);
1312 case Lisp_Misc_Boolfwd
:
1313 sprintf (buf
, "#<boolfwd to %s>",
1314 (*XBOOLFWD (obj
)->boolvar
? "t" : "nil"));
1315 strout (buf
, -1, printcharfun
);
1318 case Lisp_Misc_Objfwd
:
1319 strout ("#<objfwd to ", -1, printcharfun
);
1320 print (*XOBJFWD (obj
)->objvar
, printcharfun
, escapeflag
);
1324 case Lisp_Misc_Buffer_Objfwd
:
1325 strout ("#<buffer_objfwd to ", -1, printcharfun
);
1326 print (*(Lisp_Object
*)((char *)current_buffer
1327 + XBUFFER_OBJFWD (obj
)->offset
),
1328 printcharfun
, escapeflag
);
1332 case Lisp_Misc_Kboard_Objfwd
:
1333 strout ("#<kboard_objfwd to ", -1, printcharfun
);
1334 print (*(Lisp_Object
*)((char *) current_kboard
1335 + XKBOARD_OBJFWD (obj
)->offset
),
1336 printcharfun
, escapeflag
);
1340 case Lisp_Misc_Buffer_Local_Value
:
1341 strout ("#<buffer_local_value ", -1, printcharfun
);
1342 goto do_buffer_local
;
1343 case Lisp_Misc_Some_Buffer_Local_Value
:
1344 strout ("#<some_buffer_local_value ", -1, printcharfun
);
1346 strout ("[realvalue] ", -1, printcharfun
);
1347 print (XBUFFER_LOCAL_VALUE (obj
)->car
, printcharfun
, escapeflag
);
1348 strout ("[buffer] ", -1, printcharfun
);
1349 print (XCONS (XBUFFER_LOCAL_VALUE (obj
)->cdr
)->car
,
1350 printcharfun
, escapeflag
);
1351 strout ("[alist-elt] ", -1, printcharfun
);
1352 print (XCONS (XCONS (XBUFFER_LOCAL_VALUE (obj
)->cdr
)->cdr
)->car
,
1353 printcharfun
, escapeflag
);
1354 strout ("[default-value] ", -1, printcharfun
);
1355 print (XCONS (XCONS (XBUFFER_LOCAL_VALUE (obj
)->cdr
)->cdr
)->cdr
,
1356 printcharfun
, escapeflag
);
1364 #endif /* standalone */
1369 /* We're in trouble if this happens!
1370 Probably should just abort () */
1371 strout ("#<EMACS BUG: INVALID DATATYPE ", -1, printcharfun
);
1373 sprintf (buf
, "(MISC 0x%04x)", (int) XMISCTYPE (obj
));
1374 else if (VECTORLIKEP (obj
))
1375 sprintf (buf
, "(PVEC 0x%08x)", (int) XVECTOR (obj
)->size
);
1377 sprintf (buf
, "(0x%02x)", (int) XTYPE (obj
));
1378 strout (buf
, -1, printcharfun
);
1379 strout (" Save your buffers immediately and please report this bug>",
1387 #ifdef USE_TEXT_PROPERTIES
1389 /* Print a description of INTERVAL using PRINTCHARFUN.
1390 This is part of printing a string that has text properties. */
1393 print_interval (interval
, printcharfun
)
1395 Lisp_Object printcharfun
;
1398 print (make_number (interval
->position
), printcharfun
, 1);
1400 print (make_number (interval
->position
+ LENGTH (interval
)),
1403 print (interval
->plist
, printcharfun
, 1);
1406 #endif /* USE_TEXT_PROPERTIES */
1411 DEFVAR_LISP ("standard-output", &Vstandard_output
,
1412 "Output stream `print' uses by default for outputting a character.\n\
1413 This may be any function of one argument.\n\
1414 It may also be a buffer (output is inserted before point)\n\
1415 or a marker (output is inserted and the marker is advanced)\n\
1416 or the symbol t (output appears in the echo area).");
1417 Vstandard_output
= Qt
;
1418 Qstandard_output
= intern ("standard-output");
1419 staticpro (&Qstandard_output
);
1421 #ifdef LISP_FLOAT_TYPE
1422 DEFVAR_LISP ("float-output-format", &Vfloat_output_format
,
1423 "The format descriptor string used to print floats.\n\
1424 This is a %-spec like those accepted by `printf' in C,\n\
1425 but with some restrictions. It must start with the two characters `%.'.\n\
1426 After that comes an integer precision specification,\n\
1427 and then a letter which controls the format.\n\
1428 The letters allowed are `e', `f' and `g'.\n\
1429 Use `e' for exponential notation \"DIG.DIGITSeEXPT\"\n\
1430 Use `f' for decimal point notation \"DIGITS.DIGITS\".\n\
1431 Use `g' to choose the shorter of those two formats for the number at hand.\n\
1432 The precision in any of these cases is the number of digits following\n\
1433 the decimal point. With `f', a precision of 0 means to omit the\n\
1434 decimal point. 0 is not allowed with `e' or `g'.\n\n\
1435 A value of nil means to use `%.17g'.");
1436 Vfloat_output_format
= Qnil
;
1437 Qfloat_output_format
= intern ("float-output-format");
1438 staticpro (&Qfloat_output_format
);
1439 #endif /* LISP_FLOAT_TYPE */
1441 DEFVAR_LISP ("print-length", &Vprint_length
,
1442 "Maximum length of list to print before abbreviating.\n\
1443 A value of nil means no limit.");
1444 Vprint_length
= Qnil
;
1446 DEFVAR_LISP ("print-level", &Vprint_level
,
1447 "Maximum depth of list nesting to print before abbreviating.\n\
1448 A value of nil means no limit.");
1449 Vprint_level
= Qnil
;
1451 DEFVAR_BOOL ("print-escape-newlines", &print_escape_newlines
,
1452 "Non-nil means print newlines in strings as backslash-n.\n\
1453 Also print formfeeds as backslash-f.");
1454 print_escape_newlines
= 0;
1456 DEFVAR_BOOL ("print-quoted", &print_quoted
,
1457 "Non-nil means print quoted forms with reader syntax.\n\
1458 I.e., (quote foo) prints as 'foo, (function foo) as #'foo, and, backquoted\n\
1459 forms print in the new syntax.");
1462 DEFVAR_BOOL ("print-gensym", &print_gensym
,
1463 "Non-nil means print uninterned symbols so they will read as uninterned.\n\
1464 I.e., the value of (make-symbol "foobar
") prints as #:foobar.");
1467 /* prin1_to_string_buffer initialized in init_buffer_once in buffer.c */
1468 staticpro (&Vprin1_to_string_buffer
);
1471 defsubr (&Sprin1_to_string
);
1472 defsubr (&Serror_message_string
);
1476 defsubr (&Swrite_char
);
1477 defsubr (&Sexternal_debugging_output
);
1479 Qexternal_debugging_output
= intern ("external-debugging-output");
1480 staticpro (&Qexternal_debugging_output
);
1482 Qprint_escape_newlines
= intern ("print-escape-newlines");
1483 staticpro (&Qprint_escape_newlines
);
1485 staticpro (&printed_gensyms
);
1486 printed_gensyms
= Qnil
;
1489 defsubr (&Swith_output_to_temp_buffer
);
1490 #endif /* not standalone */