0
|
1 /* Lisp object printing and output streams.
|
|
2 Copyright (C) 1985, 1986, 1988, 1992-1995 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1995, 1996 Ben Wing.
|
|
4
|
|
5 This file is part of XEmacs.
|
|
6
|
|
7 XEmacs is free software; you can redistribute it and/or modify it
|
|
8 under the terms of the GNU General Public License as published by the
|
|
9 Free Software Foundation; either version 2, or (at your option) any
|
|
10 later version.
|
|
11
|
|
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
15 for more details.
|
|
16
|
|
17 You should have received a copy of the GNU General Public License
|
|
18 along with XEmacs; see the file COPYING. If not, write to
|
|
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
20 Boston, MA 02111-1307, USA. */
|
|
21
|
|
22 /* Synched up with: Not synched with FSF. */
|
|
23
|
|
24 /* This file has been Mule-ized. */
|
|
25
|
|
26 /* Seriously hacked on by Ben Wing for Mule. */
|
|
27
|
|
28 #include <config.h>
|
|
29 #include "lisp.h"
|
|
30
|
|
31 #ifndef standalone
|
|
32 #include "backtrace.h"
|
|
33 #include "buffer.h"
|
|
34 #include "bytecode.h"
|
|
35 #include "console-tty.h"
|
|
36 #include "console-stream.h"
|
|
37 #include "extents.h"
|
|
38 #include "frame.h"
|
|
39 #include "emacsfns.h"
|
|
40 #include "insdel.h"
|
|
41 #include "lstream.h"
|
|
42
|
|
43 #endif /* not standalone */
|
|
44
|
149
|
45 static void print_error_message (Lisp_Object data, Lisp_Object stream);
|
|
46
|
0
|
47 Lisp_Object Vstandard_output, Qstandard_output;
|
|
48
|
|
49 /* The subroutine object for external-debugging-output is kept here
|
|
50 for the convenience of the debugger. */
|
|
51 Lisp_Object Qexternal_debugging_output;
|
|
52 Lisp_Object Qalternate_debugging_output;
|
173
|
53
|
0
|
54 /* Avoid actual stack overflow in print. */
|
|
55 static int print_depth;
|
|
56
|
177
|
57 /* Detect most circularities to print finite output. */
|
|
58 #define PRINT_CIRCLE 200
|
|
59 Lisp_Object being_printed[PRINT_CIRCLE];
|
|
60
|
0
|
61 /* Maximum length of list or vector to print in full; noninteger means
|
|
62 effectively infinity */
|
|
63
|
|
64 Lisp_Object Vprint_length;
|
|
65 Lisp_Object Qprint_length;
|
|
66
|
|
67 /* Maximum length of string to print in full; noninteger means
|
|
68 effectively infinity */
|
|
69
|
|
70 Lisp_Object Vprint_string_length;
|
|
71 Lisp_Object Qprint_string_length;
|
|
72
|
|
73 /* Maximum depth of list to print in full; noninteger means
|
|
74 effectively infinity. */
|
|
75
|
|
76 Lisp_Object Vprint_level;
|
|
77
|
|
78 /* Label to use when making echo-area messages. */
|
|
79
|
|
80 Lisp_Object Vprint_message_label;
|
|
81
|
|
82 /* Nonzero means print newlines in strings as \n. */
|
|
83
|
|
84 int print_escape_newlines;
|
|
85 int print_readably;
|
245
|
86
|
|
87 /* Non-nil means print #: before uninterned symbols.
|
|
88 Neither t nor nil means so that and don't clear Vprint_gensym_alist
|
|
89 on entry to and exit from print functions. */
|
|
90 Lisp_Object Vprint_gensym;
|
|
91 Lisp_Object Vprint_gensym_alist;
|
0
|
92
|
|
93 Lisp_Object Qprint_escape_newlines;
|
|
94 Lisp_Object Qprint_readably;
|
|
95
|
171
|
96 Lisp_Object Qdisplay_error;
|
|
97 Lisp_Object Qprint_message_label;
|
|
98
|
0
|
99 /* Force immediate output of all printed data. Used for debugging. */
|
|
100 int print_unbuffered;
|
|
101
|
|
102 FILE *termscript; /* Stdio stream being used for copy of all output. */
|
|
103
|
|
104
|
|
105
|
|
106 int stdout_needs_newline;
|
|
107
|
|
108 /* Write a string (in internal format) to stdio stream STREAM. */
|
173
|
109
|
0
|
110 void
|
|
111 write_string_to_stdio_stream (FILE *stream, struct console *con,
|
|
112 CONST Bufbyte *str,
|
|
113 Bytecount offset, Bytecount len,
|
|
114 enum external_data_format fmt)
|
|
115 {
|
|
116 int extlen;
|
|
117 CONST Extbyte *extptr;
|
|
118
|
|
119 GET_CHARPTR_EXT_DATA_ALLOCA (str + offset, len, fmt, extptr, extlen);
|
|
120 if (stream)
|
|
121 fwrite (extptr, 1, extlen, stream);
|
|
122 else
|
|
123 {
|
|
124 assert (CONSOLE_TTY_P (con));
|
|
125 Lstream_write (XLSTREAM (CONSOLE_TTY_DATA (con)->outstream),
|
|
126 extptr, extlen);
|
|
127 }
|
|
128 if (stream == stdout || stream == stderr ||
|
|
129 (!stream && CONSOLE_TTY_DATA (con)->is_stdio))
|
|
130 {
|
|
131 if (termscript)
|
|
132 {
|
|
133 fwrite (extptr, 1, extlen, termscript);
|
|
134 fflush (termscript);
|
|
135 }
|
|
136 stdout_needs_newline = (extptr[extlen - 1] != '\n');
|
|
137 }
|
|
138 }
|
|
139
|
|
140 /* Write a string to the output location specified in FUNCTION.
|
|
141 Arguments NONRELOC, RELOC, OFFSET, and LEN are as in
|
|
142 buffer_insert_string_1() in insdel.c. */
|
|
143
|
|
144 static void
|
|
145 output_string (Lisp_Object function, CONST Bufbyte *nonreloc,
|
|
146 Lisp_Object reloc, Bytecount offset, Bytecount len)
|
|
147 {
|
|
148 /* This function can GC */
|
|
149 Charcount ccoff, cclen;
|
|
150 /* We change the value of nonreloc (fetching it from reloc as
|
|
151 necessary), but we don't want to pass this changed value on to
|
|
152 other functions that take both a nonreloc and a reloc, or things
|
|
153 may get confused and an assertion failure in
|
|
154 fixup_internal_substring() may get triggered. */
|
|
155 CONST Bufbyte *newnonreloc = nonreloc;
|
|
156 struct gcpro gcpro1, gcpro2;
|
|
157
|
|
158 /* Emacs won't print whilst GCing, but an external debugger might */
|
|
159 if (gc_in_progress) return;
|
|
160
|
|
161 /* Perhaps not necessary but probably safer. */
|
|
162 GCPRO2 (function, reloc);
|
|
163
|
|
164 fixup_internal_substring (newnonreloc, reloc, offset, &len);
|
|
165
|
|
166 if (STRINGP (reloc))
|
16
|
167 newnonreloc = XSTRING_DATA (reloc);
|
0
|
168
|
|
169 ccoff = bytecount_to_charcount (newnonreloc, offset);
|
|
170 cclen = bytecount_to_charcount (newnonreloc + offset, len);
|
|
171
|
|
172 if (LSTREAMP (function))
|
|
173 {
|
|
174 /* Lstream_write() could easily cause GC inside of it, if the
|
|
175 stream is a print-stream. (It will call output_string()
|
|
176 recursively.) This is probably the fastest way to fix this
|
|
177 problem. (alloca() is very fast on machines that have it
|
|
178 built-in, and you avoid some nasty problems with recursion
|
|
179 that could result from using a static buffer somewhere.)
|
|
180
|
|
181 The other possibility is to inhibit GC, but that of course
|
|
182 would require an unwind-protect, which is usually a lot
|
|
183 slower than the small amount of memcpy()ing that happens
|
|
184 here. */
|
|
185 if (STRINGP (reloc))
|
|
186 {
|
|
187 Bufbyte *copied = (Bufbyte *) alloca (len);
|
|
188 memcpy (copied, newnonreloc + offset, len);
|
|
189 Lstream_write (XLSTREAM (function), copied, len);
|
|
190 }
|
|
191 else
|
|
192 Lstream_write (XLSTREAM (function), newnonreloc + offset, len);
|
|
193
|
|
194 if (print_unbuffered)
|
|
195 Lstream_flush (XLSTREAM (function));
|
|
196 }
|
|
197
|
|
198 #ifndef standalone
|
|
199 else if (BUFFERP (function))
|
|
200 {
|
|
201 CHECK_LIVE_BUFFER (function);
|
|
202 buffer_insert_string (XBUFFER (function), nonreloc, reloc, offset, len);
|
|
203 }
|
|
204 else if (MARKERP (function))
|
|
205 {
|
|
206 /* marker_position will err if marker doesn't point anywhere */
|
|
207 Bufpos spoint = marker_position (function);
|
|
208
|
|
209 buffer_insert_string_1 (XBUFFER (Fmarker_buffer (function)),
|
|
210 spoint, nonreloc, reloc, offset, len,
|
|
211 0);
|
|
212 Fset_marker (function, make_int (spoint + cclen),
|
|
213 Fmarker_buffer (function));
|
|
214 }
|
|
215 else if (FRAMEP (function))
|
|
216 {
|
|
217 struct frame *f = XFRAME (function);
|
|
218 if (!EQ (Vprint_message_label, echo_area_status (f)))
|
|
219 clear_echo_area_from_print (f, Qnil, 1);
|
|
220 echo_area_append (f, nonreloc, reloc, offset, len, Vprint_message_label);
|
|
221 }
|
|
222 #endif /* not standalone */
|
|
223 else if (EQ (function, Qt) || EQ (function, Qnil))
|
|
224 {
|
|
225 write_string_to_stdio_stream (stdout, 0, newnonreloc, offset, len,
|
16
|
226 FORMAT_TERMINAL);
|
0
|
227 }
|
|
228 else
|
|
229 {
|
|
230 Charcount iii;
|
|
231
|
|
232 for (iii = ccoff; iii < cclen + ccoff; iii++)
|
|
233 {
|
|
234 call1 (function,
|
|
235 make_char (charptr_emchar_n (newnonreloc, iii)));
|
|
236 if (STRINGP (reloc))
|
16
|
237 newnonreloc = XSTRING_DATA (reloc);
|
0
|
238 }
|
|
239 }
|
|
240
|
|
241 UNGCPRO;
|
|
242 }
|
|
243
|
|
244 struct print_stream
|
|
245 {
|
|
246 FILE *file;
|
|
247 Lisp_Object fun;
|
|
248 };
|
|
249
|
|
250 #define get_print_stream(stream) \
|
|
251 ((struct print_stream *) Lstream_data (stream))
|
|
252
|
|
253 DEFINE_LSTREAM_IMPLEMENTATION ("print", lstream_print,
|
|
254 sizeof (struct print_stream));
|
|
255
|
|
256 static Lisp_Object
|
|
257 make_print_output_stream (FILE *file, Lisp_Object fun)
|
|
258 {
|
|
259 Lstream *str = Lstream_new (lstream_print, "w");
|
|
260 struct print_stream *ps = get_print_stream (str);
|
|
261 Lisp_Object val = Qnil;
|
|
262
|
|
263 Lstream_set_character_mode (str);
|
|
264 ps->file = file;
|
|
265 ps->fun = fun;
|
|
266 XSETLSTREAM (val, str);
|
|
267 return val;
|
|
268 }
|
|
269
|
|
270 /* #### This isn't being used anywhere at the moment. Is it supposed
|
|
271 to be? */
|
|
272 #if 0
|
|
273 static void
|
|
274 reset_print_stream (Lstream *str, FILE *file, Lisp_Object fun)
|
|
275 {
|
|
276 struct print_stream *ps = get_print_stream (str);
|
|
277
|
|
278 Lstream_reopen (str);
|
|
279 ps->file = file;
|
|
280 ps->fun = fun;
|
|
281 }
|
|
282 #endif
|
|
283
|
|
284 static Lisp_Object
|
|
285 print_marker (Lisp_Object obj, void (*markobj) (Lisp_Object))
|
|
286 {
|
|
287 return get_print_stream (XLSTREAM (obj))->fun;
|
|
288 }
|
|
289
|
|
290 static int
|
|
291 print_writer (Lstream *stream, CONST unsigned char *data, int size)
|
|
292 {
|
|
293 struct print_stream *ps = get_print_stream (stream);
|
|
294
|
|
295 if (ps->file)
|
|
296 {
|
|
297 write_string_to_stdio_stream (ps->file, 0, data, 0, size,
|
16
|
298 FORMAT_TERMINAL);
|
0
|
299 /* Make sure it really gets written now. */
|
|
300 if (print_unbuffered)
|
|
301 fflush (ps->file);
|
|
302 }
|
|
303 else
|
|
304 output_string (ps->fun, data, Qnil, 0, size);
|
|
305 return size;
|
|
306 }
|
|
307
|
|
308 static Lisp_Object
|
|
309 canonicalize_printcharfun (Lisp_Object printcharfun)
|
|
310 {
|
|
311 if (NILP (printcharfun))
|
|
312 printcharfun = Vstandard_output;
|
|
313
|
|
314 if (EQ (printcharfun, Qt) || NILP (printcharfun))
|
|
315 {
|
|
316 #ifndef standalone
|
|
317 printcharfun = Fselected_frame (Qnil); /* print to minibuffer */
|
|
318 #endif
|
|
319 }
|
173
|
320 return printcharfun;
|
0
|
321 }
|
|
322
|
|
323
|
|
324 static Lisp_Object
|
|
325 print_prepare (Lisp_Object printcharfun)
|
|
326 {
|
|
327 FILE *stdio_stream = 0;
|
|
328
|
|
329 /* Emacs won't print whilst GCing, but an external debugger might */
|
|
330 if (gc_in_progress)
|
173
|
331 return Qnil;
|
0
|
332
|
|
333 printcharfun = canonicalize_printcharfun (printcharfun);
|
|
334 if (EQ (printcharfun, Qnil))
|
|
335 {
|
|
336 stdio_stream = stdout;
|
|
337 }
|
|
338 #if 0 /* Don't bother */
|
|
339 else if (SUBRP (indirect_function (printcharfun, 0))
|
173
|
340 && (XSUBR (indirect_function (printcharfun, 0))
|
0
|
341 == Sexternal_debugging_output))
|
|
342 {
|
|
343 stdio_stream = stderr;
|
|
344 }
|
|
345 #endif
|
245
|
346 if (!CONSP (Vprint_gensym))
|
|
347 Vprint_gensym_alist = Qnil;
|
173
|
348
|
0
|
349 return make_print_output_stream (stdio_stream, printcharfun);
|
|
350 }
|
|
351
|
|
352 static void
|
|
353 print_finish (Lisp_Object stream)
|
|
354 {
|
|
355 /* Emacs won't print whilst GCing, but an external debugger might */
|
|
356 if (gc_in_progress)
|
|
357 return;
|
|
358
|
245
|
359 if (!CONSP (Vprint_gensym))
|
|
360 Vprint_gensym_alist = Qnil;
|
|
361
|
0
|
362 Lstream_delete (XLSTREAM (stream));
|
|
363 }
|
|
364
|
|
365 #if 1 /* Prefer space over "speed" */
|
|
366 #define write_char_internal(string_of_length_1, stream) \
|
|
367 write_string_1 ((CONST Bufbyte *) (string_of_length_1), 1, (stream))
|
|
368 #else
|
|
369 #define write_char_internal(string_of_length_1, stream) \
|
|
370 output_string ((stream), (CONST Bufbyte *) (string_of_length_1), Qnil, 0, 1)
|
|
371 #endif
|
|
372
|
|
373 /* NOTE: Do not call this with the data of a Lisp_String,
|
|
374 * as printcharfun might cause a GC, which might cause
|
|
375 * the string's data to be relocated.
|
|
376 * Use print_object_internal (string, printcharfun, 0)
|
|
377 * to princ a Lisp_String
|
|
378 * Note: "stream" should be the result of "canonicalize_printcharfun"
|
|
379 * (ie Qnil means stdout, not Vstandard_output, etc)
|
|
380 */
|
|
381 void
|
|
382 write_string_1 (CONST Bufbyte *str, Bytecount size, Lisp_Object stream)
|
|
383 {
|
|
384 /* This function can GC */
|
|
385 assert (size >= 0);
|
|
386 output_string (stream, str, Qnil, 0, size);
|
|
387 }
|
|
388
|
|
389 void
|
|
390 write_c_string (CONST char *str, Lisp_Object stream)
|
|
391 {
|
|
392 /* This function can GC */
|
|
393 write_string_1 ((CONST Bufbyte *) str, strlen (str), stream);
|
|
394 }
|
|
395
|
|
396
|
20
|
397 DEFUN ("write-char", Fwrite_char, 1, 2, 0, /*
|
0
|
398 Output character CH to stream STREAM.
|
|
399 STREAM defaults to the value of `standard-output' (which see).
|
20
|
400 */
|
|
401 (ch, stream))
|
0
|
402 {
|
|
403 /* This function can GC */
|
|
404 Bufbyte str[MAX_EMCHAR_LEN];
|
|
405 Bytecount len;
|
|
406
|
|
407 CHECK_CHAR_COERCE_INT (ch);
|
|
408 len = set_charptr_emchar (str, XCHAR (ch));
|
|
409 output_string (canonicalize_printcharfun (stream), str, Qnil, 0, len);
|
|
410 return ch;
|
|
411 }
|
|
412
|
|
413 #ifndef standalone
|
|
414
|
|
415 void
|
|
416 temp_output_buffer_setup (CONST char *bufname)
|
|
417 {
|
|
418 /* This function can GC */
|
|
419 struct buffer *old = current_buffer;
|
|
420 Lisp_Object buf;
|
|
421
|
|
422 #ifdef I18N3
|
|
423 /* #### This function should accept a Lisp_Object instead of a char *,
|
|
424 so that proper translation on the buffer name can occur. */
|
|
425 #endif
|
|
426
|
|
427 Fset_buffer (Fget_buffer_create (build_string (bufname)));
|
|
428
|
|
429 current_buffer->read_only = Qnil;
|
223
|
430 Ferase_buffer (Qnil);
|
0
|
431
|
|
432 XSETBUFFER (buf, current_buffer);
|
|
433 specbind (Qstandard_output, buf);
|
|
434
|
|
435 set_buffer_internal (old);
|
|
436 }
|
|
437
|
|
438 Lisp_Object
|
173
|
439 internal_with_output_to_temp_buffer (CONST char *bufname,
|
0
|
440 Lisp_Object (*function) (Lisp_Object arg),
|
173
|
441 Lisp_Object arg,
|
0
|
442 Lisp_Object same_frame)
|
|
443 {
|
|
444 int speccount = specpdl_depth ();
|
|
445 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
446 Lisp_Object buf = Qnil;
|
|
447
|
|
448 GCPRO3 (buf, arg, same_frame);
|
|
449
|
|
450 temp_output_buffer_setup (GETTEXT (bufname));
|
|
451 buf = Vstandard_output;
|
|
452
|
|
453 arg = (*function) (arg);
|
|
454
|
|
455 temp_output_buffer_show (buf, same_frame);
|
|
456 UNGCPRO;
|
|
457
|
|
458 return unbind_to (speccount, arg);
|
|
459 }
|
|
460
|
20
|
461 DEFUN ("with-output-to-temp-buffer", Fwith_output_to_temp_buffer, 1, UNEVALLED, 0, /*
|
0
|
462 Bind `standard-output' to buffer BUFNAME, eval BODY, then show that buffer.
|
|
463 The buffer is cleared out initially, and marked as unmodified when done.
|
|
464 All output done by BODY is inserted in that buffer by default.
|
|
465 The buffer is displayed in another window, but not selected.
|
|
466 The value of the last form in BODY is returned.
|
|
467 If BODY does not finish normally, the buffer BUFNAME is not displayed.
|
|
468
|
|
469 If variable `temp-buffer-show-function' is non-nil, call it at the end
|
|
470 to get the buffer displayed. It gets one argument, the buffer to display.
|
20
|
471 */
|
|
472 (args))
|
0
|
473 {
|
|
474 /* This function can GC */
|
|
475 struct gcpro gcpro1;
|
|
476 Lisp_Object name;
|
|
477 int speccount = specpdl_depth ();
|
|
478 Lisp_Object buf, val;
|
|
479
|
|
480 #ifdef I18N3
|
|
481 /* #### should set the buffer to be translating. See print_internal(). */
|
|
482 #endif
|
|
483
|
|
484 GCPRO1 (args);
|
|
485 name = Feval (Fcar (args));
|
|
486 UNGCPRO;
|
|
487
|
|
488 CHECK_STRING (name);
|
16
|
489 temp_output_buffer_setup ((char *) XSTRING_DATA (name));
|
0
|
490 buf = Vstandard_output;
|
|
491
|
|
492 val = Fprogn (Fcdr (args));
|
|
493
|
|
494 temp_output_buffer_show (buf, Qnil);
|
|
495
|
|
496 return unbind_to (speccount, val);
|
|
497 }
|
|
498 #endif /* not standalone */
|
|
499
|
20
|
500 DEFUN ("terpri", Fterpri, 0, 1, 0, /*
|
0
|
501 Output a newline to STREAM.
|
|
502 If STREAM is omitted or nil, the value of `standard-output' is used.
|
20
|
503 */
|
|
504 (stream))
|
0
|
505 {
|
|
506 /* This function can GC */
|
|
507 Bufbyte str[1];
|
|
508 str[0] = '\n';
|
|
509 output_string (canonicalize_printcharfun (stream), str, Qnil, 0, 1);
|
|
510 return Qt;
|
|
511 }
|
|
512
|
20
|
513 DEFUN ("prin1", Fprin1, 1, 2, 0, /*
|
0
|
514 Output the printed representation of OBJECT, any Lisp object.
|
|
515 Quoting characters are printed when needed to make output that `read'
|
|
516 can handle, whenever this is possible.
|
|
517 Output stream is STREAM, or value of `standard-output' (which see).
|
20
|
518 */
|
|
519 (object, stream))
|
0
|
520 {
|
|
521 /* This function can GC */
|
|
522 Lisp_Object the_stream = Qnil;
|
|
523 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
524
|
|
525 GCPRO3 (object, stream, the_stream);
|
|
526 print_depth = 0;
|
|
527 the_stream = print_prepare (stream);
|
|
528 print_internal (object, the_stream, 1);
|
|
529 print_finish (the_stream);
|
|
530 UNGCPRO;
|
|
531 return object;
|
|
532 }
|
|
533
|
219
|
534 /* Stream to which prin1-to-string prints. */
|
|
535 static Lisp_Object Vprin1_to_string_stream;
|
0
|
536
|
20
|
537 DEFUN ("prin1-to-string", Fprin1_to_string, 1, 2, 0, /*
|
0
|
538 Return a string containing the printed representation of OBJECT,
|
|
539 any Lisp object. Quoting characters are used when needed to make output
|
|
540 that `read' can handle, whenever this is possible, unless the optional
|
|
541 second argument NOESCAPE is non-nil.
|
20
|
542 */
|
|
543 (object, noescape))
|
0
|
544 {
|
|
545 /* This function can GC */
|
219
|
546 Lisp_Object result = Qnil;
|
|
547 Lstream *stream;
|
|
548 struct gcpro gcpro1;
|
|
549
|
|
550 /* We avoid creating a new stream for every invocation of
|
|
551 prin1_to_string, for better memory usage. */
|
0
|
552
|
219
|
553 if (NILP (Vprin1_to_string_stream))
|
|
554 Vprin1_to_string_stream = make_resizing_buffer_output_stream ();
|
|
555 stream = XLSTREAM (Vprin1_to_string_stream);
|
|
556 Lstream_rewind (stream);
|
|
557
|
|
558 /* In case a caller forgot to protect. */
|
|
559 GCPRO1 (object);
|
0
|
560 print_depth = 0;
|
219
|
561 print_internal (object, Vprin1_to_string_stream, NILP (noescape));
|
|
562 Lstream_flush (stream);
|
0
|
563 UNGCPRO;
|
219
|
564 result = make_string (resizing_buffer_stream_ptr (stream),
|
|
565 Lstream_byte_count (stream));
|
|
566 return result;
|
0
|
567 }
|
|
568
|
20
|
569 DEFUN ("princ", Fprinc, 1, 2, 0, /*
|
0
|
570 Output the printed representation of OBJECT, any Lisp object.
|
|
571 No quoting characters are used; no delimiters are printed around
|
|
572 the contents of strings.
|
|
573 Output stream is STREAM, or value of standard-output (which see).
|
20
|
574 */
|
|
575 (obj, stream))
|
0
|
576 {
|
|
577 /* This function can GC */
|
|
578 Lisp_Object the_stream = Qnil;
|
|
579 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
580
|
|
581 GCPRO3 (obj, stream, the_stream);
|
|
582 the_stream = print_prepare (stream);
|
|
583 print_depth = 0;
|
|
584 print_internal (obj, the_stream, 0);
|
|
585 print_finish (the_stream);
|
|
586 UNGCPRO;
|
173
|
587 return obj;
|
0
|
588 }
|
|
589
|
20
|
590 DEFUN ("print", Fprint, 1, 2, 0, /*
|
0
|
591 Output the printed representation of OBJECT, with newlines around it.
|
|
592 Quoting characters are printed when needed to make output that `read'
|
|
593 can handle, whenever this is possible.
|
|
594 Output stream is STREAM, or value of `standard-output' (which see).
|
20
|
595 */
|
|
596 (obj, stream))
|
0
|
597 {
|
|
598 /* This function can GC */
|
|
599 Lisp_Object the_stream = Qnil;
|
|
600 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
601
|
|
602 GCPRO3 (obj, stream, the_stream);
|
|
603 the_stream = print_prepare (stream);
|
|
604 print_depth = 0;
|
|
605 write_char_internal ("\n", the_stream);
|
|
606 print_internal (obj, the_stream, 1);
|
|
607 write_char_internal ("\n", the_stream);
|
|
608 print_finish (the_stream);
|
|
609 UNGCPRO;
|
|
610 return obj;
|
|
611 }
|
|
612
|
100
|
613 #include "emacsfns.h"
|
171
|
614
|
|
615 /* Synched with Emacs 19.34 -- underlying implementation (incarnated
|
|
616 in print_error_message) is completely divergent, though. */
|
100
|
617 DEFUN ("error-message-string", Ferror_message_string, 1, 1, 0, /*
|
|
618 Convert an error value (ERROR-SYMBOL . DATA) to an error message.
|
|
619 */
|
167
|
620 (data))
|
100
|
621 {
|
171
|
622 /* This function can GC */
|
100
|
623
|
219
|
624 /* This should maybe use Vprin1_to_string_stream... However, it's
|
|
625 called sufficiently rarely, so I don't think it should matter. */
|
|
626 Lisp_Object stream = make_resizing_buffer_output_stream ();
|
|
627 struct gcpro gcpro1;
|
|
628 GCPRO1 (stream);
|
|
629
|
|
630 print_error_message (data, stream);
|
|
631 Lstream_flush (XLSTREAM (stream));
|
100
|
632 UNGCPRO;
|
219
|
633 return make_string (resizing_buffer_stream_ptr (XLSTREAM (stream)),
|
|
634 Lstream_byte_count (XLSTREAM (stream)));
|
100
|
635 }
|
|
636
|
171
|
637 /* Print an error message for the error DATA onto Lisp output stream
|
|
638 STREAM (suitable for the print functions).
|
100
|
639
|
171
|
640 This is a complete implementation of `display-error', which used to
|
|
641 be in Lisp (see prim/cmdloop.el). It was ported to C so we can use
|
|
642 it in Ferror_message_string. Fdisplay_error and
|
|
643 Ferror_message_string are trivial wrappers to this function. */
|
|
644 static void
|
|
645 print_error_message (Lisp_Object error_object, Lisp_Object stream)
|
100
|
646 {
|
171
|
647 /* This function can GC */
|
|
648 Lisp_Object type;
|
|
649 Lisp_Object method = Qnil;
|
|
650 Lisp_Object tail = Qnil;
|
100
|
651 struct gcpro gcpro1;
|
171
|
652
|
|
653 GCPRO1 (tail);
|
|
654
|
|
655 type = Fcar_safe (error_object);
|
|
656
|
|
657 if (! (CONSP (error_object) && SYMBOLP (type)
|
|
658 && CONSP (Fget (type, Qerror_conditions, Qnil))))
|
|
659 goto error_throw;
|
100
|
660
|
171
|
661 tail = XCDR (error_object);
|
|
662 while (!NILP (tail))
|
|
663 {
|
|
664 if (CONSP (tail))
|
|
665 tail = XCDR (tail);
|
|
666 else
|
|
667 goto error_throw;
|
|
668 }
|
|
669 tail = Fget (type, Qerror_conditions, Qnil);
|
|
670 while (!NILP (tail))
|
100
|
671 {
|
171
|
672 if (!(CONSP (tail) && SYMBOLP (XCAR (tail))))
|
|
673 goto error_throw;
|
|
674 else if (!NILP (Fget (XCAR (tail), Qdisplay_error, Qnil)))
|
|
675 {
|
|
676 method = Fget (XCAR (tail), Qdisplay_error, Qnil);
|
|
677 goto error_throw;
|
|
678 }
|
|
679 else
|
|
680 tail = XCDR (tail);
|
|
681 }
|
|
682 /* Default method */
|
|
683 {
|
|
684 int first = 1;
|
|
685 Lisp_Object printcharfun = canonicalize_printcharfun (stream);
|
|
686 int speccount = specpdl_depth ();
|
|
687
|
|
688 specbind (Qprint_message_label, Qerror);
|
|
689 tail = Fcdr (error_object);
|
|
690 if (EQ (type, Qerror))
|
|
691 {
|
|
692 Fprinc (Fcar (tail), stream);
|
|
693 tail = Fcdr (tail);
|
|
694 }
|
|
695 else
|
|
696 {
|
|
697 Lisp_Object errmsg = Fget (type, Qerror_message, Qnil);
|
|
698 if (NILP (errmsg))
|
|
699 Fprinc (type, stream);
|
|
700 else
|
|
701 Fprinc (errmsg, stream);
|
|
702 }
|
|
703 while (!NILP (tail))
|
|
704 {
|
|
705 write_c_string (first ? ": " : ", ", printcharfun);
|
|
706 Fprin1 (Fcar (tail), stream);
|
|
707 tail = Fcdr (tail);
|
|
708 first = 0;
|
|
709 }
|
|
710 unbind_to (speccount, Qnil);
|
|
711 UNGCPRO;
|
|
712 return;
|
|
713 /* Unreached */
|
|
714 }
|
|
715
|
|
716 error_throw:
|
|
717 UNGCPRO;
|
|
718 if (NILP (method))
|
|
719 {
|
|
720 write_c_string ("Peculiar error ",
|
|
721 canonicalize_printcharfun (stream));
|
|
722 Fprin1 (error_object, stream);
|
|
723 return;
|
100
|
724 }
|
|
725 else
|
|
726 {
|
171
|
727 call2 (method, error_object, stream);
|
100
|
728 }
|
171
|
729 }
|
100
|
730
|
171
|
731 DEFUN ("display-error", Fdisplay_error, 2, 2, 0, /*
|
|
732 Display an error message for ERROR-OBJECT to STREAM.
|
|
733 */
|
|
734 (error_object, stream))
|
|
735 {
|
|
736 /* This function can GC */
|
|
737 print_error_message (error_object, stream);
|
|
738 return Qnil;
|
|
739 }
|
100
|
740
|
|
741
|
0
|
742 #ifdef LISP_FLOAT_TYPE
|
|
743
|
|
744 Lisp_Object Vfloat_output_format;
|
|
745 Lisp_Object Qfloat_output_format;
|
|
746
|
|
747 void
|
|
748 float_to_string (char *buf, double data)
|
|
749 /*
|
|
750 * This buffer should be at least as large as the max string size of the
|
|
751 * largest float, printed in the biggest notation. This is undoubtably
|
|
752 * 20d float_output_format, with the negative of the C-constant "HUGE"
|
|
753 * from <math.h>.
|
173
|
754 *
|
0
|
755 * On the vax the worst case is -1e38 in 20d format which takes 61 bytes.
|
173
|
756 *
|
0
|
757 * I assume that IEEE-754 format numbers can take 329 bytes for the worst
|
|
758 * case of -1e307 in 20d float_output_format. What is one to do (short of
|
|
759 * re-writing _doprnt to be more sane)?
|
|
760 * -wsr
|
|
761 */
|
|
762 {
|
|
763 Bufbyte *cp, c;
|
|
764 int width;
|
173
|
765
|
0
|
766 if (NILP (Vfloat_output_format)
|
|
767 || !STRINGP (Vfloat_output_format))
|
|
768 lose:
|
|
769 sprintf (buf, "%.16g", data);
|
|
770 else /* oink oink */
|
|
771 {
|
|
772 /* Check that the spec we have is fully valid.
|
|
773 This means not only valid for printf,
|
|
774 but meant for floats, and reasonable. */
|
16
|
775 cp = XSTRING_DATA (Vfloat_output_format);
|
0
|
776
|
|
777 if (cp[0] != '%')
|
|
778 goto lose;
|
|
779 if (cp[1] != '.')
|
|
780 goto lose;
|
|
781
|
|
782 cp += 2;
|
|
783 for (width = 0; (c = *cp, isdigit (c)); cp++)
|
|
784 {
|
|
785 width *= 10;
|
|
786 width += c - '0';
|
|
787 }
|
|
788
|
173
|
789 if (*cp != 'e' && *cp != 'f' && *cp != 'g' && *cp != 'E' && *cp != 'G')
|
0
|
790 goto lose;
|
|
791
|
|
792 if (width < (int) (*cp != 'e' && *cp != 'E') || width > DBL_DIG)
|
|
793 goto lose;
|
|
794
|
|
795 if (cp[1] != 0)
|
|
796 goto lose;
|
|
797
|
16
|
798 sprintf (buf, (char *) XSTRING_DATA (Vfloat_output_format),
|
0
|
799 data);
|
|
800 }
|
|
801
|
|
802 /* added by jwz: don't allow "1.0" to print as "1"; that destroys
|
|
803 the read-equivalence of lisp objects. (* x 1) and (* x 1.0) do
|
|
804 not do the same thing, so it's important that the printed
|
|
805 representation of that form not be corrupted by the printer.
|
|
806 */
|
|
807 {
|
|
808 Bufbyte *s = (Bufbyte *) buf; /* don't use signed chars here!
|
|
809 isdigit() can't hack them! */
|
|
810 if (*s == '-') s++;
|
|
811 for (; *s; s++)
|
|
812 /* if there's a non-digit, then there is a decimal point, or
|
|
813 it's in exponential notation, both of which are ok. */
|
|
814 if (!isdigit (*s))
|
|
815 goto DONE_LABEL;
|
|
816 /* otherwise, we need to hack it. */
|
|
817 *s++ = '.';
|
|
818 *s++ = '0';
|
|
819 *s = 0;
|
|
820 }
|
|
821 DONE_LABEL:
|
|
822
|
|
823 /* Some machines print "0.4" as ".4". I don't like that. */
|
|
824 if (buf [0] == '.' || (buf [0] == '-' && buf [1] == '.'))
|
|
825 {
|
|
826 int i;
|
|
827 for (i = strlen (buf) + 1; i >= 0; i--)
|
|
828 buf [i+1] = buf [i];
|
|
829 buf [(buf [0] == '-' ? 1 : 0)] = '0';
|
|
830 }
|
|
831 }
|
|
832 #endif /* LISP_FLOAT_TYPE */
|
|
833
|
|
834 static void
|
|
835 print_vector_internal (CONST char *start, CONST char *end,
|
173
|
836 Lisp_Object obj,
|
0
|
837 Lisp_Object printcharfun, int escapeflag)
|
|
838 {
|
|
839 /* This function can GC */
|
|
840 int i;
|
173
|
841 int len = XVECTOR_LENGTH (obj);
|
0
|
842 int last = len;
|
|
843 struct gcpro gcpro1, gcpro2;
|
|
844 GCPRO2 (obj, printcharfun);
|
|
845
|
|
846 if (INTP (Vprint_length))
|
|
847 {
|
|
848 int max = XINT (Vprint_length);
|
|
849 if (max < len) last = max;
|
|
850 }
|
|
851
|
|
852 write_c_string (start, printcharfun);
|
|
853 for (i = 0; i < last; i++)
|
|
854 {
|
173
|
855 Lisp_Object elt = XVECTOR_DATA (obj)[i];
|
0
|
856 if (i != 0) write_char_internal (" ", printcharfun);
|
|
857 print_internal (elt, printcharfun, escapeflag);
|
|
858 }
|
|
859 UNGCPRO;
|
|
860 if (last != len)
|
|
861 write_c_string (" ...", printcharfun);
|
|
862 write_c_string (end, printcharfun);
|
|
863 }
|
|
864
|
207
|
865 void
|
|
866 print_cons (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
867 {
|
|
868 /* This function can GC */
|
|
869 struct gcpro gcpro1, gcpro2;
|
|
870
|
|
871 /* If print_readably is on, print (quote -foo-) as '-foo-
|
|
872 (Yeah, this should really be what print-pretty does, but we
|
|
873 don't have the rest of a pretty printer, and this actually
|
|
874 has non-negligible impact on size/speed of .elc files.)
|
|
875 */
|
|
876 if (print_readably &&
|
|
877 EQ (XCAR (obj), Qquote) &&
|
|
878 CONSP (XCDR (obj)) &&
|
|
879 NILP (XCDR (XCDR (obj))))
|
|
880 {
|
|
881 obj = XCAR (XCDR (obj));
|
|
882 GCPRO2 (obj, printcharfun);
|
|
883 write_char_internal ("'", printcharfun);
|
|
884 UNGCPRO;
|
|
885 print_internal (obj, printcharfun, escapeflag);
|
|
886 return;
|
|
887 }
|
|
888
|
|
889 GCPRO2 (obj, printcharfun);
|
|
890 write_char_internal ("(", printcharfun);
|
|
891 {
|
|
892 int i = 0;
|
|
893 int max = 0;
|
|
894
|
|
895 if (INTP (Vprint_length))
|
|
896 max = XINT (Vprint_length);
|
|
897 while (CONSP (obj))
|
|
898 {
|
|
899 if (i++)
|
|
900 write_char_internal (" ", printcharfun);
|
|
901 if (max && i > max)
|
|
902 {
|
|
903 write_c_string ("...", printcharfun);
|
|
904 break;
|
|
905 }
|
245
|
906 print_internal (XCAR (obj), printcharfun,
|
207
|
907 escapeflag);
|
245
|
908 obj = XCDR (obj);
|
207
|
909 }
|
|
910 }
|
|
911 if (!NILP (obj) && !CONSP (obj))
|
|
912 {
|
|
913 write_c_string (" . ", printcharfun);
|
|
914 print_internal (obj, printcharfun, escapeflag);
|
|
915 }
|
|
916 UNGCPRO;
|
|
917 write_char_internal (")", printcharfun);
|
|
918 return;
|
|
919 }
|
|
920
|
|
921 void
|
|
922 print_vector (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
923 {
|
|
924 print_vector_internal ("[", "]", obj, printcharfun, escapeflag);
|
|
925 }
|
|
926
|
|
927 void
|
|
928 print_string (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
929 {
|
245
|
930 struct Lisp_String *s = XSTRING (obj);
|
|
931 /* We distinguish between Bytecounts and Charcounts, to make
|
|
932 Vprint_string_length work correctly under Mule. */
|
|
933 Charcount size = string_char_length (s);
|
|
934 Charcount max = size;
|
|
935 Bytecount bcmax = string_length (s);
|
207
|
936 struct gcpro gcpro1, gcpro2;
|
|
937 GCPRO2 (obj, printcharfun);
|
|
938
|
|
939 if (INTP (Vprint_string_length) &&
|
|
940 XINT (Vprint_string_length) < max)
|
245
|
941 {
|
|
942 max = XINT (Vprint_string_length);
|
|
943 bcmax = charcount_to_bytecount (string_data (s), max);
|
|
944 }
|
207
|
945 if (max < 0)
|
245
|
946 {
|
|
947 max = 0;
|
|
948 bcmax = 0;
|
|
949 }
|
207
|
950
|
|
951 if (!escapeflag)
|
|
952 {
|
245
|
953 /* This deals with GC-relocation and Mule. */
|
|
954 output_string (printcharfun, 0, obj, 0, bcmax);
|
207
|
955 if (max < size)
|
|
956 write_c_string (" ...", printcharfun);
|
|
957 }
|
|
958 else
|
|
959 {
|
245
|
960 Bytecount i, last = 0;
|
207
|
961
|
|
962 write_char_internal ("\"", printcharfun);
|
245
|
963 for (i = 0; i < bcmax; i++)
|
207
|
964 {
|
|
965 Bufbyte ch = string_byte (s, i);
|
|
966 if (ch == '\"' || ch == '\\'
|
|
967 || (ch == '\n' && print_escape_newlines))
|
|
968 {
|
|
969 if (i > last)
|
|
970 {
|
|
971 output_string (printcharfun, 0, obj, last,
|
|
972 i - last);
|
|
973 }
|
|
974 if (ch == '\n')
|
|
975 {
|
|
976 write_c_string ("\\n", printcharfun);
|
|
977 }
|
|
978 else
|
|
979 {
|
|
980 write_char_internal ("\\", printcharfun);
|
|
981 /* This is correct for Mule because the
|
|
982 character is either \ or " */
|
|
983 write_char_internal ((char *) (string_data (s) + i),
|
|
984 printcharfun);
|
|
985 }
|
|
986 last = i + 1;
|
|
987 }
|
|
988 }
|
245
|
989 if (bcmax > last)
|
207
|
990 {
|
|
991 output_string (printcharfun, 0, obj, last,
|
245
|
992 bcmax - last);
|
207
|
993 }
|
|
994 if (max < size)
|
|
995 write_c_string (" ...", printcharfun);
|
|
996 write_char_internal ("\"", printcharfun);
|
|
997 }
|
|
998 UNGCPRO;
|
|
999 return;
|
|
1000 }
|
|
1001
|
|
1002
|
0
|
1003 static void
|
|
1004 default_object_printer (Lisp_Object obj, Lisp_Object printcharfun,
|
|
1005 int escapeflag)
|
|
1006 {
|
|
1007 struct lcrecord_header *header =
|
|
1008 (struct lcrecord_header *) XPNTR (obj);
|
|
1009 char buf[200];
|
|
1010
|
|
1011 if (print_readably)
|
|
1012 error ("printing unreadable object #<%s 0x%x>",
|
211
|
1013 LHEADER_IMPLEMENTATION (&header->lheader)->name,
|
|
1014 header->uid);
|
0
|
1015
|
211
|
1016 sprintf (buf, "#<%s 0x%x>",
|
|
1017 LHEADER_IMPLEMENTATION (&header->lheader)->name,
|
0
|
1018 header->uid);
|
|
1019 write_c_string (buf, printcharfun);
|
|
1020 }
|
|
1021
|
|
1022 void
|
|
1023 internal_object_printer (Lisp_Object obj, Lisp_Object printcharfun,
|
|
1024 int escapeflag)
|
|
1025 {
|
|
1026 char buf[200];
|
173
|
1027 sprintf (buf, "#<INTERNAL OBJECT (XEmacs bug?) (%s) 0x%p>",
|
211
|
1028 XRECORD_LHEADER_IMPLEMENTATION (obj)->name,
|
173
|
1029 (void *) XPNTR (obj));
|
0
|
1030 write_c_string (buf, printcharfun);
|
|
1031 }
|
|
1032
|
|
1033 void
|
|
1034 print_internal (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
1035 {
|
|
1036 /* This function can GC */
|
|
1037 char buf[256];
|
|
1038
|
|
1039 QUIT;
|
|
1040
|
|
1041 /* Emacs won't print whilst GCing, but an external debugger might */
|
|
1042 if (gc_in_progress) return;
|
|
1043
|
|
1044 #ifdef I18N3
|
|
1045 /* #### Both input and output streams should have a flag associated
|
|
1046 with them indicating whether output to that stream, or strings
|
|
1047 read from the stream, get translated using Fgettext(). Such a
|
|
1048 stream is called a "translating stream". For the minibuffer and
|
|
1049 external-debugging-output this is always true on output, and
|
|
1050 with-output-to-temp-buffer sets the flag to true for the buffer
|
|
1051 it creates. This flag should also be user-settable. Perhaps it
|
|
1052 should be split up into two flags, one for input and one for
|
|
1053 output. */
|
|
1054 #endif
|
|
1055
|
177
|
1056 /* Detect circularities and truncate them.
|
|
1057 No need to offer any alternative--this is better than an error. */
|
|
1058 if (CONSP (obj) || VECTORP (obj) || COMPILED_FUNCTIONP (obj))
|
|
1059 {
|
|
1060 int i;
|
|
1061 for (i = 0; i < print_depth; i++)
|
|
1062 if (EQ (obj, being_printed[i]))
|
|
1063 {
|
|
1064 sprintf (buf, "#%d", i);
|
|
1065 write_c_string (buf, printcharfun);
|
|
1066 return;
|
|
1067 }
|
|
1068 }
|
|
1069
|
|
1070
|
|
1071 being_printed[print_depth] = obj;
|
0
|
1072 print_depth++;
|
|
1073
|
177
|
1074 if (print_depth > PRINT_CIRCLE)
|
0
|
1075 error ("Apparently circular structure being printed");
|
|
1076
|
|
1077 switch (XTYPE (obj))
|
|
1078 {
|
207
|
1079 #ifdef USE_MINIMAL_TAGBITS
|
|
1080 case Lisp_Type_Int_Even:
|
|
1081 case Lisp_Type_Int_Odd:
|
|
1082 #else
|
185
|
1083 case Lisp_Type_Int:
|
207
|
1084 #endif
|
0
|
1085 {
|
173
|
1086 sprintf (buf, "%ld", (long) XINT (obj));
|
0
|
1087 write_c_string (buf, printcharfun);
|
|
1088 break;
|
|
1089 }
|
|
1090
|
185
|
1091 case Lisp_Type_Char:
|
70
|
1092 {
|
|
1093 /* God intended that this be #\..., you know. */
|
|
1094 Emchar ch = XCHAR (obj);
|
|
1095 write_c_string ("?", printcharfun);
|
|
1096 if (ch == '\n')
|
|
1097 strcpy (buf, "\\n");
|
|
1098 else if (ch == '\r')
|
|
1099 strcpy (buf, "\\r");
|
|
1100 else if (ch == '\t')
|
|
1101 strcpy (buf, "\\t");
|
187
|
1102 else if (ch < 32) {
|
70
|
1103 sprintf (buf, "\\^%c", ch + 64);
|
187
|
1104 if ((ch + 64) == '\\') {
|
|
1105 strcat(buf, "\\");
|
|
1106 }
|
|
1107 } else if (ch == 127)
|
70
|
1108 strcpy (buf, "\\^?");
|
|
1109 else if (ch >= 128 && ch < 160)
|
|
1110 {
|
|
1111 Bytecount i;
|
|
1112 strcpy (buf, "\\^");
|
|
1113 i = set_charptr_emchar ((unsigned char *) (buf + 2), ch + 64);
|
|
1114 buf[2+i] = '\0';
|
|
1115 }
|
|
1116 else if (ch < 127
|
|
1117 && !isdigit (ch)
|
|
1118 && !isalpha (ch)
|
|
1119 && ch != '^') /* must not backslash this or it will
|
|
1120 be interpreted as the start of a
|
|
1121 control char */
|
|
1122 sprintf (buf, "\\%c", ch);
|
|
1123 else
|
|
1124 {
|
|
1125 Bytecount i;
|
|
1126 i = set_charptr_emchar ((unsigned char *) buf, ch);
|
|
1127 buf[i] = '\0';
|
|
1128 }
|
|
1129 write_c_string (buf, printcharfun);
|
|
1130 break;
|
|
1131 }
|
|
1132
|
207
|
1133 #ifndef LRECORD_STRING
|
185
|
1134 case Lisp_Type_String:
|
0
|
1135 {
|
207
|
1136 print_string(obj, printcharfun, escapeflag);
|
0
|
1137 break;
|
|
1138 }
|
207
|
1139 #endif /* ! LRECORD_STRING */
|
0
|
1140
|
207
|
1141 #ifndef LRECORD_CONS
|
185
|
1142 case Lisp_Type_Cons:
|
0
|
1143 {
|
|
1144 struct gcpro gcpro1, gcpro2;
|
|
1145
|
|
1146 /* If deeper than spec'd depth, print placeholder. */
|
|
1147 if (INTP (Vprint_level)
|
|
1148 && print_depth > XINT (Vprint_level))
|
|
1149 {
|
207
|
1150 GCPRO2 (obj, printcharfun);
|
0
|
1151 write_c_string ("...", printcharfun);
|
|
1152 UNGCPRO;
|
|
1153 break;
|
|
1154 }
|
|
1155
|
207
|
1156 print_cons (obj, printcharfun, escapeflag);
|
0
|
1157 break;
|
|
1158 }
|
207
|
1159 #endif /* ! LRECORD_CONS */
|
0
|
1160
|
|
1161 #ifndef LRECORD_VECTOR
|
185
|
1162 case Lisp_Type_Vector:
|
0
|
1163 {
|
207
|
1164 struct gcpro gcpro1, gcpro2;
|
|
1165
|
0
|
1166 /* If deeper than spec'd depth, print placeholder. */
|
|
1167 if (INTP (Vprint_level)
|
|
1168 && print_depth > XINT (Vprint_level))
|
|
1169 {
|
207
|
1170 GCPRO2 (obj, printcharfun);
|
0
|
1171 write_c_string ("...", printcharfun);
|
207
|
1172 UNGCPRO;
|
0
|
1173 break;
|
|
1174 }
|
|
1175
|
|
1176 /* God intended that this be #(...), you know. */
|
|
1177 print_vector_internal ("[", "]", obj, printcharfun, escapeflag);
|
|
1178 break;
|
|
1179 }
|
|
1180 #endif /* !LRECORD_VECTOR */
|
|
1181
|
|
1182 #ifndef LRECORD_SYMBOL
|
185
|
1183 case Lisp_Type_Symbol:
|
0
|
1184 {
|
|
1185 print_symbol (obj, printcharfun, escapeflag);
|
|
1186 break;
|
|
1187 }
|
|
1188 #endif /* !LRECORD_SYMBOL */
|
|
1189
|
185
|
1190 case Lisp_Type_Record:
|
0
|
1191 {
|
|
1192 struct lrecord_header *lheader = XRECORD_LHEADER (obj);
|
|
1193 struct gcpro gcpro1, gcpro2;
|
|
1194
|
207
|
1195 #if defined(LRECORD_CONS) || defined(LRECORD_VECTOR)
|
|
1196 if (CONSP (obj) || VECTORP(obj))
|
|
1197 {
|
|
1198 /* If deeper than spec'd depth, print placeholder. */
|
|
1199 if (INTP (Vprint_level)
|
|
1200 && print_depth > XINT (Vprint_level))
|
|
1201 {
|
|
1202 GCPRO2 (obj, printcharfun);
|
|
1203 write_c_string ("...", printcharfun);
|
|
1204 UNGCPRO;
|
|
1205 break;
|
|
1206 }
|
|
1207 }
|
|
1208 #endif
|
|
1209
|
0
|
1210 GCPRO2 (obj, printcharfun);
|
211
|
1211 if (LHEADER_IMPLEMENTATION (lheader)->printer)
|
|
1212 ((LHEADER_IMPLEMENTATION (lheader)->printer)
|
0
|
1213 (obj, printcharfun, escapeflag));
|
|
1214 else
|
|
1215 default_object_printer (obj, printcharfun, escapeflag);
|
|
1216 UNGCPRO;
|
|
1217 break;
|
|
1218 }
|
|
1219
|
|
1220 default:
|
|
1221 {
|
|
1222 /* We're in trouble if this happens!
|
|
1223 Probably should just abort () */
|
|
1224 if (print_readably)
|
|
1225 error ("printing illegal data type #o%03o",
|
|
1226 (int) XTYPE (obj));
|
|
1227 write_c_string ("#<EMACS BUG: ILLEGAL DATATYPE ",
|
|
1228 printcharfun);
|
|
1229 sprintf (buf, "(#o%3o)", (int) XTYPE (obj));
|
|
1230 write_c_string (buf, printcharfun);
|
|
1231 write_c_string
|
|
1232 (" Save your buffers immediately and please report this bug>",
|
|
1233 printcharfun);
|
|
1234 break;
|
|
1235 }
|
|
1236 }
|
|
1237
|
|
1238 print_depth--;
|
|
1239 }
|
|
1240
|
|
1241 static void
|
|
1242 print_compiled_function_internal (CONST char *start, CONST char *end,
|
173
|
1243 Lisp_Object obj,
|
0
|
1244 Lisp_Object printcharfun, int escapeflag)
|
|
1245 {
|
|
1246 /* This function can GC */
|
|
1247 struct Lisp_Compiled_Function *b =
|
|
1248 XCOMPILED_FUNCTION (obj); /* GC doesn't relocate */
|
|
1249 int docp = b->flags.documentationp;
|
|
1250 int intp = b->flags.interactivep;
|
|
1251 struct gcpro gcpro1, gcpro2;
|
|
1252 char buf[100];
|
|
1253 GCPRO2 (obj, printcharfun);
|
|
1254
|
|
1255 write_c_string (start, printcharfun);
|
|
1256 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
|
|
1257 if (!print_readably)
|
|
1258 {
|
|
1259 Lisp_Object ann = compiled_function_annotation (b);
|
|
1260 if (!NILP (ann))
|
|
1261 {
|
|
1262 write_c_string ("(from ", printcharfun);
|
|
1263 print_internal (ann, printcharfun, 1);
|
|
1264 write_c_string (") ", printcharfun);
|
|
1265 }
|
|
1266 }
|
|
1267 #endif /* COMPILED_FUNCTION_ANNOTATION_HACK */
|
|
1268 /* COMPILED_ARGLIST = 0 */
|
|
1269 print_internal (b->arglist, printcharfun, escapeflag);
|
|
1270 /* COMPILED_BYTECODE = 1 */
|
|
1271 write_char_internal (" ", printcharfun);
|
|
1272 /* we don't really want to see that junk in the bytecode instructions. */
|
|
1273 if (STRINGP (b->bytecodes) && !print_readably)
|
|
1274 {
|
16
|
1275 sprintf (buf, "\"...(%ld)\"", (long) XSTRING_LENGTH (b->bytecodes));
|
0
|
1276 write_c_string (buf, printcharfun);
|
|
1277 }
|
|
1278 else
|
|
1279 print_internal (b->bytecodes, printcharfun, escapeflag);
|
|
1280 /* COMPILED_CONSTANTS = 2 */
|
|
1281 write_char_internal (" ", printcharfun);
|
|
1282 print_internal (b->constants, printcharfun, escapeflag);
|
|
1283 /* COMPILED_STACK_DEPTH = 3 */
|
|
1284 sprintf (buf, " %d", b->maxdepth);
|
|
1285 write_c_string (buf, printcharfun);
|
|
1286 /* COMPILED_DOC_STRING = 4 */
|
|
1287 if (docp || intp)
|
|
1288 {
|
|
1289 write_char_internal (" ", printcharfun);
|
|
1290 print_internal (compiled_function_documentation (b), printcharfun,
|
|
1291 escapeflag);
|
|
1292 }
|
|
1293 /* COMPILED_INTERACTIVE = 5 */
|
|
1294 if (intp)
|
|
1295 {
|
|
1296 write_char_internal (" ", printcharfun);
|
|
1297 print_internal (compiled_function_interactive (b), printcharfun,
|
|
1298 escapeflag);
|
|
1299 }
|
|
1300 UNGCPRO;
|
|
1301 write_c_string (end, printcharfun);
|
|
1302 }
|
|
1303
|
|
1304 void
|
|
1305 print_compiled_function (Lisp_Object obj, Lisp_Object printcharfun,
|
|
1306 int escapeflag)
|
|
1307 {
|
|
1308 /* This function can GC */
|
|
1309 print_compiled_function_internal (((print_readably) ? "#[" :
|
|
1310 "#<compiled-function "),
|
|
1311 ((print_readably) ? "]" : ">"),
|
|
1312 obj, printcharfun, escapeflag);
|
|
1313 }
|
|
1314
|
|
1315 #ifdef LISP_FLOAT_TYPE
|
|
1316 void
|
|
1317 print_float (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
1318 {
|
|
1319 char pigbuf[350]; /* see comments in float_to_string */
|
|
1320
|
|
1321 float_to_string (pigbuf, float_data (XFLOAT (obj)));
|
|
1322 write_c_string (pigbuf, printcharfun);
|
|
1323 }
|
|
1324 #endif /* LISP_FLOAT_TYPE */
|
|
1325
|
|
1326 void
|
|
1327 print_symbol (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
1328 {
|
|
1329 /* This function can GC */
|
|
1330 /* #### Bug!! (intern "") isn't printed in some distinguished way */
|
|
1331 /* #### (the reader also loses on it) */
|
|
1332 struct Lisp_String *name = XSYMBOL (obj)->name;
|
|
1333 Bytecount size = string_length (name);
|
|
1334 struct gcpro gcpro1, gcpro2;
|
|
1335
|
|
1336 if (!escapeflag)
|
|
1337 {
|
|
1338 /* This deals with GC-relocation */
|
|
1339 Lisp_Object nameobj;
|
|
1340 XSETSTRING (nameobj, name);
|
|
1341 output_string (printcharfun, 0, nameobj, 0, size);
|
|
1342 return;
|
|
1343 }
|
|
1344 GCPRO2 (obj, printcharfun);
|
|
1345
|
245
|
1346 /* If we print an uninterned symbol as part of a complex object and
|
|
1347 the flag print-gensym is non-nil, prefix it with #n= to read the
|
|
1348 object back with the #n# reader syntax later if needed. */
|
|
1349 if (!NILP (Vprint_gensym) && NILP (XSYMBOL (obj)->obarray))
|
0
|
1350 {
|
245
|
1351 if (print_depth > 1)
|
|
1352 {
|
|
1353 Lisp_Object tem = Fassq (obj, Vprint_gensym_alist);
|
|
1354 if (CONSP (tem))
|
|
1355 {
|
|
1356 write_char_internal ("#", printcharfun);
|
|
1357 print_internal (XCDR (tem), printcharfun, escapeflag);
|
|
1358 write_char_internal ("#", printcharfun);
|
|
1359 return;
|
|
1360 }
|
|
1361 else
|
|
1362 {
|
|
1363 if (CONSP (Vprint_gensym_alist))
|
|
1364 XSETINT (tem, XINT (XCDR (XCAR (Vprint_gensym_alist))) + 1);
|
|
1365 else
|
|
1366 XSETINT (tem, 1);
|
|
1367 Vprint_gensym_alist = Fcons (Fcons (obj, tem), Vprint_gensym_alist);
|
|
1368
|
|
1369 write_char_internal ("#", printcharfun);
|
|
1370 print_internal (tem, printcharfun, escapeflag);
|
|
1371 write_char_internal ("=", printcharfun);
|
|
1372 }
|
|
1373 }
|
|
1374 write_c_string ("#:", printcharfun);
|
0
|
1375 }
|
|
1376
|
|
1377 /* Does it look like an integer or a float? */
|
|
1378 {
|
|
1379 Bufbyte *data = string_data (name);
|
|
1380 Bytecount confusing = 0;
|
|
1381
|
|
1382 if (size == 0)
|
|
1383 goto not_yet_confused; /* Really confusing */
|
|
1384 else if (isdigit (data[0]))
|
|
1385 confusing = 0;
|
|
1386 else if (size == 1)
|
|
1387 goto not_yet_confused;
|
|
1388 else if (data[0] == '-' || data[0] == '+')
|
|
1389 confusing = 1;
|
|
1390 else
|
|
1391 goto not_yet_confused;
|
|
1392
|
|
1393 for (; confusing < size; confusing++)
|
173
|
1394 {
|
0
|
1395 if (!isdigit (data[confusing]))
|
|
1396 {
|
|
1397 confusing = 0;
|
|
1398 break;
|
|
1399 }
|
|
1400 }
|
|
1401 not_yet_confused:
|
|
1402
|
|
1403 #ifdef LISP_FLOAT_TYPE
|
|
1404 if (!confusing)
|
|
1405 confusing = isfloat_string ((char *) data);
|
|
1406 #endif
|
|
1407 if (confusing)
|
|
1408 write_char_internal ("\\", printcharfun);
|
|
1409 }
|
|
1410
|
|
1411 {
|
|
1412 Lisp_Object nameobj;
|
|
1413 Bytecount i;
|
|
1414 Bytecount last = 0;
|
173
|
1415
|
0
|
1416 XSETSTRING (nameobj, name);
|
|
1417 for (i = 0; i < size; i++)
|
|
1418 {
|
|
1419 Bufbyte c = string_byte (name, i);
|
|
1420
|
|
1421 if (c == '\"' || c == '\\' || c == '\'' || c == ';' || c == '#' ||
|
|
1422 c == '(' || c == ')' || c == ',' || c =='.' || c == '`' ||
|
|
1423 c == '[' || c == ']' || c == '?' || c <= 040)
|
|
1424 {
|
|
1425 if (i > last)
|
|
1426 {
|
|
1427 output_string (printcharfun, 0, nameobj, last,
|
|
1428 i - last);
|
|
1429 }
|
|
1430 write_char_internal ("\\", printcharfun);
|
|
1431 last = i;
|
|
1432 }
|
|
1433 }
|
|
1434 output_string (printcharfun, 0, nameobj, last, size - last);
|
|
1435 }
|
|
1436 UNGCPRO;
|
|
1437 }
|
|
1438
|
|
1439 int alternate_do_pointer;
|
|
1440 char alternate_do_string[5000];
|
|
1441
|
20
|
1442 DEFUN ("alternate-debugging-output", Falternate_debugging_output, 1, 1, 0, /*
|
0
|
1443 Append CHARACTER to the array `alternate_do_string'.
|
|
1444 This can be used in place of `external-debugging-output' as a function
|
|
1445 to be passed to `print'. Before calling `print', set `alternate_do_pointer'
|
|
1446 to 0.
|
|
1447
|
20
|
1448 */
|
|
1449 (character))
|
0
|
1450 {
|
|
1451 Bufbyte str[MAX_EMCHAR_LEN];
|
|
1452 Bytecount len;
|
|
1453 int extlen;
|
|
1454 CONST Extbyte *extptr;
|
|
1455
|
|
1456 CHECK_CHAR_COERCE_INT (character);
|
|
1457 len = set_charptr_emchar (str, XCHAR (character));
|
16
|
1458 GET_CHARPTR_EXT_DATA_ALLOCA (str, len, FORMAT_TERMINAL, extptr, extlen);
|
0
|
1459 memcpy (alternate_do_string + alternate_do_pointer, extptr, extlen);
|
|
1460 alternate_do_pointer += extlen;
|
|
1461 alternate_do_string[alternate_do_pointer] = 0;
|
|
1462 return character;
|
|
1463 }
|
|
1464
|
20
|
1465 DEFUN ("external-debugging-output", Fexternal_debugging_output, 1, 3, 0, /*
|
0
|
1466 Write CHAR-OR-STRING to stderr or stdout.
|
|
1467 If optional arg STDOUT-P is non-nil, write to stdout; otherwise, write
|
|
1468 to stderr. You can use this function to write directly to the terminal.
|
|
1469 This function can be used as the STREAM argument of Fprint() or the like.
|
|
1470
|
|
1471 If you have opened a termscript file (using `open-termscript'), then
|
|
1472 the output also will be logged to this file.
|
20
|
1473 */
|
|
1474 (char_or_string, stdout_p, device))
|
0
|
1475 {
|
|
1476 FILE *file = 0;
|
|
1477 struct console *con = 0;
|
|
1478
|
|
1479 if (NILP (device))
|
|
1480 {
|
|
1481 if (!NILP (stdout_p))
|
|
1482 file = stdout;
|
|
1483 else
|
|
1484 file = stderr;
|
|
1485 }
|
|
1486 else
|
|
1487 {
|
|
1488 CHECK_LIVE_DEVICE (device);
|
|
1489 if (!DEVICE_TTY_P (XDEVICE (device)) &&
|
|
1490 !DEVICE_STREAM_P (XDEVICE (device)))
|
|
1491 signal_simple_error ("Must be tty or stream device", device);
|
|
1492 con = XCONSOLE (DEVICE_CONSOLE (XDEVICE (device)));
|
|
1493 if (DEVICE_TTY_P (XDEVICE (device)))
|
|
1494 file = 0;
|
|
1495 else if (!NILP (stdout_p))
|
|
1496 file = CONSOLE_STREAM_DATA (con)->outfd;
|
|
1497 else
|
|
1498 file = CONSOLE_STREAM_DATA (con)->errfd;
|
|
1499 }
|
|
1500
|
|
1501 if (STRINGP (char_or_string))
|
|
1502 write_string_to_stdio_stream (file, con,
|
16
|
1503 XSTRING_DATA (char_or_string),
|
|
1504 0, XSTRING_LENGTH (char_or_string),
|
|
1505 FORMAT_TERMINAL);
|
0
|
1506 else
|
|
1507 {
|
|
1508 Bufbyte str[MAX_EMCHAR_LEN];
|
|
1509 Bytecount len;
|
|
1510
|
|
1511 CHECK_CHAR_COERCE_INT (char_or_string);
|
|
1512 len = set_charptr_emchar (str, XCHAR (char_or_string));
|
16
|
1513 write_string_to_stdio_stream (file, con, str, 0, len, FORMAT_TERMINAL);
|
0
|
1514 }
|
|
1515
|
|
1516 return char_or_string;
|
|
1517 }
|
|
1518
|
20
|
1519 DEFUN ("open-termscript", Fopen_termscript, 1, 1, "FOpen termscript file: ", /*
|
0
|
1520 Start writing all terminal output to FILE as well as the terminal.
|
|
1521 FILE = nil means just close any termscript file currently open.
|
20
|
1522 */
|
|
1523 (file))
|
0
|
1524 {
|
|
1525 /* This function can GC */
|
|
1526 if (termscript != 0)
|
|
1527 fclose (termscript);
|
|
1528 termscript = 0;
|
|
1529
|
|
1530 if (! NILP (file))
|
|
1531 {
|
|
1532 file = Fexpand_file_name (file, Qnil);
|
16
|
1533 termscript = fopen ((char *) XSTRING_DATA (file), "w");
|
183
|
1534 if (termscript == NULL)
|
0
|
1535 report_file_error ("Opening termscript", Fcons (file, Qnil));
|
|
1536 }
|
|
1537 return Qnil;
|
|
1538 }
|
|
1539
|
|
1540 #if 1
|
|
1541 /* Debugging kludge -- unbuffered */
|
|
1542 static int debug_print_length = 50;
|
|
1543 static int debug_print_level = 15;
|
|
1544 Lisp_Object debug_temp;
|
|
1545 void debug_print_no_newline (Lisp_Object debug_print_obj);
|
|
1546 void
|
|
1547 debug_print_no_newline (Lisp_Object debug_print_obj)
|
|
1548 {
|
|
1549 /* This function can GC */
|
|
1550 int old_print_readably = print_readably;
|
|
1551 int old_print_depth = print_depth;
|
|
1552 Lisp_Object old_print_length = Vprint_length;
|
|
1553 Lisp_Object old_print_level = Vprint_level;
|
|
1554 Lisp_Object old_inhibit_quit = Vinhibit_quit;
|
|
1555 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
1556 GCPRO3 (old_print_level, old_print_length, old_inhibit_quit);
|
|
1557
|
|
1558 if (gc_in_progress)
|
|
1559 stderr_out ("** gc-in-progress! Bad idea to print anything! **\n");
|
|
1560
|
|
1561 print_depth = 0;
|
|
1562 print_readably = 0;
|
|
1563 print_unbuffered++;
|
|
1564 /* Could use unwind-protect, but why bother? */
|
|
1565 if (debug_print_length > 0)
|
|
1566 Vprint_length = make_int (debug_print_length);
|
|
1567 if (debug_print_level > 0)
|
|
1568 Vprint_level = make_int (debug_print_level);
|
|
1569 print_internal (debug_print_obj, Qexternal_debugging_output, 1);
|
|
1570 Vinhibit_quit = old_inhibit_quit;
|
|
1571 Vprint_level = old_print_level;
|
|
1572 Vprint_length = old_print_length;
|
|
1573 print_depth = old_print_depth;
|
|
1574 print_readably = old_print_readably;
|
|
1575 print_unbuffered--;
|
|
1576 UNGCPRO;
|
|
1577 }
|
|
1578
|
|
1579 void debug_print (Lisp_Object debug_print_obj);
|
|
1580 void
|
|
1581 debug_print (Lisp_Object debug_print_obj)
|
|
1582 {
|
|
1583 debug_print_no_newline (debug_print_obj);
|
211
|
1584 stderr_out ("\r\n");
|
0
|
1585 fflush (stderr);
|
|
1586 }
|
|
1587
|
|
1588 /* Debugging kludge -- unbuffered */
|
|
1589 void
|
|
1590 debug_backtrace (void)
|
|
1591 {
|
|
1592 /* This function can GC */
|
|
1593 int old_print_readably = print_readably;
|
|
1594 int old_print_depth = print_depth;
|
|
1595 Lisp_Object old_print_length = Vprint_length;
|
|
1596 Lisp_Object old_print_level = Vprint_level;
|
|
1597 Lisp_Object old_inhibit_quit = Vinhibit_quit;
|
|
1598 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
1599 GCPRO3 (old_print_level, old_print_length, old_inhibit_quit);
|
|
1600
|
|
1601 if (gc_in_progress)
|
|
1602 stderr_out ("** gc-in-progress! Bad idea to print anything! **\n");
|
|
1603
|
|
1604 print_depth = 0;
|
|
1605 print_readably = 0;
|
|
1606 print_unbuffered++;
|
|
1607 /* Could use unwind-protect, but why bother? */
|
|
1608 if (debug_print_length > 0)
|
|
1609 Vprint_length = make_int (debug_print_length);
|
|
1610 if (debug_print_level > 0)
|
|
1611 Vprint_level = make_int (debug_print_level);
|
|
1612 Fbacktrace (Qexternal_debugging_output, Qt);
|
|
1613 stderr_out ("\n");
|
|
1614 fflush (stderr);
|
|
1615 Vinhibit_quit = old_inhibit_quit;
|
|
1616 Vprint_level = old_print_level;
|
|
1617 Vprint_length = old_print_length;
|
|
1618 print_depth = old_print_depth;
|
|
1619 print_readably = old_print_readably;
|
|
1620 print_unbuffered--;
|
|
1621 UNGCPRO;
|
|
1622 }
|
|
1623
|
|
1624 void
|
|
1625 debug_short_backtrace (int length)
|
|
1626 {
|
|
1627 int first = 1;
|
|
1628 struct backtrace *bt = backtrace_list;
|
|
1629 stderr_out (" [");
|
|
1630 fflush (stderr);
|
|
1631 while (length > 0 && bt)
|
|
1632 {
|
|
1633 if (!first)
|
|
1634 {
|
|
1635 stderr_out (", ");
|
|
1636 fflush (stderr);
|
|
1637 }
|
|
1638 if (COMPILED_FUNCTIONP (*bt->function))
|
|
1639 {
|
233
|
1640 #if defined(COMPILED_FUNCTION_ANNOTATION_HACK)
|
0
|
1641 Lisp_Object ann = Fcompiled_function_annotation (*bt->function);
|
233
|
1642 #else
|
|
1643 Lisp_Object ann = Qnil;
|
|
1644 #endif
|
0
|
1645 if (!NILP (ann))
|
|
1646 {
|
|
1647 stderr_out ("<compiled-function from ");
|
|
1648 fflush (stderr);
|
|
1649 debug_print_no_newline (ann);
|
|
1650 stderr_out (">");
|
|
1651 fflush (stderr);
|
|
1652 }
|
|
1653 else
|
|
1654 {
|
|
1655 stderr_out ("<compiled-function of unknown origin>");
|
|
1656 fflush (stderr);
|
|
1657 }
|
|
1658 }
|
|
1659 else
|
|
1660 debug_print_no_newline (*bt->function);
|
|
1661 first = 0;
|
|
1662 length--;
|
|
1663 bt = bt->next;
|
|
1664 }
|
|
1665 stderr_out ("]\n");
|
|
1666 fflush (stderr);
|
|
1667 }
|
|
1668
|
|
1669 #endif /* debugging kludge */
|
|
1670
|
|
1671
|
|
1672 void
|
|
1673 syms_of_print (void)
|
|
1674 {
|
|
1675 defsymbol (&Qprint_escape_newlines, "print-escape-newlines");
|
|
1676 defsymbol (&Qprint_readably, "print-readably");
|
|
1677
|
|
1678 defsymbol (&Qstandard_output, "standard-output");
|
|
1679
|
|
1680 #ifdef LISP_FLOAT_TYPE
|
|
1681 defsymbol (&Qfloat_output_format, "float-output-format");
|
|
1682 #endif
|
|
1683
|
|
1684 defsymbol (&Qprint_length, "print-length");
|
|
1685
|
|
1686 defsymbol (&Qprint_string_length, "print-string-length");
|
171
|
1687
|
|
1688 defsymbol (&Qdisplay_error, "display-error");
|
|
1689 defsymbol (&Qprint_message_label, "print-message-label");
|
|
1690
|
20
|
1691 DEFSUBR (Fprin1);
|
|
1692 DEFSUBR (Fprin1_to_string);
|
|
1693 DEFSUBR (Fprinc);
|
|
1694 DEFSUBR (Fprint);
|
100
|
1695 DEFSUBR (Ferror_message_string);
|
171
|
1696 DEFSUBR (Fdisplay_error);
|
20
|
1697 DEFSUBR (Fterpri);
|
|
1698 DEFSUBR (Fwrite_char);
|
|
1699 DEFSUBR (Falternate_debugging_output);
|
0
|
1700 defsymbol (&Qalternate_debugging_output, "alternate-debugging-output");
|
20
|
1701 DEFSUBR (Fexternal_debugging_output);
|
|
1702 DEFSUBR (Fopen_termscript);
|
0
|
1703 defsymbol (&Qexternal_debugging_output, "external-debugging-output");
|
|
1704 #ifndef standalone
|
20
|
1705 DEFSUBR (Fwith_output_to_temp_buffer);
|
0
|
1706 #endif /* not standalone */
|
|
1707 }
|
|
1708
|
|
1709 void
|
|
1710 lstream_type_create_print (void)
|
|
1711 {
|
|
1712 LSTREAM_HAS_METHOD (print, writer);
|
|
1713 LSTREAM_HAS_METHOD (print, marker);
|
|
1714 }
|
|
1715
|
|
1716 void
|
|
1717 vars_of_print (void)
|
|
1718 {
|
|
1719 alternate_do_pointer = 0;
|
|
1720
|
|
1721 DEFVAR_LISP ("standard-output", &Vstandard_output /*
|
|
1722 Output stream `print' uses by default for outputting a character.
|
|
1723 This may be any function of one argument.
|
|
1724 It may also be a buffer (output is inserted before point)
|
|
1725 or a marker (output is inserted and the marker is advanced)
|
|
1726 or the symbol t (output appears in the minibuffer line).
|
|
1727 */ );
|
|
1728 Vstandard_output = Qt;
|
|
1729
|
|
1730 #ifdef LISP_FLOAT_TYPE
|
|
1731 DEFVAR_LISP ("float-output-format", &Vfloat_output_format /*
|
|
1732 The format descriptor string that lisp uses to print floats.
|
|
1733 This is a %-spec like those accepted by `printf' in C,
|
|
1734 but with some restrictions. It must start with the two characters `%.'.
|
|
1735 After that comes an integer precision specification,
|
|
1736 and then a letter which controls the format.
|
|
1737 The letters allowed are `e', `f' and `g'.
|
185
|
1738 Use `e' for exponential notation "DIG.DIGITSeEXPT"
|
|
1739 Use `f' for decimal point notation "DIGITS.DIGITS".
|
0
|
1740 Use `g' to choose the shorter of those two formats for the number at hand.
|
|
1741 The precision in any of these cases is the number of digits following
|
|
1742 the decimal point. With `f', a precision of 0 means to omit the
|
|
1743 decimal point. 0 is not allowed with `f' or `g'.
|
|
1744
|
|
1745 A value of nil means to use `%.16g'.
|
|
1746
|
|
1747 Regardless of the value of `float-output-format', a floating point number
|
|
1748 will never be printed in such a way that it is ambiguous with an integer;
|
|
1749 that is, a floating-point number will always be printed with a decimal
|
|
1750 point and/or an exponent, even if the digits following the decimal point
|
|
1751 are all zero. This is to preserve read-equivalence.
|
|
1752 */ );
|
|
1753 Vfloat_output_format = Qnil;
|
|
1754 #endif /* LISP_FLOAT_TYPE */
|
|
1755
|
|
1756 DEFVAR_LISP ("print-length", &Vprint_length /*
|
|
1757 Maximum length of list or vector to print before abbreviating.
|
|
1758 A value of nil means no limit.
|
|
1759 */ );
|
|
1760 Vprint_length = Qnil;
|
|
1761
|
|
1762 DEFVAR_LISP ("print-string-length", &Vprint_string_length /*
|
|
1763 Maximum length of string to print before abbreviating.
|
|
1764 A value of nil means no limit.
|
|
1765 */ );
|
|
1766 Vprint_string_length = Qnil;
|
|
1767
|
|
1768 DEFVAR_LISP ("print-level", &Vprint_level /*
|
|
1769 Maximum depth of list nesting to print before abbreviating.
|
|
1770 A value of nil means no limit.
|
|
1771 */ );
|
|
1772 Vprint_level = Qnil;
|
|
1773
|
|
1774 DEFVAR_BOOL ("print-escape-newlines", &print_escape_newlines /*
|
|
1775 Non-nil means print newlines in strings as backslash-n.
|
|
1776 */ );
|
|
1777 print_escape_newlines = 0;
|
|
1778
|
|
1779 DEFVAR_BOOL ("print-readably", &print_readably /*
|
|
1780 If non-nil, then all objects will be printed in a readable form.
|
|
1781 If an object has no readable representation, then an error is signalled.
|
|
1782 When print-readably is true, compiled-function objects will be written in
|
|
1783 #[...] form instead of in #<compiled-function [...]> form, and two-element
|
|
1784 lists of the form (quote object) will be written as the equivalent 'object.
|
|
1785 Do not SET this variable; bind it instead.
|
|
1786 */ );
|
|
1787 print_readably = 0;
|
|
1788
|
245
|
1789 /* #### I think this should default to t. But we'd better wait
|
|
1790 until we see that it works out. */
|
|
1791 DEFVAR_LISP ("print-gensym", &Vprint_gensym /*
|
0
|
1792 If non-nil, then uninterned symbols will be printed specially.
|
|
1793 Uninterned symbols are those which are not present in `obarray', that is,
|
|
1794 those which were made with `make-symbol' or by calling `intern' with a
|
|
1795 second argument.
|
|
1796
|
245
|
1797 When print-gensym is true, such symbols will be preceded by "#:",
|
|
1798 which causes the reader to create a new symbol instead of interning
|
|
1799 and returning an existing one. Beware: the #: syntax creates a new
|
|
1800 symbol each time it is seen, so if you print an object which contains
|
|
1801 two pointers to the same uninterned symbol, `read' will not duplicate
|
|
1802 that structure.
|
0
|
1803
|
245
|
1804 If the value of `print-gensym' is a cons cell, then in addition
|
|
1805 refrain from clearing `print-gensym-alist' on entry to and exit from
|
|
1806 printing functions, so that the use of #...# and #...= can carry over
|
|
1807 for several separately printed objects.
|
0
|
1808 */ );
|
245
|
1809 Vprint_gensym = Qnil;
|
|
1810
|
|
1811 DEFVAR_LISP ("print-gensym-alist", &Vprint_gensym_alist /*
|
|
1812 Association list of elements (GENSYM . N) to guide use of #N# and #N=.
|
|
1813 In each element, GENSYM is an uninterned symbol that has been associated
|
|
1814 with #N= for the specified value of N.
|
|
1815 */ );
|
|
1816 Vprint_gensym_alist = Qnil;
|
0
|
1817
|
|
1818 DEFVAR_LISP ("print-message-label", &Vprint_message_label /*
|
|
1819 Label for minibuffer messages created with `print'. This should
|
|
1820 generally be bound with `let' rather than set. (See `display-message'.)
|
|
1821 */ );
|
|
1822 Vprint_message_label = Qprint;
|
|
1823
|
219
|
1824 Vprin1_to_string_stream = Qnil;
|
|
1825 staticpro (&Vprin1_to_string_stream);
|
0
|
1826 }
|