all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#34123: A patch to fix reading EOF characters in non-interactive mode
@ 2019-01-18 10:35 Shawn Presser
  2019-01-18 13:25 ` Eli Zaretskii
  2019-06-23  0:18 ` Noam Postavsky
  0 siblings, 2 replies; 13+ messages in thread
From: Shawn Presser @ 2019-01-18 10:35 UTC (permalink / raw)
  To: 34123


[-- Attachment #1.1: Type: text/plain, Size: 1525 bytes --]

Hello,

Here is a patch to allow batch mode scripts to handle EOF characters. This
solves the following problem:

$ git clone https://github.com/shawwn/y
$ cd y
$ bin/y
> (read t)
Lisp expression: 42
42
> (read t)
Lisp expression: ^Derror: Error reading from stdin
> Error reading from stdin
$

Notice that it’s currently impossible for non-interactive scripts to
recover from EOF when reading from tty. After the user sends an EOF
character by pressing C-d, calling read-from-minibuffer will always result
in an error.

This patch solves this by clearing stdin of errors and returning nil when
an EOF character is detected.

Here is the patch:

From 685452ca4a098bbd7c1062a35064755c1d09512a Mon Sep 17 00:00:00 2001
From: Shawn Presser <shawnpresser@gmail.com>
Date: Fri, 18 Jan 2019 03:57:37 -0600
Subject: [PATCH] Fix reading EOF characters in batch mode.

* src/minibuf.c (read_minibuf_noninteractive): Handle EOF characters by
clearing stdin and returning Qnil.
---
 src/minibuf.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/minibuf.c b/src/minibuf.c
index 321fda1ba8..8c88a316a7 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -250,7 +250,8 @@ read_minibuf_noninteractive (Lisp_Object prompt, bool
expflag,
   else
     {
       xfree (line);
-      error ("Error reading from stdin");
+      clearerr(stdin);
+      return Qnil;
     }

   /* If Lisp form desired instead of string, parse it.  */
-- 
2.19.1

Thanks!
— shawn

[-- Attachment #1.2: Type: text/html, Size: 5814 bytes --]

[-- Attachment #2: 0001-Fix-reading-EOF-characters-in-batch-mode.patch --]
[-- Type: application/octet-stream, Size: 803 bytes --]

From 685452ca4a098bbd7c1062a35064755c1d09512a Mon Sep 17 00:00:00 2001
From: Shawn Presser <shawnpresser@gmail.com>
Date: Fri, 18 Jan 2019 03:57:37 -0600
Subject: [PATCH] Fix reading EOF characters in batch mode.

* src/minibuf.c (read_minibuf_noninteractive): Handle EOF characters by
clearing stdin and returning Qnil.
---
 src/minibuf.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/minibuf.c b/src/minibuf.c
index 321fda1ba8..8c88a316a7 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -250,7 +250,8 @@ read_minibuf_noninteractive (Lisp_Object prompt, bool expflag,
   else
     {
       xfree (line);
-      error ("Error reading from stdin");
+      clearerr(stdin);
+      return Qnil;
     }
 
   /* If Lisp form desired instead of string, parse it.  */
-- 
2.19.1


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

end of thread, other threads:[~2020-08-19 10:57 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-01-18 10:35 bug#34123: A patch to fix reading EOF characters in non-interactive mode Shawn Presser
2019-01-18 13:25 ` Eli Zaretskii
2019-01-18 14:22   ` Shawn Presser
2019-01-18 16:03     ` Eli Zaretskii
2019-01-18 16:20       ` Shawn Presser
2019-01-18 16:29         ` Eli Zaretskii
2019-01-18 17:23           ` Shawn Presser
2019-01-20  1:22           ` Shawn Presser
2019-01-21  8:59           ` Shawn Presser
2019-01-21 15:44             ` Eli Zaretskii
2020-08-10 11:56               ` Lars Ingebrigtsen
2020-08-19 10:57                 ` Lars Ingebrigtsen
2019-06-23  0:18 ` Noam Postavsky

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.