unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* standard output/error/input streams
@ 2017-01-14 12:22 Phillip Lord
  2017-01-14 14:03 ` Noam Postavsky
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Phillip Lord @ 2017-01-14 12:22 UTC (permalink / raw)
  To: emacs-devel



I've worked up the patch that I made to add input streams for writing to
the system standard out. There was some discussion about this in Jul.

https://lists.gnu.org/archive/html/emacs-devel/2016-07/msg00910.html

The new version is on feature/stdout-stderr-stream.

Additions since last time. I've updated the names
(external-standard-output, external-standard-error) and I have also
added an input stream (external-standard-input).

The main motivation for this is the same as last time; it gives a
communication channel with Emacs which does not involve buffers at any
point. Although, if you search for "Emacs" and "standard output", other
people would like the same thing for other reasons.

Can I add this to master?

Phil



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: standard output/error/input streams
  2017-01-14 12:22 standard output/error/input streams Phillip Lord
@ 2017-01-14 14:03 ` Noam Postavsky
  2017-01-14 14:31 ` Eli Zaretskii
  2017-01-19  7:21 ` John Wiegley
  2 siblings, 0 replies; 12+ messages in thread
From: Noam Postavsky @ 2017-01-14 14:03 UTC (permalink / raw)
  To: Phillip Lord; +Cc: Emacs developers

On Sat, Jan 14, 2017 at 7:22 AM, Phillip Lord
<phillip.lord@russet.org.uk> wrote:
>
>
> The new version is on feature/stdout-stderr-stream.

+DEFUN ("external-standard-error", Fexternal_standard_error,
Sexternal_standard_error, 1, 1, 0,
+       doc: /* Output character CHARACTER to system standard error. */)
+     (Lisp_Object character)
+{
+  return Fexternal_debugging_output (character);
+}

This could be just an alias instead, no?



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: standard output/error/input streams
  2017-01-14 12:22 standard output/error/input streams Phillip Lord
  2017-01-14 14:03 ` Noam Postavsky
@ 2017-01-14 14:31 ` Eli Zaretskii
  2017-01-14 17:51   ` Eli Zaretskii
  2017-01-19  7:21 ` John Wiegley
  2 siblings, 1 reply; 12+ messages in thread
From: Eli Zaretskii @ 2017-01-14 14:31 UTC (permalink / raw)
  To: Phillip Lord; +Cc: emacs-devel

> From: phillip.lord@russet.org.uk (Phillip Lord)
> Date: Sat, 14 Jan 2017 12:22:50 +0000
> 
> I've worked up the patch that I made to add input streams for writing to
> the system standard out. There was some discussion about this in Jul.
> 
> https://lists.gnu.org/archive/html/emacs-devel/2016-07/msg00910.html
> 
> The new version is on feature/stdout-stderr-stream.

Thanks.  Some of the concerns I expressed here:

  https://lists.gnu.org/archive/html/emacs-devel/2016-07/msg00938.html

are still relevant, and at the very least should be reflected in the
docs.

> Can I add this to master?

I think this still "needs work", see my comments below:

  +@cindex @code{external-standard-input}
  +@defun external-standard-input &optional char

No need to explicitly index a function that is introduced in a @defun:
the latter automatically adds an index entry.

  +This function reads a single character from the system standard input
  +(as opposed to @var{standard-input}) and functions as a stream. Note,

Two spaces between sentences, please (here and elsewhere).

  +however, that if Emacs is running in a terminal its use can be
  +unpredictable.

I think we should explain more about the issue here, so that the
reader understands what she is up against.  (I think this function
will simply not work on a TTY frame.)

  +These functions are predominately useful for debugging, as they are a
  +mechanism for producing output that does not change any buffer. Note,
  +however, that if Emacs is running in a terminal their use can affect
  +the display unpredictably.

Likewise here.  This should also mention the problems with
stdout/stderr disposition in GUI sessions.

  +(defvar external-standard-input-pushback nil
  +  "Pushback character for `external-standard-input'.")

Isn't this an internal variable?  If so, it should use double hyphen
in its name.  And what is the purpose of this pushback?  I didn't see
any code that sets it in patch.

  +DEFUN ("external-standard-input-read-char",Fexternal_standard_input_read_char, Sexternal_standard_input_read_char, 0, 0, 0,
  +       doc: /* Read a single character from the system standard input.
  +
  +Returns -1 if standard input is at the end.*/)
  +     (void)
  +{
  +  int c;
  +  Lisp_Object val;
  +
  +  c = getchar();
  +  XSETINT(val,c);
  +
  +  return val;
  +}

This implementation has a number of issues:

  . getchar reads a _byte_, not a character, so unless input is
    plain-ASCII, what you return here is a raw byte, not a character
    in the Emacs sense of that word.  That is inconsistent with every
    other input facility we have, and could very well get the user in
    trouble.

  . getchar doesn't return until you type RET, at least on my system,
    which might come as a surprise to users.

  . (nitpicking) our coding style keeps one space between the
    function/macro name and the opening parenthesis.  (Same issue
    exists elsewhere in the patch.)

  +DEFUN ("external-standard-input-read-line", Fexternal_standard_input_read_line, Sexternal_standard_input_read_line, 0, 0, 0,
  +      doc: /* Read a line from the system standard input.*/)

