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 Lisp_Object Qprint_quoted
;
87 /* Nonzero means print newline to stdout before next minibuffer message.
90 extern int noninteractive_need_newline
;
92 #ifdef MAX_PRINT_CHARS
93 static int print_chars
;
95 #endif /* MAX_PRINT_CHARS */
97 void print_interval ();
100 /* Convert between chars and GLYPHs */
104 register GLYPH
*glyphs
;
114 str_to_glyph_cpy (str
, glyphs
)
118 register GLYPH
*gp
= glyphs
;
119 register char *cp
= str
;
126 str_to_glyph_ncpy (str
, glyphs
, n
)
131 register GLYPH
*gp
= glyphs
;
132 register char *cp
= str
;
139 glyph_to_str_cpy (glyphs
, str
)
143 register GLYPH
*gp
= glyphs
;
144 register char *cp
= str
;
147 *str
++ = *gp
++ & 0377;
151 /* Low level output routines for characters and strings */
153 /* Lisp functions to do output using a stream
154 must have the stream in a variable called printcharfun
155 and must start with PRINTPREPARE and end with PRINTFINISH.
156 Use PRINTCHAR to output one character,
157 or call strout to output a block of characters.
158 Also, each one must have the declarations
159 struct buffer *old = current_buffer;
160 int old_point = -1, start_point;
161 Lisp_Object original;
164 #define PRINTPREPARE \
165 original = printcharfun; \
166 if (NILP (printcharfun)) printcharfun = Qt; \
167 if (BUFFERP (printcharfun)) \
168 { if (XBUFFER (printcharfun) != current_buffer) \
169 Fset_buffer (printcharfun); \
170 printcharfun = Qnil;} \
171 if (MARKERP (printcharfun)) \
172 { if (!(XMARKER (original)->buffer)) \
173 error ("Marker does not point anywhere"); \
174 if (XMARKER (original)->buffer != current_buffer) \
175 set_buffer_internal (XMARKER (original)->buffer); \
177 SET_PT (marker_position (printcharfun)); \
178 start_point = point; \
179 printcharfun = Qnil;} \
180 if (NILP (printcharfun)) \
182 print_buffer_pos = 0; \
183 print_buffer_size = 1000; \
184 print_buffer = (char *) xmalloc (print_buffer_size); \
189 #define PRINTFINISH \
190 if (NILP (printcharfun)) \
191 insert (print_buffer, print_buffer_pos); \
192 if (print_buffer) free (print_buffer); \
193 if (MARKERP (original)) \
194 Fset_marker (original, make_number (point), Qnil); \
195 if (old_point >= 0) \
196 SET_PT (old_point + (old_point >= start_point \
197 ? point - start_point : 0)); \
198 if (old != current_buffer) \
199 set_buffer_internal (old)
201 #define PRINTCHAR(ch) printchar (ch, printcharfun)
203 /* Index of first unused element of FRAME_MESSAGE_BUF(mini_frame). */
204 static int printbufidx
;
213 #ifdef MAX_PRINT_CHARS
216 #endif /* MAX_PRINT_CHARS */
221 if (print_buffer_pos
== print_buffer_size
)
222 print_buffer
= (char *) xrealloc (print_buffer
,
223 print_buffer_size
*= 2);
224 print_buffer
[print_buffer_pos
++] = ch
;
231 = XFRAME (WINDOW_FRAME (XWINDOW (minibuf_window
)));
236 noninteractive_need_newline
= 1;
240 if (echo_area_glyphs
!= FRAME_MESSAGE_BUF (mini_frame
)
241 || !message_buf_print
)
243 message_log_maybe_newline ();
244 echo_area_glyphs
= FRAME_MESSAGE_BUF (mini_frame
);
246 echo_area_glyphs_length
= 0;
247 message_buf_print
= 1;
250 message_dolog (&ch
, 1, 0);
251 if (printbufidx
< FRAME_WIDTH (mini_frame
) - 1)
252 FRAME_MESSAGE_BUF (mini_frame
)[printbufidx
++] = ch
;
253 FRAME_MESSAGE_BUF (mini_frame
)[printbufidx
] = 0;
254 echo_area_glyphs_length
= printbufidx
;
258 #endif /* not standalone */
260 XSETFASTINT (ch1
, ch
);
265 strout (ptr
, size
, printcharfun
)
268 Lisp_Object printcharfun
;
272 if (EQ (printcharfun
, Qnil
))
277 if (print_buffer_pos
+ size
> print_buffer_size
)
279 print_buffer_size
= print_buffer_size
* 2 + size
;
280 print_buffer
= (char *) xrealloc (print_buffer
,
283 bcopy (ptr
, print_buffer
+ print_buffer_pos
, size
);
284 print_buffer_pos
+= size
;
286 #ifdef MAX_PRINT_CHARS
289 #endif /* MAX_PRINT_CHARS */
292 if (EQ (printcharfun
, Qt
))
295 = XFRAME (WINDOW_FRAME (XWINDOW (minibuf_window
)));
297 i
= size
>= 0 ? size
: strlen (ptr
);
298 #ifdef MAX_PRINT_CHARS
301 #endif /* MAX_PRINT_CHARS */
305 fwrite (ptr
, 1, i
, stdout
);
306 noninteractive_need_newline
= 1;
310 if (echo_area_glyphs
!= FRAME_MESSAGE_BUF (mini_frame
)
311 || !message_buf_print
)
313 message_log_maybe_newline ();
314 echo_area_glyphs
= FRAME_MESSAGE_BUF (mini_frame
);
316 echo_area_glyphs_length
= 0;
317 message_buf_print
= 1;
320 message_dolog (ptr
, i
, 0);
321 if (i
> FRAME_WIDTH (mini_frame
) - printbufidx
- 1)
322 i
= FRAME_WIDTH (mini_frame
) - printbufidx
- 1;
323 bcopy (ptr
, &FRAME_MESSAGE_BUF (mini_frame
) [printbufidx
], i
);
325 echo_area_glyphs_length
= printbufidx
;
326 FRAME_MESSAGE_BUF (mini_frame
) [printbufidx
] = 0;
333 PRINTCHAR (ptr
[i
++]);
336 PRINTCHAR (ptr
[i
++]);
339 /* Print the contents of a string STRING using PRINTCHARFUN.
340 It isn't safe to use strout in many cases,
341 because printing one char can relocate. */
343 print_string (string
, printcharfun
)
345 Lisp_Object printcharfun
;
347 if (EQ (printcharfun
, Qt
) || NILP (printcharfun
))
348 /* strout is safe for output to a frame (echo area) or to print_buffer. */
349 strout (XSTRING (string
)->data
, XSTRING (string
)->size
, printcharfun
);
352 /* Otherwise, fetch the string address for each character. */
354 int size
= XSTRING (string
)->size
;
357 for (i
= 0; i
< size
; i
++)
358 PRINTCHAR (XSTRING (string
)->data
[i
]);
363 DEFUN ("write-char", Fwrite_char
, Swrite_char
, 1, 2, 0,
364 "Output character CHARACTER to stream PRINTCHARFUN.\n\
365 PRINTCHARFUN defaults to the value of `standard-output' (which see).")
366 (character
, printcharfun
)
367 Lisp_Object character
, printcharfun
;
369 struct buffer
*old
= current_buffer
;
372 Lisp_Object original
;
374 if (NILP (printcharfun
))
375 printcharfun
= Vstandard_output
;
376 CHECK_NUMBER (character
, 0);
378 PRINTCHAR (XINT (character
));
383 /* Used from outside of print.c to print a block of SIZE chars at DATA
384 on the default output stream.
385 Do not use this on the contents of a Lisp string. */
387 write_string (data
, size
)
391 struct buffer
*old
= current_buffer
;
392 Lisp_Object printcharfun
;
395 Lisp_Object original
;
397 printcharfun
= Vstandard_output
;
400 strout (data
, size
, printcharfun
);
404 /* Used from outside of print.c to print a block of SIZE chars at DATA
405 on a specified stream PRINTCHARFUN.
406 Do not use this on the contents of a Lisp string. */
408 write_string_1 (data
, size
, printcharfun
)
411 Lisp_Object printcharfun
;
413 struct buffer
*old
= current_buffer
;
416 Lisp_Object original
;
419 strout (data
, size
, printcharfun
);
427 temp_output_buffer_setup (bufname
)
430 register struct buffer
*old
= current_buffer
;
431 register Lisp_Object buf
;
433 Fset_buffer (Fget_buffer_create (build_string (bufname
)));
435 current_buffer
->directory
= old
->directory
;
436 current_buffer
->read_only
= Qnil
;
439 XSETBUFFER (buf
, current_buffer
);
440 specbind (Qstandard_output
, buf
);
442 set_buffer_internal (old
);
446 internal_with_output_to_temp_buffer (bufname
, function
, args
)
448 Lisp_Object (*function
) ();
451 int count
= specpdl_ptr
- specpdl
;
452 Lisp_Object buf
, val
;
456 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
457 temp_output_buffer_setup (bufname
);
458 buf
= Vstandard_output
;
461 val
= (*function
) (args
);
464 temp_output_buffer_show (buf
);
467 return unbind_to (count
, val
);
470 DEFUN ("with-output-to-temp-buffer", Fwith_output_to_temp_buffer
, Swith_output_to_temp_buffer
,
472 "Bind `standard-output' to buffer BUFNAME, eval BODY, then show that buffer.\n\
473 The buffer is cleared out initially, and marked as unmodified when done.\n\
474 All output done by BODY is inserted in that buffer by default.\n\
475 The buffer is displayed in another window, but not selected.\n\
476 The value of the last form in BODY is returned.\n\
477 If BODY does not finish normally, the buffer BUFNAME is not displayed.\n\n\
478 If variable `temp-buffer-show-function' is non-nil, call it at the end\n\
479 to get the buffer displayed. It gets one argument, the buffer to display.")
485 int count
= specpdl_ptr
- specpdl
;
486 Lisp_Object buf
, val
;
489 name
= Feval (Fcar (args
));
492 CHECK_STRING (name
, 0);
493 temp_output_buffer_setup (XSTRING (name
)->data
);
494 buf
= Vstandard_output
;
496 val
= Fprogn (Fcdr (args
));
498 temp_output_buffer_show (buf
);
500 return unbind_to (count
, val
);
502 #endif /* not standalone */
504 static void print ();
506 DEFUN ("terpri", Fterpri
, Sterpri
, 0, 1, 0,
507 "Output a newline to stream PRINTCHARFUN.\n\
508 If PRINTCHARFUN is omitted or nil, the value of `standard-output' is used.")
510 Lisp_Object printcharfun
;
512 struct buffer
*old
= current_buffer
;
515 Lisp_Object original
;
517 if (NILP (printcharfun
))
518 printcharfun
= Vstandard_output
;
525 DEFUN ("prin1", Fprin1
, Sprin1
, 1, 2, 0,
526 "Output the printed representation of OBJECT, any Lisp object.\n\
527 Quoting characters are printed when needed to make output that `read'\n\
528 can handle, whenever this is possible.\n\
529 Output stream is PRINTCHARFUN, or value of `standard-output' (which see).")
530 (object
, printcharfun
)
531 Lisp_Object object
, printcharfun
;
533 struct buffer
*old
= current_buffer
;
536 Lisp_Object original
;
538 #ifdef MAX_PRINT_CHARS
540 #endif /* MAX_PRINT_CHARS */
541 if (NILP (printcharfun
))
542 printcharfun
= Vstandard_output
;
545 print (object
, printcharfun
, 1);
550 /* a buffer which is used to hold output being built by prin1-to-string */
551 Lisp_Object Vprin1_to_string_buffer
;
553 DEFUN ("prin1-to-string", Fprin1_to_string
, Sprin1_to_string
, 1, 2, 0,
554 "Return a string containing the printed representation of OBJECT,\n\
555 any Lisp object. Quoting characters are used when needed to make output\n\
556 that `read' can handle, whenever this is possible, unless the optional\n\
557 second argument NOESCAPE is non-nil.")
559 Lisp_Object object
, noescape
;
561 struct buffer
*old
= current_buffer
;
564 Lisp_Object original
, printcharfun
;
565 struct gcpro gcpro1
, gcpro2
;
568 /* Save and restore this--we are altering a buffer
569 but we don't want to deactivate the mark just for that.
570 No need for specbind, since errors deactivate the mark. */
571 tem
= Vdeactivate_mark
;
572 GCPRO2 (object
, tem
);
574 printcharfun
= Vprin1_to_string_buffer
;
577 print (object
, printcharfun
, NILP (noescape
));
578 /* Make Vprin1_to_string_buffer be the default buffer after PRINTFINSH */
580 set_buffer_internal (XBUFFER (Vprin1_to_string_buffer
));
581 object
= Fbuffer_string ();
584 set_buffer_internal (old
);
586 Vdeactivate_mark
= tem
;
592 DEFUN ("princ", Fprinc
, Sprinc
, 1, 2, 0,
593 "Output the printed representation of OBJECT, any Lisp object.\n\
594 No quoting characters are used; no delimiters are printed around\n\
595 the contents of strings.\n\
596 Output stream is PRINTCHARFUN, or value of standard-output (which see).")
597 (object
, printcharfun
)
598 Lisp_Object object
, printcharfun
;
600 struct buffer
*old
= current_buffer
;
603 Lisp_Object original
;
605 if (NILP (printcharfun
))
606 printcharfun
= Vstandard_output
;
609 print (object
, printcharfun
, 0);
614 DEFUN ("print", Fprint
, Sprint
, 1, 2, 0,
615 "Output the printed representation of OBJECT, with newlines around it.\n\
616 Quoting characters are printed when needed to make output that `read'\n\
617 can handle, whenever this is possible.\n\
618 Output stream is PRINTCHARFUN, or value of `standard-output' (which see).")
619 (object
, printcharfun
)
620 Lisp_Object object
, printcharfun
;
622 struct buffer
*old
= current_buffer
;
625 Lisp_Object original
;
628 #ifdef MAX_PRINT_CHARS
630 max_print
= MAX_PRINT_CHARS
;
631 #endif /* MAX_PRINT_CHARS */
632 if (NILP (printcharfun
))
633 printcharfun
= Vstandard_output
;
638 print (object
, printcharfun
, 1);
641 #ifdef MAX_PRINT_CHARS
644 #endif /* MAX_PRINT_CHARS */
649 /* The subroutine object for external-debugging-output is kept here
650 for the convenience of the debugger. */
651 Lisp_Object Qexternal_debugging_output
;
653 DEFUN ("external-debugging-output", Fexternal_debugging_output
, Sexternal_debugging_output
, 1, 1, 0,
654 "Write CHARACTER to stderr.\n\
655 You can call print while debugging emacs, and pass it this function\n\
656 to make it write to the debugging output.\n")
658 Lisp_Object character
;
660 CHECK_NUMBER (character
, 0);
661 putc (XINT (character
), stderr
);
666 /* This is the interface for debugging printing. */
672 Fprin1 (arg
, Qexternal_debugging_output
);
673 fprintf (stderr
, "\r\n");
676 DEFUN ("error-message-string", Ferror_message_string
, Serror_message_string
,
678 "Convert an error value (ERROR-SYMBOL . DATA) to an error message.")
682 struct buffer
*old
= current_buffer
;
683 Lisp_Object original
, printcharfun
, value
;
686 print_error_message (obj
, Vprin1_to_string_buffer
, NULL
);
688 set_buffer_internal (XBUFFER (Vprin1_to_string_buffer
));
689 value
= Fbuffer_string ();
693 set_buffer_internal (old
);
699 /* Print an error message for the error DATA
700 onto Lisp output stream STREAM (suitable for the print functions). */
702 print_error_message (data
, stream
)
703 Lisp_Object data
, stream
;
705 Lisp_Object errname
, errmsg
, file_error
, tail
;
709 errname
= Fcar (data
);
711 if (EQ (errname
, Qerror
))
714 if (!CONSP (data
)) data
= Qnil
;
715 errmsg
= Fcar (data
);
720 errmsg
= Fget (errname
, Qerror_message
);
721 file_error
= Fmemq (Qfile_error
,
722 Fget (errname
, Qerror_conditions
));
725 /* Print an error message including the data items. */
727 tail
= Fcdr_safe (data
);
730 /* For file-error, make error message by concatenating
731 all the data items. They are all strings. */
732 if (!NILP (file_error
) && !NILP (tail
))
733 errmsg
= XCONS (tail
)->car
, tail
= XCONS (tail
)->cdr
;
735 if (STRINGP (errmsg
))
736 Fprinc (errmsg
, stream
);
738 write_string_1 ("peculiar error", -1, stream
);
740 for (i
= 0; CONSP (tail
); tail
= Fcdr (tail
), i
++)
742 write_string_1 (i
? ", " : ": ", 2, stream
);
743 if (!NILP (file_error
))
744 Fprinc (Fcar (tail
), stream
);
746 Fprin1 (Fcar (tail
), stream
);
751 #ifdef LISP_FLOAT_TYPE
754 * The buffer should be at least as large as the max string size of the
755 * largest float, printed in the biggest notation. This is undoubtedly
756 * 20d float_output_format, with the negative of the C-constant "HUGE"
759 * On the vax the worst case is -1e38 in 20d format which takes 61 bytes.
761 * I assume that IEEE-754 format numbers can take 329 bytes for the worst
762 * case of -1e307 in 20d float_output_format. What is one to do (short of
763 * re-writing _doprnt to be more sane)?
768 float_to_string (buf
, data
)
775 if (NILP (Vfloat_output_format
)
776 || !STRINGP (Vfloat_output_format
))
779 sprintf (buf
, "%.17g", data
);
784 /* Check that the spec we have is fully valid.
785 This means not only valid for printf,
786 but meant for floats, and reasonable. */
787 cp
= XSTRING (Vfloat_output_format
)->data
;
796 /* Check the width specification. */
798 if ('0' <= *cp
&& *cp
<= '9')
802 width
= (width
* 10) + (*cp
++ - '0');
803 while (*cp
>= '0' && *cp
<= '9');
805 /* A precision of zero is valid only for %f. */
807 || (width
== 0 && *cp
!= 'f'))
811 if (*cp
!= 'e' && *cp
!= 'f' && *cp
!= 'g')
817 sprintf (buf
, XSTRING (Vfloat_output_format
)->data
, data
);
820 /* Make sure there is a decimal point with digit after, or an
821 exponent, so that the value is readable as a float. But don't do
822 this with "%.0f"; it's valid for that not to produce a decimal
823 point. Note that width can be 0 only for %.0f. */
826 for (cp
= buf
; *cp
; cp
++)
827 if ((*cp
< '0' || *cp
> '9') && *cp
!= '-')
830 if (*cp
== '.' && cp
[1] == 0)
844 #endif /* LISP_FLOAT_TYPE */
847 print (obj
, printcharfun
, escapeflag
)
849 register Lisp_Object printcharfun
;
856 #if 1 /* I'm not sure this is really worth doing. */
857 /* Detect circularities and truncate them.
858 No need to offer any alternative--this is better than an error. */
859 if (CONSP (obj
) || VECTORP (obj
) || COMPILEDP (obj
))
862 for (i
= 0; i
< print_depth
; i
++)
863 if (EQ (obj
, being_printed
[i
]))
865 sprintf (buf
, "#%d", i
);
866 strout (buf
, -1, printcharfun
);
872 being_printed
[print_depth
] = obj
;
875 if (print_depth
> PRINT_CIRCLE
)
876 error ("Apparently circular structure being printed");
877 #ifdef MAX_PRINT_CHARS
878 if (max_print
&& print_chars
> max_print
)
883 #endif /* MAX_PRINT_CHARS */
885 switch (XGCTYPE (obj
))
888 if (sizeof (int) == sizeof (EMACS_INT
))
889 sprintf (buf
, "%d", XINT (obj
));
890 else if (sizeof (long) == sizeof (EMACS_INT
))
891 sprintf (buf
, "%ld", XINT (obj
));
894 strout (buf
, -1, printcharfun
);
897 #ifdef LISP_FLOAT_TYPE
900 char pigbuf
[350]; /* see comments in float_to_string */
902 float_to_string (pigbuf
, XFLOAT(obj
)->data
);
903 strout (pigbuf
, -1, printcharfun
);
910 print_string (obj
, printcharfun
);
914 register unsigned char c
;
919 #ifdef USE_TEXT_PROPERTIES
920 if (!NULL_INTERVAL_P (XSTRING (obj
)->intervals
))
928 for (i
= 0; i
< XSTRING (obj
)->size
; i
++)
931 c
= XSTRING (obj
)->data
[i
];
932 if (c
== '\n' && print_escape_newlines
)
937 else if (c
== '\f' && print_escape_newlines
)
944 if (c
== '\"' || c
== '\\')
951 #ifdef USE_TEXT_PROPERTIES
952 if (!NULL_INTERVAL_P (XSTRING (obj
)->intervals
))
954 traverse_intervals (XSTRING (obj
)->intervals
,
955 0, 0, print_interval
, printcharfun
);
966 register int confusing
;
967 register unsigned char *p
= XSYMBOL (obj
)->name
->data
;
968 register unsigned char *end
= p
+ XSYMBOL (obj
)->name
->size
;
969 register unsigned char c
;
971 if (p
!= end
&& (*p
== '-' || *p
== '+')) p
++;
976 while (p
!= end
&& *p
>= '0' && *p
<= '9')
978 confusing
= (end
== p
);
981 p
= XSYMBOL (obj
)->name
->data
;
988 if (c
== '\"' || c
== '\\' || c
== '\'' || c
== ';' || c
== '#' ||
989 c
== '(' || c
== ')' || c
== ',' || c
=='.' || c
== '`' ||
990 c
== '[' || c
== ']' || c
== '?' || c
<= 040 || confusing
)
991 PRINTCHAR ('\\'), confusing
= 0;
999 /* If deeper than spec'd depth, print placeholder. */
1000 if (INTEGERP (Vprint_level
)
1001 && print_depth
> XINT (Vprint_level
))
1002 strout ("...", -1, printcharfun
);
1003 else if (print_quoted
&& CONSP (XCDR (obj
)) && NILP (XCDR (XCDR (obj
)))
1004 && (EQ (XCAR (obj
), Qquote
)))
1007 print (XCAR (XCDR (obj
)), printcharfun
, escapeflag
);
1009 else if (print_quoted
&& CONSP (XCDR (obj
)) && NILP (XCDR (XCDR (obj
)))
1010 && (EQ (XCAR (obj
), Qfunction
)))
1014 print (XCAR (XCDR (obj
)), printcharfun
, escapeflag
);
1016 else if (print_quoted
&& CONSP (XCDR (obj
)) && NILP (XCDR (XCDR (obj
)))
1017 && ((EQ (XCAR (obj
), Qbackquote
)
1018 || EQ (XCAR (obj
), Qcomma
)
1019 || EQ (XCAR (obj
), Qcomma_at
)
1020 || EQ (XCAR (obj
), Qcomma_dot
))))
1022 print (XCAR (obj
), printcharfun
, 0);
1023 print (XCAR (XCDR (obj
)), printcharfun
, escapeflag
);
1030 register int max
= 0;
1032 if (INTEGERP (Vprint_length
))
1033 max
= XINT (Vprint_length
);
1034 /* Could recognize circularities in cdrs here,
1035 but that would make printing of long lists quadratic.
1036 It's not worth doing. */
1043 strout ("...", 3, printcharfun
);
1046 print (XCAR (obj
), printcharfun
, escapeflag
);
1052 strout (" . ", 3, printcharfun
);
1053 print (obj
, printcharfun
, escapeflag
);
1059 case Lisp_Vectorlike
:
1064 strout ("#<process ", -1, printcharfun
);
1065 print_string (XPROCESS (obj
)->name
, printcharfun
);
1069 print_string (XPROCESS (obj
)->name
, printcharfun
);
1071 else if (BOOL_VECTOR_P (obj
))
1074 register unsigned char c
;
1075 struct gcpro gcpro1
;
1077 = (XBOOL_VECTOR (obj
)->size
+ BITS_PER_CHAR
) / BITS_PER_CHAR
;
1083 sprintf (buf
, "%d", XBOOL_VECTOR (obj
)->size
);
1084 strout (buf
, -1, printcharfun
);
1087 /* Don't print more characters than the specified maximum. */
1088 if (INTEGERP (Vprint_length
)
1089 && XINT (Vprint_length
) < size_in_chars
)
1090 size_in_chars
= XINT (Vprint_length
);
1092 for (i
= 0; i
< size_in_chars
; i
++)
1095 c
= XBOOL_VECTOR (obj
)->data
[i
];
1096 if (c
== '\n' && print_escape_newlines
)
1101 else if (c
== '\f' && print_escape_newlines
)
1108 if (c
== '\"' || c
== '\\')
1117 else if (SUBRP (obj
))
1119 strout ("#<subr ", -1, printcharfun
);
1120 strout (XSUBR (obj
)->symbol_name
, -1, printcharfun
);
1124 else if (WINDOWP (obj
))
1126 strout ("#<window ", -1, printcharfun
);
1127 sprintf (buf
, "%d", XFASTINT (XWINDOW (obj
)->sequence_number
));
1128 strout (buf
, -1, printcharfun
);
1129 if (!NILP (XWINDOW (obj
)->buffer
))
1131 strout (" on ", -1, printcharfun
);
1132 print_string (XBUFFER (XWINDOW (obj
)->buffer
)->name
, printcharfun
);
1136 else if (BUFFERP (obj
))
1138 if (NILP (XBUFFER (obj
)->name
))
1139 strout ("#<killed buffer>", -1, printcharfun
);
1140 else if (escapeflag
)
1142 strout ("#<buffer ", -1, printcharfun
);
1143 print_string (XBUFFER (obj
)->name
, printcharfun
);
1147 print_string (XBUFFER (obj
)->name
, printcharfun
);
1149 else if (WINDOW_CONFIGURATIONP (obj
))
1151 strout ("#<window-configuration>", -1, printcharfun
);
1154 else if (FRAMEP (obj
))
1156 strout ((FRAME_LIVE_P (XFRAME (obj
))
1157 ? "#<frame " : "#<dead frame "),
1159 print_string (XFRAME (obj
)->name
, printcharfun
);
1160 sprintf (buf
, " 0x%lx", (unsigned long) (XFRAME (obj
)));
1161 strout (buf
, -1, printcharfun
);
1165 #endif /* not standalone */
1168 int size
= XVECTOR (obj
)->size
;
1169 if (COMPILEDP (obj
))
1172 size
&= PSEUDOVECTOR_SIZE_MASK
;
1174 if (CHAR_TABLE_P (obj
))
1176 /* We print a char-table as if it were a vector,
1177 lumping the parent and default slots in with the
1178 character slots. But we add #^ as a prefix. */
1181 size
&= PSEUDOVECTOR_SIZE_MASK
;
1183 if (size
& PSEUDOVECTOR_FLAG
)
1189 register Lisp_Object tem
;
1191 /* Don't print more elements than the specified maximum. */
1192 if (INTEGERP (Vprint_length
)
1193 && XINT (Vprint_length
) < size
)
1194 size
= XINT (Vprint_length
);
1196 for (i
= 0; i
< size
; i
++)
1198 if (i
) PRINTCHAR (' ');
1199 tem
= XVECTOR (obj
)->contents
[i
];
1200 print (tem
, printcharfun
, escapeflag
);
1209 switch (XMISCTYPE (obj
))
1211 case Lisp_Misc_Marker
:
1212 strout ("#<marker ", -1, printcharfun
);
1213 if (!(XMARKER (obj
)->buffer
))
1214 strout ("in no buffer", -1, printcharfun
);
1217 sprintf (buf
, "at %d", marker_position (obj
));
1218 strout (buf
, -1, printcharfun
);
1219 strout (" in ", -1, printcharfun
);
1220 print_string (XMARKER (obj
)->buffer
->name
, printcharfun
);
1225 case Lisp_Misc_Overlay
:
1226 strout ("#<overlay ", -1, printcharfun
);
1227 if (!(XMARKER (OVERLAY_START (obj
))->buffer
))
1228 strout ("in no buffer", -1, printcharfun
);
1231 sprintf (buf
, "from %d to %d in ",
1232 marker_position (OVERLAY_START (obj
)),
1233 marker_position (OVERLAY_END (obj
)));
1234 strout (buf
, -1, printcharfun
);
1235 print_string (XMARKER (OVERLAY_START (obj
))->buffer
->name
,
1241 /* Remaining cases shouldn't happen in normal usage, but let's print
1242 them anyway for the benefit of the debugger. */
1243 case Lisp_Misc_Free
:
1244 strout ("#<misc free cell>", -1, printcharfun
);
1247 case Lisp_Misc_Intfwd
:
1248 sprintf (buf
, "#<intfwd to %d>", *XINTFWD (obj
)->intvar
);
1249 strout (buf
, -1, printcharfun
);
1252 case Lisp_Misc_Boolfwd
:
1253 sprintf (buf
, "#<boolfwd to %s>",
1254 (*XBOOLFWD (obj
)->boolvar
? "t" : "nil"));
1255 strout (buf
, -1, printcharfun
);
1258 case Lisp_Misc_Objfwd
:
1259 strout ("#<objfwd to ", -1, printcharfun
);
1260 print (*XOBJFWD (obj
)->objvar
, printcharfun
, escapeflag
);
1264 case Lisp_Misc_Buffer_Objfwd
:
1265 strout ("#<buffer_objfwd to ", -1, printcharfun
);
1266 print (*(Lisp_Object
*)((char *)current_buffer
1267 + XBUFFER_OBJFWD (obj
)->offset
),
1268 printcharfun
, escapeflag
);
1272 case Lisp_Misc_Kboard_Objfwd
:
1273 strout ("#<kboard_objfwd to ", -1, printcharfun
);
1274 print (*(Lisp_Object
*)((char *) current_kboard
1275 + XKBOARD_OBJFWD (obj
)->offset
),
1276 printcharfun
, escapeflag
);
1280 case Lisp_Misc_Buffer_Local_Value
:
1281 strout ("#<buffer_local_value ", -1, printcharfun
);
1282 goto do_buffer_local
;
1283 case Lisp_Misc_Some_Buffer_Local_Value
:
1284 strout ("#<some_buffer_local_value ", -1, printcharfun
);
1286 strout ("[realvalue] ", -1, printcharfun
);
1287 print (XBUFFER_LOCAL_VALUE (obj
)->car
, printcharfun
, escapeflag
);
1288 strout ("[buffer] ", -1, printcharfun
);
1289 print (XCONS (XBUFFER_LOCAL_VALUE (obj
)->cdr
)->car
,
1290 printcharfun
, escapeflag
);
1291 strout ("[alist-elt] ", -1, printcharfun
);
1292 print (XCONS (XCONS (XBUFFER_LOCAL_VALUE (obj
)->cdr
)->cdr
)->car
,
1293 printcharfun
, escapeflag
);
1294 strout ("[default-value] ", -1, printcharfun
);
1295 print (XCONS (XCONS (XBUFFER_LOCAL_VALUE (obj
)->cdr
)->cdr
)->cdr
,
1296 printcharfun
, escapeflag
);
1304 #endif /* standalone */
1309 /* We're in trouble if this happens!
1310 Probably should just abort () */
1311 strout ("#<EMACS BUG: INVALID DATATYPE ", -1, printcharfun
);
1313 sprintf (buf
, "(MISC 0x%04x)", (int) XMISCTYPE (obj
));
1314 else if (VECTORLIKEP (obj
))
1315 sprintf (buf
, "(PVEC 0x%08x)", (int) XVECTOR (obj
)->size
);
1317 sprintf (buf
, "(0x%02x)", (int) XTYPE (obj
));
1318 strout (buf
, -1, printcharfun
);
1319 strout (" Save your buffers immediately and please report this bug>",
1327 #ifdef USE_TEXT_PROPERTIES
1329 /* Print a description of INTERVAL using PRINTCHARFUN.
1330 This is part of printing a string that has text properties. */
1333 print_interval (interval
, printcharfun
)
1335 Lisp_Object printcharfun
;
1338 print (make_number (interval
->position
), printcharfun
, 1);
1340 print (make_number (interval
->position
+ LENGTH (interval
)),
1343 print (interval
->plist
, printcharfun
, 1);
1346 #endif /* USE_TEXT_PROPERTIES */
1351 DEFVAR_LISP ("standard-output", &Vstandard_output
,
1352 "Output stream `print' uses by default for outputting a character.\n\
1353 This may be any function of one argument.\n\
1354 It may also be a buffer (output is inserted before point)\n\
1355 or a marker (output is inserted and the marker is advanced)\n\
1356 or the symbol t (output appears in the echo area).");
1357 Vstandard_output
= Qt
;
1358 Qstandard_output
= intern ("standard-output");
1359 staticpro (&Qstandard_output
);
1361 #ifdef LISP_FLOAT_TYPE
1362 DEFVAR_LISP ("float-output-format", &Vfloat_output_format
,
1363 "The format descriptor string used to print floats.\n\
1364 This is a %-spec like those accepted by `printf' in C,\n\
1365 but with some restrictions. It must start with the two characters `%.'.\n\
1366 After that comes an integer precision specification,\n\
1367 and then a letter which controls the format.\n\
1368 The letters allowed are `e', `f' and `g'.\n\
1369 Use `e' for exponential notation \"DIG.DIGITSeEXPT\"\n\
1370 Use `f' for decimal point notation \"DIGITS.DIGITS\".\n\
1371 Use `g' to choose the shorter of those two formats for the number at hand.\n\
1372 The precision in any of these cases is the number of digits following\n\
1373 the decimal point. With `f', a precision of 0 means to omit the\n\
1374 decimal point. 0 is not allowed with `e' or `g'.\n\n\
1375 A value of nil means to use `%.17g'.");
1376 Vfloat_output_format
= Qnil
;
1377 Qfloat_output_format
= intern ("float-output-format");
1378 staticpro (&Qfloat_output_format
);
1379 #endif /* LISP_FLOAT_TYPE */
1381 DEFVAR_LISP ("print-length", &Vprint_length
,
1382 "Maximum length of list to print before abbreviating.\n\
1383 A value of nil means no limit.");
1384 Vprint_length
= Qnil
;
1386 DEFVAR_LISP ("print-level", &Vprint_level
,
1387 "Maximum depth of list nesting to print before abbreviating.\n\
1388 A value of nil means no limit.");
1389 Vprint_level
= Qnil
;
1391 DEFVAR_BOOL ("print-escape-newlines", &print_escape_newlines
,
1392 "Non-nil means print newlines in strings as backslash-n.\n\
1393 Also print formfeeds as backslash-f.");
1394 print_escape_newlines
= 0;
1396 DEFVAR_BOOL ("print-quoted", &print_quoted
,
1397 "Non-nil means print quoted forms with reader syntax.\n\
1398 I.e., (quote foo) prints as 'foo, (function foo) as #'foo, and, backquoted\n\
1399 forms print in the new syntax.");
1402 /* prin1_to_string_buffer initialized in init_buffer_once in buffer.c */
1403 staticpro (&Vprin1_to_string_buffer
);
1406 defsubr (&Sprin1_to_string
);
1407 defsubr (&Serror_message_string
);
1411 defsubr (&Swrite_char
);
1412 defsubr (&Sexternal_debugging_output
);
1414 Qexternal_debugging_output
= intern ("external-debugging-output");
1415 staticpro (&Qexternal_debugging_output
);
1417 Qprint_escape_newlines
= intern ("print-escape-newlines");
1418 staticpro (&Qprint_escape_newlines
);
1420 Qprint_quoted
= intern ("print-quoted");
1421 staticpro (&Qprint_quoted
);
1424 defsubr (&Swith_output_to_temp_buffer
);
1425 #endif /* not standalone */