/* 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, 03, 2004
Free Software Foundation, Inc.
This file is part of GNU Emacs.
/* 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;
+ specbind (Qinhibit_read_only, Qt);
+ specbind (Qinhibit_modification_hooks, Qt);
Ferase_buffer ();
XSETBUFFER (buf, current_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 ...) */)
+usage: (with-output-to-temp-buffer BUFNAME BODY ...) */)
(args)
Lisp_Object 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;
{
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;
}
register Lisp_Object printcharfun;
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,
start = index = print_number_index;
/* Construct Vprint_number_table.
This increments print_number_index for the objects added. */
+ print_depth = 0;
print_preprocess (obj);
/* Remove unnecessary objects, which appear only once in OBJ;
print_number_index = index;
}
+ print_depth = 0;
print_object (obj, printcharfun, escapeflag);
}
print_preprocess (obj)
Lisp_Object obj;
{
- int i, size;
+ int i;
+ EMACS_INT size;
+ int loop_count = 0;
+ Lisp_Object halftail;
+
+ /* Give up if we go so deep that print_object will get an error. */
+ /* See similar code in print_object. */
+ if (print_depth >= PRINT_CIRCLE)
+ return;
+
+ /* Avoid infinite recursion for circular nested structure
+ in the case where Vprint_circle is nil. */
+ if (NILP (Vprint_circle))
+ {
+ for (i = 0; i < print_depth; i++)
+ if (EQ (obj, being_printed[i]))
+ return;
+ being_printed[print_depth] = obj;
+ }
+
+ print_depth++;
+ halftail = obj;
loop:
if (STRINGP (obj) || CONSP (obj) || VECTORP (obj)
break;
case Lisp_Cons:
+ /* Use HALFTAIL and LOOP_COUNT to detect circular lists,
+ just as in print_object. */
+ if (loop_count && EQ (obj, halftail))
+ break;
print_preprocess (XCAR (obj));
obj = XCDR (obj);
+ loop_count++;
+ if (!(loop_count & 1))
+ halftail = XCDR (halftail);
goto loop;
case Lisp_Vectorlike:
- size = XVECTOR (obj)->size & PSEUDOVECTOR_SIZE_MASK;
+ size = XVECTOR (obj)->size;
+ if (size & PSEUDOVECTOR_FLAG)
+ size &= PSEUDOVECTOR_SIZE_MASK;
for (i = 0; i < size; i++)
print_preprocess (XVECTOR (obj)->contents[i]);
break;
break;
}
}
+ print_depth--;
}
static void
register Lisp_Object printcharfun;
int escapeflag;
{
- char buf[30];
+ char buf[40];
QUIT;
print_depth++;
+ /* See similar code in print_preprocess. */
if (print_depth > PRINT_CIRCLE)
error ("Apparently circular structure being printed");
#ifdef MAX_PRINT_CHARS
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 (')');
}
register unsigned char c;
struct gcpro gcpro1;
int size_in_chars
- = (XBOOL_VECTOR (obj)->size + BITS_PER_CHAR - 1) / BITS_PER_CHAR;
+ = ((XBOOL_VECTOR (obj)->size + BOOL_VECTOR_BITS_PER_CHAR - 1)
+ / BOOL_VECTOR_BITS_PER_CHAR);
GCPRO1 (obj);
PRINTCHAR ('#');
PRINTCHAR ('&');
- sprintf (buf, "%d", XBOOL_VECTOR (obj)->size);
+ sprintf (buf, "%ld", (long) XBOOL_VECTOR (obj)->size);
strout (buf, -1, -1, printcharfun, 0);
PRINTCHAR ('\"');
PRINTCHAR ('\\');
PRINTCHAR ('f');
}
+ else if (c > '\177')
+ {
+ /* Use octal escapes to avoid encoding issues. */
+ PRINTCHAR ('\\');
+ PRINTCHAR ('0' + ((c >> 6) & 3));
+ PRINTCHAR ('0' + ((c >> 3) & 7));
+ PRINTCHAR ('0' + (c & 7));
+ }
else
{
if (c == '\"' || c == '\\')
else if (WINDOWP (obj))
{
strout ("#<window ", -1, -1, printcharfun, 0);
- sprintf (buf, "%d", XFASTINT (XWINDOW (obj)->sequence_number));
+ sprintf (buf, "%ld", (long) XFASTINT (XWINDOW (obj)->sequence_number));
strout (buf, -1, -1, printcharfun, 0);
if (!NILP (XWINDOW (obj)->buffer))
{
PRINTCHAR (' ');
strout (SDATA (SYMBOL_NAME (h->weak)), -1, -1, printcharfun, 0);
PRINTCHAR (' ');
- sprintf (buf, "%d/%d", XFASTINT (h->count),
- XVECTOR (h->next)->size);
+ sprintf (buf, "%ld/%ld", (long) XFASTINT (h->count),
+ (long) XVECTOR (h->next)->size);
strout (buf, -1, -1, printcharfun, 0);
}
sprintf (buf, " 0x%lx", (unsigned long) h);
}
else
{
- int size = XVECTOR (obj)->size;
+ EMACS_INT size = XVECTOR (obj)->size;
if (COMPILEDP (obj))
{
PRINTCHAR ('#');
break;
case Lisp_Misc_Intfwd:
- sprintf (buf, "#<intfwd to %d>", *XINTFWD (obj)->intvar);
+ sprintf (buf, "#<intfwd to %ld>", (long) *XINTFWD (obj)->intvar);
strout (buf, -1, -1, printcharfun, 0);
break;
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,
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) */