Mercurial > emacs
annotate src/print.c @ 5307:069c54e77fd1
Don't repeat at load time any bindings that are autoloaded.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 23 Dec 1993 04:52:56 +0000 |
parents | 83e771f33251 |
children | 58a9bb23c3ea |
rev | line source |
---|---|
329 | 1 /* Lisp object printing and output streams. |
1967 | 2 Copyright (C) 1985, 1986, 1988, 1993 Free Software Foundation, Inc. |
329 | 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 | |
621 | 8 the Free Software Foundation; either version 2, or (at your option) |
329 | 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, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | |
20 | |
4696
1fc792473491
Include <config.h> instead of "config.h".
Roland McGrath <roland@gnu.org>
parents:
4224
diff
changeset
|
21 #include <config.h> |
329 | 22 #include <stdio.h> |
23 #undef NULL | |
24 #include "lisp.h" | |
25 | |
26 #ifndef standalone | |
27 #include "buffer.h" | |
766 | 28 #include "frame.h" |
329 | 29 #include "window.h" |
30 #include "process.h" | |
31 #include "dispextern.h" | |
32 #include "termchar.h" | |
33 #endif /* not standalone */ | |
34 | |
1967 | 35 #ifdef USE_TEXT_PROPERTIES |
36 #include "intervals.h" | |
37 #endif | |
38 | |
329 | 39 Lisp_Object Vstandard_output, Qstandard_output; |
40 | |
41 #ifdef LISP_FLOAT_TYPE | |
42 Lisp_Object Vfloat_output_format, Qfloat_output_format; | |
43 #endif /* LISP_FLOAT_TYPE */ | |
44 | |
45 /* Avoid actual stack overflow in print. */ | |
46 int print_depth; | |
47 | |
379
34ec8957c6c0
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
373
diff
changeset
|
48 /* Detect most circularities to print finite output. */ |
34ec8957c6c0
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
373
diff
changeset
|
49 #define PRINT_CIRCLE 200 |
34ec8957c6c0
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
373
diff
changeset
|
50 Lisp_Object being_printed[PRINT_CIRCLE]; |
34ec8957c6c0
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
373
diff
changeset
|
51 |
329 | 52 /* Maximum length of list to print in full; noninteger means |
53 effectively infinity */ | |
54 | |
55 Lisp_Object Vprint_length; | |
56 | |
57 /* Maximum depth of list to print in full; noninteger means | |
58 effectively infinity. */ | |
59 | |
60 Lisp_Object Vprint_level; | |
61 | |
62 /* Nonzero means print newlines in strings as \n. */ | |
63 | |
64 int print_escape_newlines; | |
65 | |
66 Lisp_Object Qprint_escape_newlines; | |
67 | |
68 /* Nonzero means print newline before next minibuffer message. | |
69 Defined in xdisp.c */ | |
70 | |
71 extern int noninteractive_need_newline; | |
72 #ifdef MAX_PRINT_CHARS | |
73 static int print_chars; | |
74 static int max_print; | |
75 #endif /* MAX_PRINT_CHARS */ | |
1967 | 76 |
77 void print_interval (); | |
329 | 78 |
79 #if 0 | |
80 /* Convert between chars and GLYPHs */ | |
81 | |
82 int | |
83 glyphlen (glyphs) | |
84 register GLYPH *glyphs; | |
85 { | |
86 register int i = 0; | |
87 | |
88 while (glyphs[i]) | |
89 i++; | |
90 return i; | |
91 } | |
92 | |
93 void | |
94 str_to_glyph_cpy (str, glyphs) | |
95 char *str; | |
96 GLYPH *glyphs; | |
97 { | |
98 register GLYPH *gp = glyphs; | |
99 register char *cp = str; | |
100 | |
101 while (*cp) | |
102 *gp++ = *cp++; | |
103 } | |
104 | |
105 void | |
106 str_to_glyph_ncpy (str, glyphs, n) | |
107 char *str; | |
108 GLYPH *glyphs; | |
109 register int n; | |
110 { | |
111 register GLYPH *gp = glyphs; | |
112 register char *cp = str; | |
113 | |
114 while (n-- > 0) | |
115 *gp++ = *cp++; | |
116 } | |
117 | |
118 void | |
119 glyph_to_str_cpy (glyphs, str) | |
120 GLYPH *glyphs; | |
121 char *str; | |
122 { | |
123 register GLYPH *gp = glyphs; | |
124 register char *cp = str; | |
125 | |
126 while (*gp) | |
127 *str++ = *gp++ & 0377; | |
128 } | |
129 #endif | |
130 | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3377
diff
changeset
|
131 /* Low level output routines for characters and strings */ |
329 | 132 |
133 /* Lisp functions to do output using a stream | |
134 must have the stream in a variable called printcharfun | |
135 and must start with PRINTPREPARE and end with PRINTFINISH. | |
136 Use PRINTCHAR to output one character, | |
137 or call strout to output a block of characters. | |
138 Also, each one must have the declarations | |
139 struct buffer *old = current_buffer; | |
140 int old_point = -1, start_point; | |
141 Lisp_Object original; | |
142 */ | |
143 | |
2193
652b38173a63
(PRINTPREPARE): Handle marker that points nowhere.
Richard M. Stallman <rms@gnu.org>
parents:
1991
diff
changeset
|
144 #define PRINTPREPARE \ |
652b38173a63
(PRINTPREPARE): Handle marker that points nowhere.
Richard M. Stallman <rms@gnu.org>
parents:
1991
diff
changeset
|
145 original = printcharfun; \ |
652b38173a63
(PRINTPREPARE): Handle marker that points nowhere.
Richard M. Stallman <rms@gnu.org>
parents:
1991
diff
changeset
|
146 if (NILP (printcharfun)) printcharfun = Qt; \ |
652b38173a63
(PRINTPREPARE): Handle marker that points nowhere.
Richard M. Stallman <rms@gnu.org>
parents:
1991
diff
changeset
|
147 if (XTYPE (printcharfun) == Lisp_Buffer) \ |
652b38173a63
(PRINTPREPARE): Handle marker that points nowhere.
Richard M. Stallman <rms@gnu.org>
parents:
1991
diff
changeset
|
148 { if (XBUFFER (printcharfun) != current_buffer) \ |
652b38173a63
(PRINTPREPARE): Handle marker that points nowhere.
Richard M. Stallman <rms@gnu.org>
parents:
1991
diff
changeset
|
149 Fset_buffer (printcharfun); \ |
652b38173a63
(PRINTPREPARE): Handle marker that points nowhere.
Richard M. Stallman <rms@gnu.org>
parents:
1991
diff
changeset
|
150 printcharfun = Qnil;} \ |
652b38173a63
(PRINTPREPARE): Handle marker that points nowhere.
Richard M. Stallman <rms@gnu.org>
parents:
1991
diff
changeset
|
151 if (XTYPE (printcharfun) == Lisp_Marker) \ |
652b38173a63
(PRINTPREPARE): Handle marker that points nowhere.
Richard M. Stallman <rms@gnu.org>
parents:
1991
diff
changeset
|
152 { if (!(XMARKER (original)->buffer)) \ |
652b38173a63
(PRINTPREPARE): Handle marker that points nowhere.
Richard M. Stallman <rms@gnu.org>
parents:
1991
diff
changeset
|
153 error ("Marker does not point anywhere"); \ |
652b38173a63
(PRINTPREPARE): Handle marker that points nowhere.
Richard M. Stallman <rms@gnu.org>
parents:
1991
diff
changeset
|
154 if (XMARKER (original)->buffer != current_buffer) \ |
652b38173a63
(PRINTPREPARE): Handle marker that points nowhere.
Richard M. Stallman <rms@gnu.org>
parents:
1991
diff
changeset
|
155 set_buffer_internal (XMARKER (original)->buffer); \ |
652b38173a63
(PRINTPREPARE): Handle marker that points nowhere.
Richard M. Stallman <rms@gnu.org>
parents:
1991
diff
changeset
|
156 old_point = point; \ |
652b38173a63
(PRINTPREPARE): Handle marker that points nowhere.
Richard M. Stallman <rms@gnu.org>
parents:
1991
diff
changeset
|
157 SET_PT (marker_position (printcharfun)); \ |
652b38173a63
(PRINTPREPARE): Handle marker that points nowhere.
Richard M. Stallman <rms@gnu.org>
parents:
1991
diff
changeset
|
158 start_point = point; \ |
329 | 159 printcharfun = Qnil;} |
160 | |
2193
652b38173a63
(PRINTPREPARE): Handle marker that points nowhere.
Richard M. Stallman <rms@gnu.org>
parents:
1991
diff
changeset
|
161 #define PRINTFINISH \ |
652b38173a63
(PRINTPREPARE): Handle marker that points nowhere.
Richard M. Stallman <rms@gnu.org>
parents:
1991
diff
changeset
|
162 if (XTYPE (original) == Lisp_Marker) \ |
652b38173a63
(PRINTPREPARE): Handle marker that points nowhere.
Richard M. Stallman <rms@gnu.org>
parents:
1991
diff
changeset
|
163 Fset_marker (original, make_number (point), Qnil); \ |
652b38173a63
(PRINTPREPARE): Handle marker that points nowhere.
Richard M. Stallman <rms@gnu.org>
parents:
1991
diff
changeset
|
164 if (old_point >= 0) \ |
652b38173a63
(PRINTPREPARE): Handle marker that points nowhere.
Richard M. Stallman <rms@gnu.org>
parents:
1991
diff
changeset
|
165 SET_PT (old_point + (old_point >= start_point \ |
652b38173a63
(PRINTPREPARE): Handle marker that points nowhere.
Richard M. Stallman <rms@gnu.org>
parents:
1991
diff
changeset
|
166 ? point - start_point : 0)); \ |
652b38173a63
(PRINTPREPARE): Handle marker that points nowhere.
Richard M. Stallman <rms@gnu.org>
parents:
1991
diff
changeset
|
167 if (old != current_buffer) \ |
329 | 168 set_buffer_internal (old) |
169 | |
170 #define PRINTCHAR(ch) printchar (ch, printcharfun) | |
171 | |
766 | 172 /* Index of first unused element of FRAME_MESSAGE_BUF(selected_frame). */ |
329 | 173 static int printbufidx; |
174 | |
175 static void | |
176 printchar (ch, fun) | |
177 unsigned char ch; | |
178 Lisp_Object fun; | |
179 { | |
180 Lisp_Object ch1; | |
181 | |
182 #ifdef MAX_PRINT_CHARS | |
183 if (max_print) | |
184 print_chars++; | |
185 #endif /* MAX_PRINT_CHARS */ | |
186 #ifndef standalone | |
187 if (EQ (fun, Qnil)) | |
188 { | |
189 QUIT; | |
190 insert (&ch, 1); | |
191 return; | |
192 } | |
193 | |
194 if (EQ (fun, Qt)) | |
195 { | |
196 if (noninteractive) | |
197 { | |
198 putchar (ch); | |
199 noninteractive_need_newline = 1; | |
200 return; | |
201 } | |
202 | |
766 | 203 if (echo_area_glyphs != FRAME_MESSAGE_BUF (selected_frame) |
329 | 204 || !message_buf_print) |
205 { | |
766 | 206 echo_area_glyphs = FRAME_MESSAGE_BUF (selected_frame); |
329 | 207 printbufidx = 0; |
5233
83e771f33251
(printchar, strout): Set echo_area_glyphs_length.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
208 echo_area_glyphs_length = 0; |
329 | 209 message_buf_print = 1; |
210 } | |
211 | |
766 | 212 if (printbufidx < FRAME_WIDTH (selected_frame) - 1) |
213 FRAME_MESSAGE_BUF (selected_frame)[printbufidx++] = ch; | |
214 FRAME_MESSAGE_BUF (selected_frame)[printbufidx] = 0; | |
5233
83e771f33251
(printchar, strout): Set echo_area_glyphs_length.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
215 echo_area_glyphs_length = printbufidx; |
329 | 216 |
217 return; | |
218 } | |
219 #endif /* not standalone */ | |
220 | |
221 XFASTINT (ch1) = ch; | |
222 call1 (fun, ch1); | |
223 } | |
224 | |
225 static void | |
226 strout (ptr, size, printcharfun) | |
227 char *ptr; | |
228 int size; | |
229 Lisp_Object printcharfun; | |
230 { | |
231 int i = 0; | |
232 | |
233 if (EQ (printcharfun, Qnil)) | |
234 { | |
235 insert (ptr, size >= 0 ? size : strlen (ptr)); | |
236 #ifdef MAX_PRINT_CHARS | |
237 if (max_print) | |
238 print_chars += size >= 0 ? size : strlen(ptr); | |
239 #endif /* MAX_PRINT_CHARS */ | |
240 return; | |
241 } | |
242 if (EQ (printcharfun, Qt)) | |
243 { | |
244 i = size >= 0 ? size : strlen (ptr); | |
245 #ifdef MAX_PRINT_CHARS | |
246 if (max_print) | |
247 print_chars += i; | |
248 #endif /* MAX_PRINT_CHARS */ | |
249 | |
250 if (noninteractive) | |
251 { | |
252 fwrite (ptr, 1, i, stdout); | |
253 noninteractive_need_newline = 1; | |
254 return; | |
255 } | |
256 | |
766 | 257 if (echo_area_glyphs != FRAME_MESSAGE_BUF (selected_frame) |
329 | 258 || !message_buf_print) |
259 { | |
766 | 260 echo_area_glyphs = FRAME_MESSAGE_BUF (selected_frame); |
329 | 261 printbufidx = 0; |
5233
83e771f33251
(printchar, strout): Set echo_area_glyphs_length.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
262 echo_area_glyphs_length = 0; |
329 | 263 message_buf_print = 1; |
264 } | |
265 | |
766 | 266 if (i > FRAME_WIDTH (selected_frame) - printbufidx - 1) |
267 i = FRAME_WIDTH (selected_frame) - printbufidx - 1; | |
268 bcopy (ptr, &FRAME_MESSAGE_BUF (selected_frame) [printbufidx], i); | |
329 | 269 printbufidx += i; |
5233
83e771f33251
(printchar, strout): Set echo_area_glyphs_length.
Richard M. Stallman <rms@gnu.org>
parents:
4696
diff
changeset
|
270 echo_area_glyphs_length = printbufidx; |
766 | 271 FRAME_MESSAGE_BUF (selected_frame) [printbufidx] = 0; |
329 | 272 |
273 return; | |
274 } | |
275 | |
276 if (size >= 0) | |
277 while (i < size) | |
278 PRINTCHAR (ptr[i++]); | |
279 else | |
280 while (ptr[i]) | |
281 PRINTCHAR (ptr[i++]); | |
282 } | |
283 | |
284 /* Print the contents of a string STRING using PRINTCHARFUN. | |
285 It isn't safe to use strout, because printing one char can relocate. */ | |
286 | |
287 print_string (string, printcharfun) | |
288 Lisp_Object string; | |
289 Lisp_Object printcharfun; | |
290 { | |
291 if (EQ (printcharfun, Qnil) || EQ (printcharfun, Qt)) | |
766 | 292 /* In predictable cases, strout is safe: output to buffer or frame. */ |
329 | 293 strout (XSTRING (string)->data, XSTRING (string)->size, printcharfun); |
294 else | |
295 { | |
296 /* Otherwise, fetch the string address for each character. */ | |
297 int i; | |
298 int size = XSTRING (string)->size; | |
299 struct gcpro gcpro1; | |
300 GCPRO1 (string); | |
301 for (i = 0; i < size; i++) | |
302 PRINTCHAR (XSTRING (string)->data[i]); | |
303 UNGCPRO; | |
304 } | |
305 } | |
306 | |
307 DEFUN ("write-char", Fwrite_char, Swrite_char, 1, 2, 0, | |
308 "Output character CHAR to stream STREAM.\n\ | |
309 STREAM defaults to the value of `standard-output' (which see).") | |
310 (ch, printcharfun) | |
311 Lisp_Object ch, printcharfun; | |
312 { | |
313 struct buffer *old = current_buffer; | |
314 int old_point = -1; | |
315 int start_point; | |
316 Lisp_Object original; | |
317 | |
520 | 318 if (NILP (printcharfun)) |
329 | 319 printcharfun = Vstandard_output; |
320 CHECK_NUMBER (ch, 0); | |
321 PRINTPREPARE; | |
322 PRINTCHAR (XINT (ch)); | |
323 PRINTFINISH; | |
324 return ch; | |
325 } | |
326 | |
327 /* Used from outside of print.c to print a block of SIZE chars at DATA | |
328 on the default output stream. | |
329 Do not use this on the contents of a Lisp string. */ | |
330 | |
331 write_string (data, size) | |
332 char *data; | |
333 int size; | |
334 { | |
335 struct buffer *old = current_buffer; | |
336 Lisp_Object printcharfun; | |
337 int old_point = -1; | |
338 int start_point; | |
339 Lisp_Object original; | |
340 | |
341 printcharfun = Vstandard_output; | |
342 | |
343 PRINTPREPARE; | |
344 strout (data, size, printcharfun); | |
345 PRINTFINISH; | |
346 } | |
347 | |
348 /* Used from outside of print.c to print a block of SIZE chars at DATA | |
349 on a specified stream PRINTCHARFUN. | |
350 Do not use this on the contents of a Lisp string. */ | |
351 | |
352 write_string_1 (data, size, printcharfun) | |
353 char *data; | |
354 int size; | |
355 Lisp_Object printcharfun; | |
356 { | |
357 struct buffer *old = current_buffer; | |
358 int old_point = -1; | |
359 int start_point; | |
360 Lisp_Object original; | |
361 | |
362 PRINTPREPARE; | |
363 strout (data, size, printcharfun); | |
364 PRINTFINISH; | |
365 } | |
366 | |
367 | |
368 #ifndef standalone | |
369 | |
370 void | |
371 temp_output_buffer_setup (bufname) | |
372 char *bufname; | |
373 { | |
374 register struct buffer *old = current_buffer; | |
375 register Lisp_Object buf; | |
376 | |
377 Fset_buffer (Fget_buffer_create (build_string (bufname))); | |
378 | |
379 current_buffer->read_only = Qnil; | |
380 Ferase_buffer (); | |
381 | |
382 XSET (buf, Lisp_Buffer, current_buffer); | |
383 specbind (Qstandard_output, buf); | |
384 | |
385 set_buffer_internal (old); | |
386 } | |
387 | |
388 Lisp_Object | |
389 internal_with_output_to_temp_buffer (bufname, function, args) | |
390 char *bufname; | |
391 Lisp_Object (*function) (); | |
392 Lisp_Object args; | |
393 { | |
394 int count = specpdl_ptr - specpdl; | |
395 Lisp_Object buf, val; | |
396 | |
397 record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); | |
398 temp_output_buffer_setup (bufname); | |
399 buf = Vstandard_output; | |
400 | |
401 val = (*function) (args); | |
402 | |
403 temp_output_buffer_show (buf); | |
404 | |
405 return unbind_to (count, val); | |
406 } | |
407 | |
408 DEFUN ("with-output-to-temp-buffer", Fwith_output_to_temp_buffer, Swith_output_to_temp_buffer, | |
409 1, UNEVALLED, 0, | |
410 "Bind `standard-output' to buffer BUFNAME, eval BODY, then show that buffer.\n\ | |
411 The buffer is cleared out initially, and marked as unmodified when done.\n\ | |
412 All output done by BODY is inserted in that buffer by default.\n\ | |
413 The buffer is displayed in another window, but not selected.\n\ | |
414 The value of the last form in BODY is returned.\n\ | |
415 If BODY does not finish normally, the buffer BUFNAME is not displayed.\n\n\ | |
3337
f5f76ebe6286
(Fwith_output_to_temp_buffer): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
2782
diff
changeset
|
416 If variable `temp-buffer-show-function' is non-nil, call it at the end\n\ |
329 | 417 to get the buffer displayed. It gets one argument, the buffer to display.") |
418 (args) | |
419 Lisp_Object args; | |
420 { | |
421 struct gcpro gcpro1; | |
422 Lisp_Object name; | |
423 int count = specpdl_ptr - specpdl; | |
424 Lisp_Object buf, val; | |
425 | |
426 GCPRO1(args); | |
427 name = Feval (Fcar (args)); | |
428 UNGCPRO; | |
429 | |
430 CHECK_STRING (name, 0); | |
431 temp_output_buffer_setup (XSTRING (name)->data); | |
432 buf = Vstandard_output; | |
433 | |
434 val = Fprogn (Fcdr (args)); | |
435 | |
436 temp_output_buffer_show (buf); | |
437 | |
438 return unbind_to (count, val); | |
439 } | |
440 #endif /* not standalone */ | |
441 | |
442 static void print (); | |
443 | |
444 DEFUN ("terpri", Fterpri, Sterpri, 0, 1, 0, | |
445 "Output a newline to STREAM.\n\ | |
446 If STREAM is omitted or nil, the value of `standard-output' is used.") | |
447 (printcharfun) | |
448 Lisp_Object printcharfun; | |
449 { | |
450 struct buffer *old = current_buffer; | |
451 int old_point = -1; | |
452 int start_point; | |
453 Lisp_Object original; | |
454 | |
520 | 455 if (NILP (printcharfun)) |
329 | 456 printcharfun = Vstandard_output; |
457 PRINTPREPARE; | |
458 PRINTCHAR ('\n'); | |
459 PRINTFINISH; | |
460 return Qt; | |
461 } | |
462 | |
463 DEFUN ("prin1", Fprin1, Sprin1, 1, 2, 0, | |
464 "Output the printed representation of OBJECT, any Lisp object.\n\ | |
465 Quoting characters are printed when needed to make output that `read'\n\ | |
466 can handle, whenever this is possible.\n\ | |
467 Output stream is STREAM, or value of `standard-output' (which see).") | |
468 (obj, printcharfun) | |
469 Lisp_Object obj, printcharfun; | |
470 { | |
471 struct buffer *old = current_buffer; | |
472 int old_point = -1; | |
473 int start_point; | |
474 Lisp_Object original; | |
475 | |
476 #ifdef MAX_PRINT_CHARS | |
477 max_print = 0; | |
478 #endif /* MAX_PRINT_CHARS */ | |
520 | 479 if (NILP (printcharfun)) |
329 | 480 printcharfun = Vstandard_output; |
481 PRINTPREPARE; | |
482 print_depth = 0; | |
483 print (obj, printcharfun, 1); | |
484 PRINTFINISH; | |
485 return obj; | |
486 } | |
487 | |
488 /* a buffer which is used to hold output being built by prin1-to-string */ | |
489 Lisp_Object Vprin1_to_string_buffer; | |
490 | |
491 DEFUN ("prin1-to-string", Fprin1_to_string, Sprin1_to_string, 1, 2, 0, | |
492 "Return a string containing the printed representation of OBJECT,\n\ | |
493 any Lisp object. Quoting characters are used when needed to make output\n\ | |
494 that `read' can handle, whenever this is possible, unless the optional\n\ | |
495 second argument NOESCAPE is non-nil.") | |
496 (obj, noescape) | |
497 Lisp_Object obj, noescape; | |
498 { | |
499 struct buffer *old = current_buffer; | |
500 int old_point = -1; | |
501 int start_point; | |
502 Lisp_Object original, printcharfun; | |
503 struct gcpro gcpro1; | |
504 | |
505 printcharfun = Vprin1_to_string_buffer; | |
506 PRINTPREPARE; | |
507 print_depth = 0; | |
520 | 508 print (obj, printcharfun, NILP (noescape)); |
329 | 509 /* Make Vprin1_to_string_buffer be the default buffer after PRINTFINSH */ |
510 PRINTFINISH; | |
511 set_buffer_internal (XBUFFER (Vprin1_to_string_buffer)); | |
512 obj = Fbuffer_string (); | |
513 | |
514 GCPRO1 (obj); | |
515 Ferase_buffer (); | |
516 set_buffer_internal (old); | |
517 UNGCPRO; | |
518 | |
519 return obj; | |
520 } | |
521 | |
522 DEFUN ("princ", Fprinc, Sprinc, 1, 2, 0, | |
523 "Output the printed representation of OBJECT, any Lisp object.\n\ | |
524 No quoting characters are used; no delimiters are printed around\n\ | |
525 the contents of strings.\n\ | |
526 Output stream is STREAM, or value of standard-output (which see).") | |
527 (obj, printcharfun) | |
528 Lisp_Object obj, printcharfun; | |
529 { | |
530 struct buffer *old = current_buffer; | |
531 int old_point = -1; | |
532 int start_point; | |
533 Lisp_Object original; | |
534 | |
520 | 535 if (NILP (printcharfun)) |
329 | 536 printcharfun = Vstandard_output; |
537 PRINTPREPARE; | |
538 print_depth = 0; | |
539 print (obj, printcharfun, 0); | |
540 PRINTFINISH; | |
541 return obj; | |
542 } | |
543 | |
544 DEFUN ("print", Fprint, Sprint, 1, 2, 0, | |
545 "Output the printed representation of OBJECT, with newlines around it.\n\ | |
546 Quoting characters are printed when needed to make output that `read'\n\ | |
547 can handle, whenever this is possible.\n\ | |
548 Output stream is STREAM, or value of `standard-output' (which see).") | |
549 (obj, printcharfun) | |
550 Lisp_Object obj, printcharfun; | |
551 { | |
552 struct buffer *old = current_buffer; | |
553 int old_point = -1; | |
554 int start_point; | |
555 Lisp_Object original; | |
556 struct gcpro gcpro1; | |
557 | |
558 #ifdef MAX_PRINT_CHARS | |
559 print_chars = 0; | |
560 max_print = MAX_PRINT_CHARS; | |
561 #endif /* MAX_PRINT_CHARS */ | |
520 | 562 if (NILP (printcharfun)) |
329 | 563 printcharfun = Vstandard_output; |
564 GCPRO1 (obj); | |
565 PRINTPREPARE; | |
566 print_depth = 0; | |
567 PRINTCHAR ('\n'); | |
568 print (obj, printcharfun, 1); | |
569 PRINTCHAR ('\n'); | |
570 PRINTFINISH; | |
571 #ifdef MAX_PRINT_CHARS | |
572 max_print = 0; | |
573 print_chars = 0; | |
574 #endif /* MAX_PRINT_CHARS */ | |
575 UNGCPRO; | |
576 return obj; | |
577 } | |
578 | |
579 /* The subroutine object for external-debugging-output is kept here | |
580 for the convenience of the debugger. */ | |
581 Lisp_Object Qexternal_debugging_output; | |
582 | |
621 | 583 DEFUN ("external-debugging-output", Fexternal_debugging_output, Sexternal_debugging_output, 1, 1, 0, |
584 "Write CHARACTER to stderr.\n\ | |
329 | 585 You can call print while debugging emacs, and pass it this function\n\ |
586 to make it write to the debugging output.\n") | |
621 | 587 (character) |
588 Lisp_Object character; | |
329 | 589 { |
590 CHECK_NUMBER (character, 0); | |
591 putc (XINT (character), stderr); | |
592 | |
593 return character; | |
594 } | |
595 | |
596 #ifdef LISP_FLOAT_TYPE | |
597 | |
598 /* | |
1759
3c615a9dcd64
(float_to_string): Add `.0' at end if needed.
Richard M. Stallman <rms@gnu.org>
parents:
1521
diff
changeset
|
599 * The buffer should be at least as large as the max string size of the |
329 | 600 * largest float, printed in the biggest notation. This is undoubtably |
601 * 20d float_output_format, with the negative of the C-constant "HUGE" | |
602 * from <math.h>. | |
603 * | |
604 * On the vax the worst case is -1e38 in 20d format which takes 61 bytes. | |
605 * | |
606 * I assume that IEEE-754 format numbers can take 329 bytes for the worst | |
607 * case of -1e307 in 20d float_output_format. What is one to do (short of | |
608 * re-writing _doprnt to be more sane)? | |
609 * -wsr | |
610 */ | |
1759
3c615a9dcd64
(float_to_string): Add `.0' at end if needed.
Richard M. Stallman <rms@gnu.org>
parents:
1521
diff
changeset
|
611 |
3c615a9dcd64
(float_to_string): Add `.0' at end if needed.
Richard M. Stallman <rms@gnu.org>
parents:
1521
diff
changeset
|
612 void |
3c615a9dcd64
(float_to_string): Add `.0' at end if needed.
Richard M. Stallman <rms@gnu.org>
parents:
1521
diff
changeset
|
613 float_to_string (buf, data) |
1991
0f88f314fc34
* print.c (float_to_string): Define buf to be an unsigned char, to
Jim Blandy <jimb@redhat.com>
parents:
1967
diff
changeset
|
614 unsigned char *buf; |
329 | 615 double data; |
616 { | |
4140
2738089e8383
* print.c (float_to_string): Distinguish between a precision of
Jim Blandy <jimb@redhat.com>
parents:
4003
diff
changeset
|
617 unsigned char *cp; |
4224
6cb1cfba6500
(float_to_string): Don't use uninitialized pointer `cp'.
Richard M. Stallman <rms@gnu.org>
parents:
4140
diff
changeset
|
618 int width; |
329 | 619 |
520 | 620 if (NILP (Vfloat_output_format) |
329 | 621 || XTYPE (Vfloat_output_format) != Lisp_String) |
622 lose: | |
4224
6cb1cfba6500
(float_to_string): Don't use uninitialized pointer `cp'.
Richard M. Stallman <rms@gnu.org>
parents:
4140
diff
changeset
|
623 { |
6cb1cfba6500
(float_to_string): Don't use uninitialized pointer `cp'.
Richard M. Stallman <rms@gnu.org>
parents:
4140
diff
changeset
|
624 sprintf (buf, "%.17g", data); |
6cb1cfba6500
(float_to_string): Don't use uninitialized pointer `cp'.
Richard M. Stallman <rms@gnu.org>
parents:
4140
diff
changeset
|
625 width = -1; |
6cb1cfba6500
(float_to_string): Don't use uninitialized pointer `cp'.
Richard M. Stallman <rms@gnu.org>
parents:
4140
diff
changeset
|
626 } |
329 | 627 else /* oink oink */ |
628 { | |
629 /* Check that the spec we have is fully valid. | |
630 This means not only valid for printf, | |
631 but meant for floats, and reasonable. */ | |
632 cp = XSTRING (Vfloat_output_format)->data; | |
633 | |
634 if (cp[0] != '%') | |
635 goto lose; | |
636 if (cp[1] != '.') | |
637 goto lose; | |
638 | |
639 cp += 2; | |
4140
2738089e8383
* print.c (float_to_string): Distinguish between a precision of
Jim Blandy <jimb@redhat.com>
parents:
4003
diff
changeset
|
640 |
2738089e8383
* print.c (float_to_string): Distinguish between a precision of
Jim Blandy <jimb@redhat.com>
parents:
4003
diff
changeset
|
641 /* Check the width specification. */ |
4224
6cb1cfba6500
(float_to_string): Don't use uninitialized pointer `cp'.
Richard M. Stallman <rms@gnu.org>
parents:
4140
diff
changeset
|
642 width = -1; |
4140
2738089e8383
* print.c (float_to_string): Distinguish between a precision of
Jim Blandy <jimb@redhat.com>
parents:
4003
diff
changeset
|
643 if ('0' <= *cp && *cp <= '9') |
2738089e8383
* print.c (float_to_string): Distinguish between a precision of
Jim Blandy <jimb@redhat.com>
parents:
4003
diff
changeset
|
644 for (width = 0; (*cp >= '0' && *cp <= '9'); cp++) |
2738089e8383
* print.c (float_to_string): Distinguish between a precision of
Jim Blandy <jimb@redhat.com>
parents:
4003
diff
changeset
|
645 width = (width * 10) + (*cp - '0'); |
329 | 646 |
647 if (*cp != 'e' && *cp != 'f' && *cp != 'g') | |
648 goto lose; | |
649 | |
4140
2738089e8383
* print.c (float_to_string): Distinguish between a precision of
Jim Blandy <jimb@redhat.com>
parents:
4003
diff
changeset
|
650 /* A precision of zero is valid for %f; everything else requires |
2738089e8383
* print.c (float_to_string): Distinguish between a precision of
Jim Blandy <jimb@redhat.com>
parents:
4003
diff
changeset
|
651 at least one. Width may be omitted anywhere. */ |
2738089e8383
* print.c (float_to_string): Distinguish between a precision of
Jim Blandy <jimb@redhat.com>
parents:
4003
diff
changeset
|
652 if (width != -1 |
2738089e8383
* print.c (float_to_string): Distinguish between a precision of
Jim Blandy <jimb@redhat.com>
parents:
4003
diff
changeset
|
653 && (width < (*cp != 'f') |
2738089e8383
* print.c (float_to_string): Distinguish between a precision of
Jim Blandy <jimb@redhat.com>
parents:
4003
diff
changeset
|
654 || width > DBL_DIG)) |
329 | 655 goto lose; |
656 | |
657 if (cp[1] != 0) | |
658 goto lose; | |
659 | |
660 sprintf (buf, XSTRING (Vfloat_output_format)->data, data); | |
661 } | |
1759
3c615a9dcd64
(float_to_string): Add `.0' at end if needed.
Richard M. Stallman <rms@gnu.org>
parents:
1521
diff
changeset
|
662 |
4140
2738089e8383
* print.c (float_to_string): Distinguish between a precision of
Jim Blandy <jimb@redhat.com>
parents:
4003
diff
changeset
|
663 /* Make sure there is a decimal point with digit after, or an |
2738089e8383
* print.c (float_to_string): Distinguish between a precision of
Jim Blandy <jimb@redhat.com>
parents:
4003
diff
changeset
|
664 exponent, so that the value is readable as a float. But don't do |
4224
6cb1cfba6500
(float_to_string): Don't use uninitialized pointer `cp'.
Richard M. Stallman <rms@gnu.org>
parents:
4140
diff
changeset
|
665 this with "%.0f"; it's valid for that not to produce a decimal |
6cb1cfba6500
(float_to_string): Don't use uninitialized pointer `cp'.
Richard M. Stallman <rms@gnu.org>
parents:
4140
diff
changeset
|
666 point. Note that width can be 0 only for %.0f. */ |
6cb1cfba6500
(float_to_string): Don't use uninitialized pointer `cp'.
Richard M. Stallman <rms@gnu.org>
parents:
4140
diff
changeset
|
667 if (width != 0) |
1764
94ff5d9ef48a
(float_to_string): Add final 0 if text ends with decimal pt.
Richard M. Stallman <rms@gnu.org>
parents:
1759
diff
changeset
|
668 { |
4140
2738089e8383
* print.c (float_to_string): Distinguish between a precision of
Jim Blandy <jimb@redhat.com>
parents:
4003
diff
changeset
|
669 for (cp = buf; *cp; cp++) |
2738089e8383
* print.c (float_to_string): Distinguish between a precision of
Jim Blandy <jimb@redhat.com>
parents:
4003
diff
changeset
|
670 if ((*cp < '0' || *cp > '9') && *cp != '-') |
2738089e8383
* print.c (float_to_string): Distinguish between a precision of
Jim Blandy <jimb@redhat.com>
parents:
4003
diff
changeset
|
671 break; |
1764
94ff5d9ef48a
(float_to_string): Add final 0 if text ends with decimal pt.
Richard M. Stallman <rms@gnu.org>
parents:
1759
diff
changeset
|
672 |
4140
2738089e8383
* print.c (float_to_string): Distinguish between a precision of
Jim Blandy <jimb@redhat.com>
parents:
4003
diff
changeset
|
673 if (*cp == '.' && cp[1] == 0) |
2738089e8383
* print.c (float_to_string): Distinguish between a precision of
Jim Blandy <jimb@redhat.com>
parents:
4003
diff
changeset
|
674 { |
2738089e8383
* print.c (float_to_string): Distinguish between a precision of
Jim Blandy <jimb@redhat.com>
parents:
4003
diff
changeset
|
675 cp[1] = '0'; |
2738089e8383
* print.c (float_to_string): Distinguish between a precision of
Jim Blandy <jimb@redhat.com>
parents:
4003
diff
changeset
|
676 cp[2] = 0; |
2738089e8383
* print.c (float_to_string): Distinguish between a precision of
Jim Blandy <jimb@redhat.com>
parents:
4003
diff
changeset
|
677 } |
2738089e8383
* print.c (float_to_string): Distinguish between a precision of
Jim Blandy <jimb@redhat.com>
parents:
4003
diff
changeset
|
678 |
2738089e8383
* print.c (float_to_string): Distinguish between a precision of
Jim Blandy <jimb@redhat.com>
parents:
4003
diff
changeset
|
679 if (*cp == 0) |
2738089e8383
* print.c (float_to_string): Distinguish between a precision of
Jim Blandy <jimb@redhat.com>
parents:
4003
diff
changeset
|
680 { |
2738089e8383
* print.c (float_to_string): Distinguish between a precision of
Jim Blandy <jimb@redhat.com>
parents:
4003
diff
changeset
|
681 *cp++ = '.'; |
2738089e8383
* print.c (float_to_string): Distinguish between a precision of
Jim Blandy <jimb@redhat.com>
parents:
4003
diff
changeset
|
682 *cp++ = '0'; |
2738089e8383
* print.c (float_to_string): Distinguish between a precision of
Jim Blandy <jimb@redhat.com>
parents:
4003
diff
changeset
|
683 *cp++ = 0; |
2738089e8383
* print.c (float_to_string): Distinguish between a precision of
Jim Blandy <jimb@redhat.com>
parents:
4003
diff
changeset
|
684 } |
1759
3c615a9dcd64
(float_to_string): Add `.0' at end if needed.
Richard M. Stallman <rms@gnu.org>
parents:
1521
diff
changeset
|
685 } |
329 | 686 } |
687 #endif /* LISP_FLOAT_TYPE */ | |
688 | |
689 static void | |
690 print (obj, printcharfun, escapeflag) | |
691 Lisp_Object obj; | |
692 register Lisp_Object printcharfun; | |
693 int escapeflag; | |
694 { | |
695 char buf[30]; | |
696 | |
697 QUIT; | |
698 | |
379
34ec8957c6c0
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
373
diff
changeset
|
699 #if 1 /* I'm not sure this is really worth doing. */ |
34ec8957c6c0
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
373
diff
changeset
|
700 /* Detect circularities and truncate them. |
34ec8957c6c0
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
373
diff
changeset
|
701 No need to offer any alternative--this is better than an error. */ |
34ec8957c6c0
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
373
diff
changeset
|
702 if (XTYPE (obj) == Lisp_Cons || XTYPE (obj) == Lisp_Vector |
34ec8957c6c0
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
373
diff
changeset
|
703 || XTYPE (obj) == Lisp_Compiled) |
34ec8957c6c0
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
373
diff
changeset
|
704 { |
34ec8957c6c0
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
373
diff
changeset
|
705 int i; |
34ec8957c6c0
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
373
diff
changeset
|
706 for (i = 0; i < print_depth; i++) |
34ec8957c6c0
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
373
diff
changeset
|
707 if (EQ (obj, being_printed[i])) |
34ec8957c6c0
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
373
diff
changeset
|
708 { |
34ec8957c6c0
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
373
diff
changeset
|
709 sprintf (buf, "#%d", i); |
34ec8957c6c0
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
373
diff
changeset
|
710 strout (buf, -1, printcharfun); |
34ec8957c6c0
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
373
diff
changeset
|
711 return; |
34ec8957c6c0
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
373
diff
changeset
|
712 } |
34ec8957c6c0
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
373
diff
changeset
|
713 } |
34ec8957c6c0
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
373
diff
changeset
|
714 #endif |
34ec8957c6c0
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
373
diff
changeset
|
715 |
34ec8957c6c0
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
373
diff
changeset
|
716 being_printed[print_depth] = obj; |
329 | 717 print_depth++; |
718 | |
379
34ec8957c6c0
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
373
diff
changeset
|
719 if (print_depth > PRINT_CIRCLE) |
329 | 720 error ("Apparently circular structure being printed"); |
721 #ifdef MAX_PRINT_CHARS | |
722 if (max_print && print_chars > max_print) | |
723 { | |
724 PRINTCHAR ('\n'); | |
725 print_chars = 0; | |
726 } | |
727 #endif /* MAX_PRINT_CHARS */ | |
728 | |
729 #ifdef SWITCH_ENUM_BUG | |
730 switch ((int) XTYPE (obj)) | |
731 #else | |
732 switch (XTYPE (obj)) | |
733 #endif | |
734 { | |
735 default: | |
736 /* We're in trouble if this happens! | |
737 Probably should just abort () */ | |
738 strout ("#<EMACS BUG: INVALID DATATYPE ", -1, printcharfun); | |
739 sprintf (buf, "(#o%3o)", (int) XTYPE (obj)); | |
740 strout (buf, -1, printcharfun); | |
741 strout (" Save your buffers immediately and please report this bug>", | |
742 -1, printcharfun); | |
743 break; | |
744 | |
745 #ifdef LISP_FLOAT_TYPE | |
746 case Lisp_Float: | |
747 { | |
748 char pigbuf[350]; /* see comments in float_to_string */ | |
749 | |
750 float_to_string (pigbuf, XFLOAT(obj)->data); | |
751 strout (pigbuf, -1, printcharfun); | |
752 } | |
753 break; | |
754 #endif /* LISP_FLOAT_TYPE */ | |
755 | |
756 case Lisp_Int: | |
757 sprintf (buf, "%d", XINT (obj)); | |
758 strout (buf, -1, printcharfun); | |
759 break; | |
760 | |
761 case Lisp_String: | |
762 if (!escapeflag) | |
763 print_string (obj, printcharfun); | |
764 else | |
765 { | |
766 register int i; | |
767 register unsigned char c; | |
768 struct gcpro gcpro1; | |
769 | |
1967 | 770 GCPRO1 (obj); |
771 | |
772 #ifdef USE_TEXT_PROPERTIES | |
773 if (!NULL_INTERVAL_P (XSTRING (obj)->intervals)) | |
774 { | |
775 PRINTCHAR ('#'); | |
776 PRINTCHAR ('('); | |
777 } | |
778 #endif | |
329 | 779 |
780 PRINTCHAR ('\"'); | |
781 for (i = 0; i < XSTRING (obj)->size; i++) | |
782 { | |
783 QUIT; | |
784 c = XSTRING (obj)->data[i]; | |
785 if (c == '\n' && print_escape_newlines) | |
786 { | |
787 PRINTCHAR ('\\'); | |
788 PRINTCHAR ('n'); | |
789 } | |
790 else | |
791 { | |
792 if (c == '\"' || c == '\\') | |
793 PRINTCHAR ('\\'); | |
794 PRINTCHAR (c); | |
795 } | |
796 } | |
797 PRINTCHAR ('\"'); | |
1967 | 798 |
799 #ifdef USE_TEXT_PROPERTIES | |
800 if (!NULL_INTERVAL_P (XSTRING (obj)->intervals)) | |
801 { | |
802 traverse_intervals (XSTRING (obj)->intervals, | |
803 0, 0, print_interval, printcharfun); | |
804 PRINTCHAR (')'); | |
805 } | |
806 #endif | |
807 | |
329 | 808 UNGCPRO; |
809 } | |
810 break; | |
811 | |
812 case Lisp_Symbol: | |
813 { | |
814 register int confusing; | |
815 register unsigned char *p = XSYMBOL (obj)->name->data; | |
816 register unsigned char *end = p + XSYMBOL (obj)->name->size; | |
817 register unsigned char c; | |
818 | |
819 if (p != end && (*p == '-' || *p == '+')) p++; | |
820 if (p == end) | |
821 confusing = 0; | |
822 else | |
823 { | |
824 while (p != end && *p >= '0' && *p <= '9') | |
825 p++; | |
826 confusing = (end == p); | |
827 } | |
828 | |
829 p = XSYMBOL (obj)->name->data; | |
830 while (p != end) | |
831 { | |
832 QUIT; | |
833 c = *p++; | |
834 if (escapeflag) | |
835 { | |
836 if (c == '\"' || c == '\\' || c == '\'' || c == ';' || c == '#' || | |
837 c == '(' || c == ')' || c == ',' || c =='.' || c == '`' || | |
838 c == '[' || c == ']' || c == '?' || c <= 040 || confusing) | |
839 PRINTCHAR ('\\'), confusing = 0; | |
840 } | |
841 PRINTCHAR (c); | |
842 } | |
843 } | |
844 break; | |
845 | |
846 case Lisp_Cons: | |
847 /* If deeper than spec'd depth, print placeholder. */ | |
848 if (XTYPE (Vprint_level) == Lisp_Int | |
849 && print_depth > XINT (Vprint_level)) | |
850 { | |
851 strout ("...", -1, printcharfun); | |
852 break; | |
853 } | |
854 | |
855 PRINTCHAR ('('); | |
856 { | |
857 register int i = 0; | |
858 register int max = 0; | |
859 | |
860 if (XTYPE (Vprint_length) == Lisp_Int) | |
861 max = XINT (Vprint_length); | |
379
34ec8957c6c0
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
373
diff
changeset
|
862 /* Could recognize circularities in cdrs here, |
34ec8957c6c0
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
373
diff
changeset
|
863 but that would make printing of long lists quadratic. |
34ec8957c6c0
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
373
diff
changeset
|
864 It's not worth doing. */ |
329 | 865 while (CONSP (obj)) |
866 { | |
867 if (i++) | |
868 PRINTCHAR (' '); | |
869 if (max && i > max) | |
870 { | |
871 strout ("...", 3, printcharfun); | |
872 break; | |
873 } | |
874 print (Fcar (obj), printcharfun, escapeflag); | |
875 obj = Fcdr (obj); | |
876 } | |
877 } | |
520 | 878 if (!NILP (obj) && !CONSP (obj)) |
329 | 879 { |
880 strout (" . ", 3, printcharfun); | |
881 print (obj, printcharfun, escapeflag); | |
882 } | |
883 PRINTCHAR (')'); | |
884 break; | |
885 | |
886 case Lisp_Compiled: | |
373
7c6f74ef31a3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
329
diff
changeset
|
887 strout ("#", -1, printcharfun); |
329 | 888 case Lisp_Vector: |
889 PRINTCHAR ('['); | |
890 { | |
891 register int i; | |
892 register Lisp_Object tem; | |
893 for (i = 0; i < XVECTOR (obj)->size; i++) | |
894 { | |
895 if (i) PRINTCHAR (' '); | |
896 tem = XVECTOR (obj)->contents[i]; | |
897 print (tem, printcharfun, escapeflag); | |
898 } | |
899 } | |
900 PRINTCHAR (']'); | |
901 break; | |
902 | |
903 #ifndef standalone | |
904 case Lisp_Buffer: | |
520 | 905 if (NILP (XBUFFER (obj)->name)) |
329 | 906 strout ("#<killed buffer>", -1, printcharfun); |
907 else if (escapeflag) | |
908 { | |
909 strout ("#<buffer ", -1, printcharfun); | |
910 print_string (XBUFFER (obj)->name, printcharfun); | |
911 PRINTCHAR ('>'); | |
912 } | |
913 else | |
914 print_string (XBUFFER (obj)->name, printcharfun); | |
915 break; | |
916 | |
917 case Lisp_Process: | |
918 if (escapeflag) | |
919 { | |
920 strout ("#<process ", -1, printcharfun); | |
921 print_string (XPROCESS (obj)->name, printcharfun); | |
922 PRINTCHAR ('>'); | |
923 } | |
924 else | |
925 print_string (XPROCESS (obj)->name, printcharfun); | |
926 break; | |
927 | |
928 case Lisp_Window: | |
929 strout ("#<window ", -1, printcharfun); | |
930 sprintf (buf, "%d", XFASTINT (XWINDOW (obj)->sequence_number)); | |
931 strout (buf, -1, printcharfun); | |
520 | 932 if (!NILP (XWINDOW (obj)->buffer)) |
329 | 933 { |
934 strout (" on ", -1, printcharfun); | |
935 print_string (XBUFFER (XWINDOW (obj)->buffer)->name, printcharfun); | |
936 } | |
937 PRINTCHAR ('>'); | |
938 break; | |
939 | |
940 case Lisp_Window_Configuration: | |
941 strout ("#<window-configuration>", -1, printcharfun); | |
942 break; | |
943 | |
766 | 944 #ifdef MULTI_FRAME |
945 case Lisp_Frame: | |
946 strout ((FRAME_LIVE_P (XFRAME (obj)) | |
947 ? "#<frame " : "#<dead frame "), | |
430 | 948 -1, printcharfun); |
766 | 949 print_string (XFRAME (obj)->name, printcharfun); |
1521
5d58b9e933ee
* print.c (print): Cast the frame's address to an integer before
Jim Blandy <jimb@redhat.com>
parents:
766
diff
changeset
|
950 sprintf (buf, " 0x%x", (unsigned int) (XFRAME (obj))); |
329 | 951 strout (buf, -1, printcharfun); |
952 strout (">", -1, printcharfun); | |
953 break; | |
766 | 954 #endif /* MULTI_FRAME */ |
329 | 955 |
956 case Lisp_Marker: | |
957 strout ("#<marker ", -1, printcharfun); | |
958 if (!(XMARKER (obj)->buffer)) | |
959 strout ("in no buffer", -1, printcharfun); | |
960 else | |
961 { | |
962 sprintf (buf, "at %d", marker_position (obj)); | |
963 strout (buf, -1, printcharfun); | |
964 strout (" in ", -1, printcharfun); | |
965 print_string (XMARKER (obj)->buffer->name, printcharfun); | |
966 } | |
967 PRINTCHAR ('>'); | |
968 break; | |
2782
683f4472f1c8
* lisp.h (Lisp_Overlay): New tag.
Jim Blandy <jimb@redhat.com>
parents:
2193
diff
changeset
|
969 |
683f4472f1c8
* lisp.h (Lisp_Overlay): New tag.
Jim Blandy <jimb@redhat.com>
parents:
2193
diff
changeset
|
970 case Lisp_Overlay: |
683f4472f1c8
* lisp.h (Lisp_Overlay): New tag.
Jim Blandy <jimb@redhat.com>
parents:
2193
diff
changeset
|
971 strout ("#<overlay ", -1, printcharfun); |
683f4472f1c8
* lisp.h (Lisp_Overlay): New tag.
Jim Blandy <jimb@redhat.com>
parents:
2193
diff
changeset
|
972 if (!(XMARKER (OVERLAY_START (obj))->buffer)) |
683f4472f1c8
* lisp.h (Lisp_Overlay): New tag.
Jim Blandy <jimb@redhat.com>
parents:
2193
diff
changeset
|
973 strout ("in no buffer", -1, printcharfun); |
683f4472f1c8
* lisp.h (Lisp_Overlay): New tag.
Jim Blandy <jimb@redhat.com>
parents:
2193
diff
changeset
|
974 else |
683f4472f1c8
* lisp.h (Lisp_Overlay): New tag.
Jim Blandy <jimb@redhat.com>
parents:
2193
diff
changeset
|
975 { |
683f4472f1c8
* lisp.h (Lisp_Overlay): New tag.
Jim Blandy <jimb@redhat.com>
parents:
2193
diff
changeset
|
976 sprintf (buf, "from %d to %d in ", |
683f4472f1c8
* lisp.h (Lisp_Overlay): New tag.
Jim Blandy <jimb@redhat.com>
parents:
2193
diff
changeset
|
977 marker_position (OVERLAY_START (obj)), |
683f4472f1c8
* lisp.h (Lisp_Overlay): New tag.
Jim Blandy <jimb@redhat.com>
parents:
2193
diff
changeset
|
978 marker_position (OVERLAY_END (obj))); |
683f4472f1c8
* lisp.h (Lisp_Overlay): New tag.
Jim Blandy <jimb@redhat.com>
parents:
2193
diff
changeset
|
979 strout (buf, -1, printcharfun); |
683f4472f1c8
* lisp.h (Lisp_Overlay): New tag.
Jim Blandy <jimb@redhat.com>
parents:
2193
diff
changeset
|
980 print_string (XMARKER (OVERLAY_START (obj))->buffer->name, |
683f4472f1c8
* lisp.h (Lisp_Overlay): New tag.
Jim Blandy <jimb@redhat.com>
parents:
2193
diff
changeset
|
981 printcharfun); |
683f4472f1c8
* lisp.h (Lisp_Overlay): New tag.
Jim Blandy <jimb@redhat.com>
parents:
2193
diff
changeset
|
982 } |
683f4472f1c8
* lisp.h (Lisp_Overlay): New tag.
Jim Blandy <jimb@redhat.com>
parents:
2193
diff
changeset
|
983 PRINTCHAR ('>'); |
683f4472f1c8
* lisp.h (Lisp_Overlay): New tag.
Jim Blandy <jimb@redhat.com>
parents:
2193
diff
changeset
|
984 break; |
683f4472f1c8
* lisp.h (Lisp_Overlay): New tag.
Jim Blandy <jimb@redhat.com>
parents:
2193
diff
changeset
|
985 |
329 | 986 #endif /* standalone */ |
987 | |
988 case Lisp_Subr: | |
989 strout ("#<subr ", -1, printcharfun); | |
990 strout (XSUBR (obj)->symbol_name, -1, printcharfun); | |
991 PRINTCHAR ('>'); | |
992 break; | |
993 } | |
994 | |
995 print_depth--; | |
996 } | |
997 | |
1967 | 998 #ifdef USE_TEXT_PROPERTIES |
999 | |
1000 /* Print a description of INTERVAL using PRINTCHARFUN. | |
1001 This is part of printing a string that has text properties. */ | |
1002 | |
1003 void | |
1004 print_interval (interval, printcharfun) | |
1005 INTERVAL interval; | |
1006 Lisp_Object printcharfun; | |
1007 { | |
4003
49918d6c6dda
* print.c: Get rid of extra space at the end of print syntax for
Jim Blandy <jimb@redhat.com>
parents:
3591
diff
changeset
|
1008 PRINTCHAR (' '); |
1967 | 1009 print (make_number (interval->position), printcharfun, 1); |
1010 PRINTCHAR (' '); | |
1011 print (make_number (interval->position + LENGTH (interval)), | |
1012 printcharfun, 1); | |
1013 PRINTCHAR (' '); | |
1014 print (interval->plist, printcharfun, 1); | |
1015 } | |
1016 | |
1017 #endif /* USE_TEXT_PROPERTIES */ | |
1018 | |
329 | 1019 void |
1020 syms_of_print () | |
1021 { | |
1022 staticpro (&Qprint_escape_newlines); | |
1023 Qprint_escape_newlines = intern ("print-escape-newlines"); | |
1024 | |
1025 DEFVAR_LISP ("standard-output", &Vstandard_output, | |
1026 "Output stream `print' uses by default for outputting a character.\n\ | |
1027 This may be any function of one argument.\n\ | |
1028 It may also be a buffer (output is inserted before point)\n\ | |
1029 or a marker (output is inserted and the marker is advanced)\n\ | |
1030 or the symbol t (output appears in the minibuffer line)."); | |
1031 Vstandard_output = Qt; | |
1032 Qstandard_output = intern ("standard-output"); | |
1033 staticpro (&Qstandard_output); | |
1034 | |
1035 #ifdef LISP_FLOAT_TYPE | |
1036 DEFVAR_LISP ("float-output-format", &Vfloat_output_format, | |
687
e2b747dd6a6e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
686
diff
changeset
|
1037 "The format descriptor string used to print floats.\n\ |
329 | 1038 This is a %-spec like those accepted by `printf' in C,\n\ |
1039 but with some restrictions. It must start with the two characters `%.'.\n\ | |
1040 After that comes an integer precision specification,\n\ | |
1041 and then a letter which controls the format.\n\ | |
1042 The letters allowed are `e', `f' and `g'.\n\ | |
1043 Use `e' for exponential notation \"DIG.DIGITSeEXPT\"\n\ | |
1044 Use `f' for decimal point notation \"DIGITS.DIGITS\".\n\ | |
1045 Use `g' to choose the shorter of those two formats for the number at hand.\n\ | |
1046 The precision in any of these cases is the number of digits following\n\ | |
1047 the decimal point. With `f', a precision of 0 means to omit the\n\ | |
4140
2738089e8383
* print.c (float_to_string): Distinguish between a precision of
Jim Blandy <jimb@redhat.com>
parents:
4003
diff
changeset
|
1048 decimal point. 0 is not allowed with `e' or `g'.\n\n\ |
4224
6cb1cfba6500
(float_to_string): Don't use uninitialized pointer `cp'.
Richard M. Stallman <rms@gnu.org>
parents:
4140
diff
changeset
|
1049 A value of nil means to use `%.17g'."); |
329 | 1050 Vfloat_output_format = Qnil; |
1051 Qfloat_output_format = intern ("float-output-format"); | |
1052 staticpro (&Qfloat_output_format); | |
1053 #endif /* LISP_FLOAT_TYPE */ | |
1054 | |
1055 DEFVAR_LISP ("print-length", &Vprint_length, | |
686
bd3068742807
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
621
diff
changeset
|
1056 "Maximum length of list to print before abbreviating.\n\ |
329 | 1057 A value of nil means no limit."); |
1058 Vprint_length = Qnil; | |
1059 | |
1060 DEFVAR_LISP ("print-level", &Vprint_level, | |
686
bd3068742807
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
621
diff
changeset
|
1061 "Maximum depth of list nesting to print before abbreviating.\n\ |
329 | 1062 A value of nil means no limit."); |
1063 Vprint_level = Qnil; | |
1064 | |
1065 DEFVAR_BOOL ("print-escape-newlines", &print_escape_newlines, | |
1066 "Non-nil means print newlines in strings as backslash-n."); | |
1067 print_escape_newlines = 0; | |
1068 | |
1069 /* prin1_to_string_buffer initialized in init_buffer_once in buffer.c */ | |
1070 staticpro (&Vprin1_to_string_buffer); | |
1071 | |
1072 defsubr (&Sprin1); | |
1073 defsubr (&Sprin1_to_string); | |
1074 defsubr (&Sprinc); | |
1075 defsubr (&Sprint); | |
1076 defsubr (&Sterpri); | |
1077 defsubr (&Swrite_char); | |
1078 defsubr (&Sexternal_debugging_output); | |
1079 | |
1080 Qexternal_debugging_output = intern ("external-debugging-output"); | |
1081 staticpro (&Qexternal_debugging_output); | |
1082 | |
1083 #ifndef standalone | |
1084 defsubr (&Swith_output_to_temp_buffer); | |
1085 #endif /* not standalone */ | |
1086 } |