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