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