summaryrefslogtreecommitdiff
path: root/src/print.c
diff options
context:
space:
mode:
authorYuan Fu <casouri@gmail.com>2022-05-07 01:57:39 -0700
committerYuan Fu <casouri@gmail.com>2022-05-07 01:57:39 -0700
commit82d5e902af68695481b8809e511a7913ef9a75aa (patch)
treee6a366278590e8906a9282d04e48de2061b6fe3f /src/print.c
parent84847cad82e3b667c82f411627cd58d236f55e84 (diff)
parent293a97d61e1977440f96b7fc91f281a06250ea72 (diff)
downloademacs-82d5e902af68695481b8809e511a7913ef9a75aa.tar.gz
; Merge from master.
Diffstat (limited to 'src/print.c')
-rw-r--r--src/print.c59
1 files changed, 44 insertions, 15 deletions
diff --git a/src/print.c b/src/print.c
index ab3047dee52..d8b8513f311 100644
--- a/src/print.c
+++ b/src/print.c
@@ -772,6 +772,16 @@ is used instead. */)
return object;
}
+DEFUN ("flush-standard-output", Fflush_standard_output, Sflush_standard_output,
+ 0, 0, 0,
+ doc: /* Flush standard-output.
+This can be useful after using `princ' and the like in scripts. */)
+ (void)
+{
+ fflush (stdout);
+ return Qnil;
+}
+
DEFUN ("external-debugging-output", Fexternal_debugging_output, Sexternal_debugging_output, 1, 1, 0,
doc: /* Write CHARACTER to stderr.
You can call `print' while debugging emacs, and pass it this function
@@ -948,7 +958,14 @@ print_error_message (Lisp_Object data, Lisp_Object stream, const char *context,
errmsg = Fget (errname, Qerror_message);
/* During loadup 'substitute-command-keys' might not be available. */
if (!NILP (Ffboundp (Qsubstitute_command_keys)))
- errmsg = call1 (Qsubstitute_command_keys, errmsg);
+ {
+ /* `substitute-command-keys' may bug out, which would lead
+ to infinite recursion when we're called from
+ skip_debugger, so ignore errors. */
+ Lisp_Object subs = safe_call1 (Qsubstitute_command_keys, errmsg);
+ if (!NILP (subs))
+ errmsg = subs;
+ }
file_error = Fmemq (Qfile_error, error_conditions);
}
@@ -1695,10 +1712,10 @@ print_vectorlike (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag,
case PVEC_USER_PTR:
{
+ void *finalizer = XUSER_PTR (obj)->finalizer;
print_c_string ("#<user-ptr ", printcharfun);
int i = sprintf (buf, "ptr=%p finalizer=%p",
- XUSER_PTR (obj)->p,
- XUSER_PTR (obj)->finalizer);
+ XUSER_PTR (obj)->p, finalizer);
strout (buf, i, i, printcharfun);
printchar ('>', printcharfun);
}
@@ -1869,7 +1886,8 @@ print_vectorlike (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag,
print_string (XTHREAD (obj)->name, printcharfun);
else
{
- int len = sprintf (buf, "%p", XTHREAD (obj));
+ void *p = XTHREAD (obj);
+ int len = sprintf (buf, "%p", p);
strout (buf, len, len, printcharfun);
}
printchar ('>', printcharfun);
@@ -1881,7 +1899,8 @@ print_vectorlike (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag,
print_string (XMUTEX (obj)->name, printcharfun);
else
{
- int len = sprintf (buf, "%p", XMUTEX (obj));
+ void *p = XMUTEX (obj);
+ int len = sprintf (buf, "%p", p);
strout (buf, len, len, printcharfun);
}
printchar ('>', printcharfun);
@@ -1893,7 +1912,8 @@ print_vectorlike (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag,
print_string (XCONDVAR (obj)->name, printcharfun);
else
{
- int len = sprintf (buf, "%p", XCONDVAR (obj));
+ void *p = XCONDVAR (obj);
+ int len = sprintf (buf, "%p", p);
strout (buf, len, len, printcharfun);
}
printchar ('>', printcharfun);
@@ -2088,8 +2108,10 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
}
else
{
- int len = sprintf (buf, "%"pI"d", i);
- strout (buf, len, len, printcharfun);
+ char *end = buf + sizeof buf;
+ char *start = fixnum_to_string (i, buf, end);
+ ptrdiff_t len = end - start;
+ strout (start, len, len, printcharfun);
}
}
break;
@@ -2199,14 +2221,19 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
Lisp_Object name = SYMBOL_NAME (obj);
ptrdiff_t size_byte = SBYTES (name);
- /* Set CONFUSING if NAME looks like a number, calling
- string_to_number for non-obvious cases. */
char *p = SSDATA (name);
bool signedp = *p == '-' || *p == '+';
ptrdiff_t len;
- bool confusing = ((c_isdigit (p[signedp]) || p[signedp] == '.')
- && !NILP (string_to_number (p, 10, &len))
- && len == size_byte);
+ bool confusing =
+ /* Set CONFUSING if NAME looks like a number, calling
+ string_to_number for non-obvious cases. */
+ ((c_isdigit (p[signedp]) || p[signedp] == '.')
+ && !NILP (string_to_number (p, 10, &len))
+ && len == size_byte)
+ /* We don't escape "." or "?" (unless they're the first
+ character in the symbol name). */
+ || *p == '?'
+ || *p == '.';
if (! NILP (Vprint_gensym)
&& !SYMBOL_INTERNED_IN_INITIAL_OBARRAY_P (obj))
@@ -2229,8 +2256,8 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
{
if (c == '\"' || c == '\\' || c == '\''
|| c == ';' || c == '#' || c == '(' || c == ')'
- || c == ',' || c == '.' || c == '`'
- || c == '[' || c == ']' || c == '?' || c <= 040
+ || c == ',' || c == '`'
+ || c == '[' || c == ']' || c <= 040
|| c == NO_BREAK_SPACE
|| confusing)
{
@@ -2570,4 +2597,6 @@ printed. If the function returns anything else, the object will not
be printed. */);
Vprint_unreadable_function = Qnil;
DEFSYM (Qprint_unreadable_function, "print-unreadable-function");
+
+ defsubr (&Sflush_standard_output);
}