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