From: Lars Ingebrigtsen Date: Sun, 17 Apr 2022 12:04:34 +0000 (+0200) Subject: Add new function `flush-standard-output'. X-Git-Tag: emacs-29.0.90~1931^2~462 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=2136db067f4292d84553ebfddab30d88b862262e;p=emacs.git Add new function `flush-standard-output'. * doc/lispref/streams.texi (Output Functions): Document it. * src/print.c (Fflush_standard_output): New function (bug#15180). --- diff --git a/doc/lispref/streams.texi b/doc/lispref/streams.texi index 8f8562cadc8..781a50f5c49 100644 --- a/doc/lispref/streams.texi +++ b/doc/lispref/streams.texi @@ -685,6 +685,15 @@ This function outputs @var{character} to @var{stream}. It returns @var{character}. @end defun +@defun flush-standard-output +If you have Emacs-based batch scripts that send output to the +terminal, Emacs will automatically display the output whenever you +write a newline characters to @code{standard-output}. This function +allows you to flush to @code{standard-output} without sending a +newline character first, which enables you to display incomplete +lines. +@end defun + @defun prin1-to-string object &optional noescape @cindex object to string This function returns a string containing the text that @code{prin1} diff --git a/etc/NEWS b/etc/NEWS index 071fdd7aee9..3821dac1798 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1423,6 +1423,11 @@ functions. * Lisp Changes in Emacs 29.1 ++++ +** New function 'flush-standard-output'. +This enables you do display incomplete lines from batch-based Emacs +scripts. + +++ ** New convenience function 'buttonize-region'. This works like 'buttonize', but for a region instead of a string. diff --git a/src/print.c b/src/print.c index 4a68d15fe02..baf515047b4 100644 --- a/src/print.c +++ b/src/print.c @@ -768,6 +768,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 @@ -2549,4 +2559,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); }