bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#34123: A patch to fix reading EOF characters in non-interactive mode


From: Shawn Presser
Subject: bug#34123: A patch to fix reading EOF characters in non-interactive mode
Date: Fri, 18 Jan 2019 04:35:34 -0600

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: 0001-Fix-reading-EOF-characters-in-batch-mode.patch
Description: Binary data


reply via email to

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