This function doesn't seem to be documented in the ELisp manual.

  +  if (len || c == '\n' || c == '\r')
  +    {
  +      val = make_string (line, len);
  +      xfree (line);

What about EOL decoding, as in all the other Emacs input functions?

Also, make_string has its own ideas about when to produce unibyte
strings and when multibyte strings.  You should instead decode the
input text using coding-system-for-read (if non-nil) or
locale-coding-system (or maybe what terminal-coding-system returns).

  +DEFUN ("external-standard-output", Fexternal_standard_output, Sexternal_standard_output, 1, 1, 0,
  +       doc: /* Output character CHARACTER to system standard output. */)
  +     (Lisp_Object character)
  +{
  +  CHECK_NUMBER (character);
  +  printchar_to_stream (XINT(character), stdout);

printchar_to_stream converts the output text via
standard-display-table, if that is non-nil; do we really want that for
functionality that is supposed to be a debugging aid?  It also sends
its argument to the debugger on MS-Windows -- is that desirable?



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: standard output/error/input streams
  2017-01-14 14:31 ` Eli Zaretskii
@ 2017-01-14 17:51   ` Eli Zaretskii
  0 siblings, 0 replies; 12+ messages in thread
From: Eli Zaretskii @ 2017-01-14 17:51 UTC (permalink / raw)
  To: phillip.lord; +Cc: emacs-devel

> Date: Sat, 14 Jan 2017 16:31:54 +0200
> From: Eli Zaretskii <eliz@gnu.org>
> Cc: emacs-devel@gnu.org
> 
>   . getchar doesn't return until you type RET, at least on my system,
>     which might come as a surprise to users.

One other problem with this is that until getchar returns, Emacs is
stuck, and nothing runs.  That's not a good thing, IMO, so I think the
implementation should go via wait_reading_process_output and stuff
(which will have a nice side effect of letting some other thread run
while Emacs waits for input).



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: standard output/error/input streams
  2017-01-14 12:22 standard output/error/input streams Phillip Lord
  2017-01-14 14:03 ` Noam Postavsky
  2017-01-14 14:31 ` Eli Zaretskii
@ 2017-01-19  7:21 ` John Wiegley
  2017-01-20 13:38   ` Phillip Lord
  2017-01-20 16:26   ` Stefan Monnier
  2 siblings, 2 replies; 12+ messages in thread
From: John Wiegley @ 2017-01-19  7:21 UTC (permalink / raw)
  To: Phillip Lord; +Cc: emacs-devel

>>>>> "PL" == Phillip Lord <phillip.lord@russet.org.uk> writes:

PL> The main motivation for this is the same as last time; it gives a
PL> communication channel with Emacs which does not involve buffers at any
PL> point. Although, if you search for "Emacs" and "standard output", other
PL> people would like the same thing for other reasons.

Have you thought of allowing files to be "opened" for direct writing as well?
That is, I'd rather see file handles become a new output stream type, with
stdout and stderr instances of these, than hard-coded streams for only stdout
and stderr. Although, getting cleanup right makes me less certain.

-- 
John Wiegley                  GPG fingerprint = 4710 CF98 AF9B 327B B80F
http://newartisans.com                          60E1 46C4 BD1A 7AC1 4BA2



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: standard output/error/input streams
  2017-01-19  7:21 ` John Wiegley
@ 2017-01-20 13:38   ` Phillip Lord
  2017-01-20 16:26   ` Stefan Monnier
  1 sibling, 0 replies; 12+ messages in thread
From: Phillip Lord @ 2017-01-20 13:38 UTC (permalink / raw)
  To: emacs-devel

John Wiegley <jwiegley@gmail.com> writes:

>>>>>> "PL" == Phillip Lord <phillip.lord@russet.org.uk> writes:
>
> PL> The main motivation for this is the same as last time; it gives a
> PL> communication channel with Emacs which does not involve buffers at any
> PL> point. Although, if you search for "Emacs" and "standard output", other
> PL> people would like the same thing for other reasons.
>
> Have you thought of allowing files to be "opened" for direct writing as well?
> That is, I'd rather see file handles become a new output stream type, with
> stdout and stderr instances of these, than hard-coded streams for only stdout
> and stderr. Although, getting cleanup right makes me less certain.

Yes, that would be nice I agree, although standard out gives me my main
use case, and there is already support for clean up.

I'll take a look next maybe.

Phil



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: standard output/error/input streams
  2017-01-19  7:21 ` John Wiegley
  2017-01-20 13:38   ` Phillip Lord
@ 2017-01-20 16:26   ` Stefan Monnier
  2017-01-20 21:24     ` John Wiegley
  1 sibling, 1 reply; 12+ messages in thread
From: Stefan Monnier @ 2017-01-20 16:26 UTC (permalink / raw)
  To: emacs-devel

> Have you thought of allowing files to be "opened" for direct writing as well?

Last time this came up, I thought that mapping "opened files" to Emacs
subprocess objects was probably going to be more natural.


        Stefan




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: standard output/error/input streams
  2017-01-20 16:26   ` Stefan Monnier
@ 2017-01-20 21:24     ` John Wiegley
  2017-01-20 21:52       ` Stefan Monnier
  0 siblings, 1 reply; 12+ messages in thread
From: John Wiegley @ 2017-01-20 21:24 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

>>>>> "SM" == Stefan Monnier <monnier@iro.umontreal.ca> writes:

SM> Last time this came up, I thought that mapping "opened files" to Emacs
SM> subprocess objects was probably going to be more natural.

That does make me realize that I could use `start-process` with an executable
that does what I want, and use `process-send-string` to bypass the involvement
of any buffers. Thanks for mentioning it.

-- 
John Wiegley                  GPG fingerprint = 4710 CF98 AF9B 327B B80F
http://newartisans.com                          60E1 46C4 BD1A 7AC1 4BA2



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: standard output/error/input streams
  2017-01-20 21:24     ` John Wiegley
@ 2017-01-20 21:52       ` Stefan Monnier
  2017-01-20 21:59         ` John Wiegley
  2017-01-23 12:41         ` Phillip Lord
  0 siblings, 2 replies; 12+ messages in thread
From: Stefan Monnier @ 2017-01-20 21:52 UTC (permalink / raw)
  To: emacs-devel

> That does make me realize that I could use `start-process` with an executable
> that does what I want, and use `process-send-string` to bypass the involvement
> of any buffers. Thanks for mentioning it.

Right.  What I was thinking of was to add a `make-file-process`
primitive so you don't need an external executable.


        Stefan




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: standard output/error/input streams
  2017-01-20 21:52       ` Stefan Monnier
@ 2017-01-20 21:59         ` John Wiegley
  2017-01-23 12:41         ` Phillip Lord
  1 sibling, 0 replies; 12+ messages in thread
From: John Wiegley @ 2017-01-20 21:59 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

>>>>> "SM" == Stefan Monnier <monnier@iro.umontreal.ca> writes:

SM> Right. What I was thinking of was to add a `make-file-process` primitive
SM> so you don't need an external executable.

Sounds like a good workaround to me, and handily solves the cleanup problem.

-- 
John Wiegley                  GPG fingerprint = 4710 CF98 AF9B 327B B80F
http://newartisans.com                          60E1 46C4 BD1A 7AC1 4BA2



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: standard output/error/input streams
  2017-01-20 21:52       ` Stefan Monnier
  2017-01-20 21:59         ` John Wiegley
@ 2017-01-23 12:41         ` Phillip Lord
  2017-01-23 13:11           ` Stefan Monnier
  1 sibling, 1 reply; 12+ messages in thread
From: Phillip Lord @ 2017-01-23 12:41 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> That does make me realize that I could use `start-process` with an executable
>> that does what I want, and use `process-send-string` to bypass the involvement
>> of any buffers. Thanks for mentioning it.
>
> Right.  What I was thinking of was to add a `make-file-process`
> primitive so you don't need an external executable.


If we had a function to go to generate a stream from a process then we
could have our cake and eat it.

Phil



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: standard output/error/input streams
  2017-01-23 12:41         ` Phillip Lord
@ 2017-01-23 13:11           ` Stefan Monnier
  0 siblings, 0 replies; 12+ messages in thread
From: Stefan Monnier @ 2017-01-23 13:11 UTC (permalink / raw)
  To: Phillip Lord; +Cc: emacs-devel

> If we had a function to go to generate a stream from a process then we
> could have our cake and eat it.

(lambda (c) (process-send-string PROC (string c))) ?

BTW, w.r.t stdin/stdout/stderr: these are special because they may be
inaccessible to something like a subprocess (or at least it can be nigh
on impossible for the Emacs process itself to determine where
std(in|out|err) are going).

IOW, additionally to make-file-process, we'd need
a make-process-from-open-file-descriptor.


        Stefan



^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2017-01-23 13:11 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-14 12:22 standard output/error/input streams Phillip Lord
2017-01-14 14:03 ` Noam Postavsky
2017-01-14 14:31 ` Eli Zaretskii
2017-01-14 17:51   ` Eli Zaretskii
2017-01-19  7:21 ` John Wiegley
2017-01-20 13:38   ` Phillip Lord
2017-01-20 16:26   ` Stefan Monnier
2017-01-20 21:24     ` John Wiegley
2017-01-20 21:52       ` Stefan Monnier
2017-01-20 21:59         ` John Wiegley
2017-01-23 12:41         ` Phillip Lord
2017-01-23 13:11           ` Stefan Monnier

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