/* Lisp object printing and output streams.
- Copyright (C) 1985, 86, 88, 93, 94, 95, 97, 98, 1999, 2000, 2001
+ Copyright (C) 1985, 86, 88, 93, 94, 95, 97, 98, 1999, 2000, 01, 2003
Free Software Foundation, Inc.
This file is part of GNU Emacs.
#include "window.h"
#include "process.h"
#include "dispextern.h"
+#include "systty.h" /* For emacs_tty in termchar.h */
#include "termchar.h"
#include "intervals.h"
/* Avoid actual stack overflow in print. */
int print_depth;
+/* Nonzero if inside outputting backquote in old style. */
+int old_backquote_output;
+
/* Detect most circularities to print finite output. */
#define PRINT_CIRCLE 200
Lisp_Object being_printed[PRINT_CIRCLE];
and must start with PRINTPREPARE, end with PRINTFINISH,
and use PRINTDECLARE to declare common variables.
Use PRINTCHAR to output one character,
- or call strout to output a block of characters. */
+ or call strout to output a block of characters. */
#define PRINTDECLARE \
struct buffer *old = current_buffer; \
int len = CHAR_STRING (ch, str);
QUIT;
-
+
if (NILP (fun))
{
if (print_buffer_pos_byte + len >= print_buffer_size)
{
int multibyte_p
= !NILP (current_buffer->enable_multibyte_characters);
-
+
setup_echo_area_for_printing (multibyte_p);
insert_char (ch);
message_dolog (str, len, 0, multibyte_p);
int i;
int multibyte_p
= !NILP (current_buffer->enable_multibyte_characters);
-
+
setup_echo_area_for_printing (multibyte_p);
message_dolog (ptr, size_byte, 0, multibyte_p);
-
+
if (size == size_byte)
{
for (i = 0; i < size; ++i)
insert_char (ch);
}
}
-
+
#ifdef MAX_PRINT_CHARS
if (max_print)
print_chars += size;
for (i = 0; i < size; i++)
PRINTCHAR (SREF (string, i));
else
- for (i = 0; i < size_byte; i++)
+ for (i = 0; i < size_byte; )
{
/* Here, we must convert each multi-byte form to the
corresponding character code before handing it to PRINTCHAR. */
Fset_buffer (Fget_buffer_create (build_string (bufname)));
Fkill_all_local_variables ();
+ delete_all_overlays (current_buffer);
current_buffer->directory = old->directory;
current_buffer->read_only = Qnil;
current_buffer->filename = Qnil;
current_buffer->undo_list = Qt;
- current_buffer->overlays_before = Qnil;
- current_buffer->overlays_after = Qnil;
+ eassert (current_buffer->overlays_before == NULL);
+ eassert (current_buffer->overlays_after == NULL);
current_buffer->enable_multibyte_characters
= buffer_defaults.enable_multibyte_characters;
Ferase_buffer ();
If variable `temp-buffer-show-function' is non-nil, call it at the end
to get the buffer displayed instead of just displaying the non-selected
-buffer and calling the hook. It gets one argument, the buffer to display.
+buffer and calling the hook. It gets one argument, the buffer to display.
usage: (with-output-to-temp-buffer BUFFNAME BODY ...) */)
(args)
(object, noescape)
Lisp_Object object, noescape;
{
- PRINTDECLARE;
Lisp_Object printcharfun;
- struct gcpro gcpro1, gcpro2;
- Lisp_Object tem;
+ /* struct gcpro gcpro1, gcpro2; */
+ Lisp_Object save_deactivate_mark;
+ int count = specpdl_ptr - specpdl;
+ struct buffer *previous;
- /* Save and restore this--we are altering a buffer
- but we don't want to deactivate the mark just for that.
- No need for specbind, since errors deactivate the mark. */
- tem = Vdeactivate_mark;
- GCPRO2 (object, tem);
+ specbind (Qinhibit_modification_hooks, Qt);
- printcharfun = Vprin1_to_string_buffer;
- PRINTPREPARE;
- print (object, printcharfun, NILP (noescape));
- /* Make Vprin1_to_string_buffer be the default buffer after PRINTFINSH */
- PRINTFINISH;
+ {
+ PRINTDECLARE;
+
+ /* Save and restore this--we are altering a buffer
+ but we don't want to deactivate the mark just for that.
+ No need for specbind, since errors deactivate the mark. */
+ save_deactivate_mark = Vdeactivate_mark;
+ /* GCPRO2 (object, save_deactivate_mark); */
+ abort_on_gc++;
+
+ printcharfun = Vprin1_to_string_buffer;
+ PRINTPREPARE;
+ print (object, printcharfun, NILP (noescape));
+ /* Make Vprin1_to_string_buffer be the default buffer after PRINTFINSH */
+ PRINTFINISH;
+ }
+
+ previous = current_buffer;
set_buffer_internal (XBUFFER (Vprin1_to_string_buffer));
object = Fbuffer_string ();
+ if (SBYTES (object) == SCHARS (object))
+ STRING_SET_UNIBYTE (object);
+ /* Note that this won't make prepare_to_modify_buffer call
+ ask-user-about-supersession-threat because this buffer
+ does not visit a file. */
Ferase_buffer ();
- set_buffer_internal (old);
+ set_buffer_internal (previous);
- Vdeactivate_mark = tem;
- UNGCPRO;
+ Vdeactivate_mark = save_deactivate_mark;
+ /* UNGCPRO; */
- return object;
+ abort_on_gc--;
+ return unbind_to (count, object);
}
DEFUN ("princ", Fprinc, Sprinc, 1, 2, 0,
return character;
}
+
+#if defined(GNU_LINUX)
+
+/* This functionality is not vitally important in general, so we rely on
+ non-portable ability to use stderr as lvalue. */
+
+#define WITH_REDIRECT_DEBUGGING_OUTPUT 1
+
+FILE *initial_stderr_stream = NULL;
+
+DEFUN ("redirect-debugging-output", Fredirect_debugging_output, Sredirect_debugging_output,
+ 1, 2,
+ "FDebug output file: \nP",
+ doc: /* Redirect debugging output (stderr stream) to file FILE.
+If FILE is nil, reset target to the initial stderr stream.
+Optional arg APPEND non-nil (interactively, with prefix arg) means
+append to existing target file. */)
+ (file, append)
+ Lisp_Object file, append;
+{
+ if (initial_stderr_stream != NULL)
+ fclose(stderr);
+ stderr = initial_stderr_stream;
+ initial_stderr_stream = NULL;
+
+ if (STRINGP (file))
+ {
+ file = Fexpand_file_name (file, Qnil);
+ initial_stderr_stream = stderr;
+ stderr = fopen(SDATA (file), NILP (append) ? "w" : "a");
+ if (stderr == NULL)
+ {
+ stderr = initial_stderr_stream;
+ initial_stderr_stream = NULL;
+ report_file_error ("Cannot open debugging output stream",
+ Fcons (file, Qnil));
+ }
+ }
+ return Qnil;
+}
+#endif /* GNU_LINUX */
+
+
/* This is the interface for debugging printing. */
void
\f
DEFUN ("error-message-string", Ferror_message_string, Serror_message_string,
1, 1, 0,
- doc: /* Convert an error value (ERROR-SYMBOL . DATA) to an error message. */)
+ doc: /* Convert an error value (ERROR-SYMBOL . DATA) to an error message.
+See Info anchor `(elisp)Definition of signal' for some details on how this
+error message is constructed. */)
(obj)
Lisp_Object obj;
{
&& NILP (XCDR (XCDR (obj))))
return XCAR (XCDR (obj));
- print_error_message (obj, Vprin1_to_string_buffer);
+ print_error_message (obj, Vprin1_to_string_buffer, 0, Qnil);
set_buffer_internal (XBUFFER (Vprin1_to_string_buffer));
value = Fbuffer_string ();
STREAM (suitable for the print functions). */
void
-print_error_message (data, stream)
+print_error_message (data, stream, context, caller)
Lisp_Object data, stream;
+ char *context;
+ Lisp_Object caller;
{
Lisp_Object errname, errmsg, file_error, tail;
struct gcpro gcpro1;
int i;
+ if (context != 0)
+ write_string_1 (context, -1, stream);
+
+ /* If we know from where the error was signaled, show it in
+ *Messages*. */
+ if (!NILP (caller) && SYMBOLP (caller))
+ {
+ const char *name = SDATA (SYMBOL_NAME (caller));
+ message_dolog (name, strlen (name), 0, 0);
+ message_dolog (": ", 2, 0, 0);
+ }
+
errname = Fcar (data);
if (EQ (errname, Qerror))
else
Fprin1 (obj, stream);
}
-
+
UNGCPRO;
}
* largest float, printed in the biggest notation. This is undoubtedly
* 20d float_output_format, with the negative of the C-constant "HUGE"
* from <math.h>.
- *
+ *
* On the vax the worst case is -1e38 in 20d format which takes 61 bytes.
- *
+ *
* I assume that IEEE-754 format numbers can take 329 bytes for the worst
* case of -1e307 in 20d float_output_format. What is one to do (short of
* re-writing _doprnt to be more sane)?
{
unsigned char *cp;
int width;
-
+
/* Check for plus infinity in a way that won't lose
if there is no plus infinity. */
if (data == data / 2 && data > 1.0)
*buf++ = '-';
break;
}
-
+
strcpy (buf, "0.0e+NaN");
return;
}
int escapeflag;
{
print_depth = 0;
+ old_backquote_output = 0;
/* Reset print_number_index and Vprint_number_table only when
the variable Vprint_continuous_numbering is nil. Otherwise,
if (!NILP (Vprint_gensym) || !NILP (Vprint_circle))
{
int i, start, index;
- /* Construct Vprint_number_table. */
start = index = print_number_index;
+ /* Construct Vprint_number_table.
+ This increments print_number_index for the objects added. */
print_preprocess (obj);
+
/* Remove unnecessary objects, which appear only once in OBJ;
- that is, whose status is Qnil. */
+ that is, whose status is Qnil. Compactify the necessary objects. */
for (i = start; i < print_number_index; i++)
if (!NILP (PRINT_NUMBER_STATUS (Vprint_number_table, i)))
{
PRINT_NUMBER_OBJECT (Vprint_number_table, index)
= PRINT_NUMBER_OBJECT (Vprint_number_table, i);
- /* Reset the status field for the next print step. Now this
- field means whether the object has already been printed. */
- PRINT_NUMBER_STATUS (Vprint_number_table, index) = Qnil;
index++;
}
+
+ /* Clear out objects outside the active part of the table. */
+ for (i = index; i < print_number_index; i++)
+ PRINT_NUMBER_OBJECT (Vprint_number_table, i) = Qnil;
+
+ /* Reset the status field for the next print step. Now this
+ field means whether the object has already been printed. */
+ for (i = start; i < print_number_index; i++)
+ PRINT_NUMBER_STATUS (Vprint_number_table, i) = Qnil;
+
print_number_index = index;
}
print_object (XCAR (XCDR (obj)), printcharfun, escapeflag);
}
else if (print_quoted && CONSP (XCDR (obj)) && NILP (XCDR (XCDR (obj)))
+ && ! old_backquote_output
&& ((EQ (XCAR (obj), Qbackquote)
|| EQ (XCAR (obj), Qcomma)
|| EQ (XCAR (obj), Qcomma_at)
else
{
PRINTCHAR ('(');
+
+ /* If the first element is a backquote form,
+ print it old-style so it won't be misunderstood. */
+ if (print_quoted && CONSP (XCAR (obj))
+ && CONSP (XCDR (XCAR (obj)))
+ && NILP (XCDR (XCDR (XCAR (obj))))
+ && EQ (XCAR (XCAR (obj)), Qbackquote))
+ {
+ Lisp_Object tem;
+ tem = XCAR (obj);
+ PRINTCHAR ('(');
+
+ print_object (Qbackquote, printcharfun, 0);
+ PRINTCHAR (' ');
+
+ ++old_backquote_output;
+ print_object (XCAR (XCDR (tem)), printcharfun, 0);
+ --old_backquote_output;
+ PRINTCHAR (')');
+
+ obj = XCDR (obj);
+ }
+
{
int print_length, i;
Lisp_Object halftail = obj;
}
}
}
-
+
if (i++)
PRINTCHAR (' ');
-
+
if (print_length && i > print_length)
{
strout ("...", 3, 3, printcharfun, 0);
goto end_of_list;
}
-
+
print_object (XCAR (obj), printcharfun, escapeflag);
-
+
obj = XCDR (obj);
if (!(i & 1))
halftail = XCDR (halftail);
strout (" . ", 3, 3, printcharfun, 0);
print_object (obj, printcharfun, escapeflag);
}
-
+
end_of_list:
PRINTCHAR (')');
}
DEFVAR_BOOL ("print-escape-nonascii", &print_escape_nonascii,
doc: /* Non-nil means print unibyte non-ASCII chars in strings as \\OOO.
\(OOO is the octal representation of the character code.)
-Only single-byte characters are affected, and only in `prin1'. */);
+Only single-byte characters are affected, and only in `prin1'.
+When the output goes in a multibyte buffer, this feature is
+enabled regardless of the value of the variable. */);
print_escape_nonascii = 0;
DEFVAR_BOOL ("print-escape-multibyte", &print_escape_multibyte,
DEFVAR_LISP ("print-number-table", &Vprint_number_table,
doc: /* A vector used internally to produce `#N=' labels and `#N#' references.
The Lisp printer uses this vector to detect Lisp objects referenced more
-than once. When `print-continuous-numbering' is bound to t, you should
-probably also bind `print-number-table' to nil. This ensures that the
-value of `print-number-table' can be garbage-collected once the printing
-is done. */);
+than once.
+
+When you bind `print-continuous-numbering' to t, you should probably
+also bind `print-number-table' to nil. This ensures that the value of
+`print-number-table' can be garbage-collected once the printing is
+done. If all elements of `print-number-table' are nil, it means that
+the printing done so far has not found any shared structure or objects
+that need to be recorded in the table. */);
Vprint_number_table = Qnil;
/* prin1_to_string_buffer initialized in init_buffer_once in buffer.c */
defsubr (&Sterpri);
defsubr (&Swrite_char);
defsubr (&Sexternal_debugging_output);
+#ifdef WITH_REDIRECT_DEBUGGING_OUTPUT
+ defsubr (&Sredirect_debugging_output);
+#endif
Qexternal_debugging_output = intern ("external-debugging-output");
staticpro (&Qexternal_debugging_output);
defsubr (&Swith_output_to_temp_buffer);
}
+
+/* arch-tag: bc797170-94ae-41de-86e3-75e20f8f7a39
+ (do not change this comment) */