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