unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: phillip.lord@russet.org.uk (Phillip Lord)
To: emacs-devel@gnu.org
Subject: Adding streams for standard out and standard err
Date: Wed, 20 Jul 2016 23:48:43 +0100	[thread overview]
Message-ID: <87oa5sexis.fsf@russet.org.uk> (raw)

[-- Attachment #1: Type: text/plain, Size: 225 bytes --]


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...


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-streams-for-stdout-stderr.patch --]
[-- Type: text/x-diff, Size: 2643 bytes --]

From eac3394997a122d57f90bea2ca850ac609104840 Mon Sep 17 00:00:00 2001
From: Phillip Lord <phillip.lord@russet.org.uk>
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


             reply	other threads:[~2016-07-20 22:48 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-20 22:48 Phillip Lord [this message]
2016-07-21  7:12 ` Adding streams for standard out and standard err Andreas Schwab
2016-07-21 18:42   ` Phillip Lord
2016-07-25  7:35     ` Andreas Schwab
2016-07-21 14:21 ` Eli Zaretskii
2016-07-21 14:40   ` Paul Eggert
2016-07-21 15:02     ` Eli Zaretskii
2016-07-21 19:01       ` Phillip Lord
2016-07-21 18:52   ` Phillip Lord
2016-07-21 19:11     ` Eli Zaretskii
2016-07-21 20:13       ` Phillip Lord
2016-07-22  6:50         ` Eli Zaretskii
2016-07-22 15:43           ` Phillip Lord
2016-07-21 22:15     ` Davis Herring
2016-08-02 23:35   ` John Wiegley
2016-07-22 14:48 ` Phil Sainty
2016-07-22 15:42   ` Phillip Lord

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87oa5sexis.fsf@russet.org.uk \
    --to=phillip.lord@russet.org.uk \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).