From eac3394997a122d57f90bea2ca850ac609104840 Mon Sep 17 00:00:00 2001 From: Phillip Lord Date: Mon, 18 Jul 2016 23:28:05 +0100 Subject: [PATCH] Add streams for stdout, stderr * src/print.c (Fstdout,Fstderr): New function --- doc/lispref/streams.texi | 21 +++++++++++++++++++++ src/print.c | 20 ++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/doc/lispref/streams.texi b/doc/lispref/streams.texi index 41bc71e..7d26c9f 100644 --- a/doc/lispref/streams.texi +++ b/doc/lispref/streams.texi @@ -530,6 +530,27 @@ Output Streams Calling @code{concat} converts the list to a string so you can see its contents more clearly. +Two functions which are specifically designed for use as output +streams: + +@table @asis +@cindex @code{stdout} output stream +@item @var{stdout} +Prints to the system standard output (as opposed to the +@var{standard-output}), regardless of whether Emacs is running +interactively or not. + +@item @var{stderr} output stream +Prints to the system standard error, regardless of whether Emacs is +running interactively or not. +@end table + +These functions are predominately useful for debugging, as they are a +mechanism for producing output that does not change any buffer. Note +that these functions do not flush their output; in general, no output +will be produced until a newline. + + @node Output Functions @section Output Functions diff --git a/src/print.c b/src/print.c index 5531210..f5a38c3 100644 --- a/src/print.c +++ b/src/print.c @@ -264,6 +264,24 @@ printchar_to_stream (unsigned int ch, FILE *stream) } } +DEFUN ("stdout", Fstdout, Sstdout, 1, 1, 0, + doc: /* Output character CHARACTER to system standard output. */) + (Lisp_Object character) +{ + CHECK_NUMBER (character); + printchar_to_stream (XINT(character), stdout); + return character; +} + +DEFUN ("stderr", Fstderr, Sstderr, 1, 1, 0, + doc: /* Output character CHARACTER to system standard error. */) + (Lisp_Object character) +{ + CHECK_NUMBER (character); + printchar_to_stream (XINT(character), stderr); + return character; +} + /* Print character CH using method FUN. FUN nil means print to print_buffer. FUN t means print to echo area or stdout if non-interactive. If FUN is neither nil nor t, call FUN with CH as @@ -2301,6 +2319,8 @@ priorities. */); /* prin1_to_string_buffer initialized in init_buffer_once in buffer.c */ staticpro (&Vprin1_to_string_buffer); + defsubr (&Sstdout); + defsubr (&Sstderr); defsubr (&Sprin1); defsubr (&Sprin1_to_string); defsubr (&Serror_message_string); -- 2.9.2