[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Adding streams for standard out and standard err

From: Phillip Lord
Subject: Adding streams for standard out and standard err
Date: Wed, 20 Jul 2016 23:48:43 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.95 (gnu/linux)

For a while I've wanted Emacs to have the ability to write to standard
out, and/or standard err, when not running in batch. Mostly, I've wanted
for debugging, as it involves touching no buffers at all.

Comments welcome...

>From eac3394997a122d57f90bea2ca850ac609104840 Mon Sep 17 00:00:00 2001
From: Phillip Lord <address@hidden>
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
address@hidden @asis
address@hidden @code{stdout} output stream
address@hidden @var{stdout}
+Prints to the system standard output (as opposed to the
address@hidden), regardless of whether Emacs is running
+interactively or not.
address@hidden @var{stderr} output stream
+Prints to the system standard error, regardless of whether Emacs is
+running interactively or not.
address@hidden 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);

reply via email to

[Prev in Thread] Current Thread [Next in Thread]