From debbugs-submit-bounces@debbugs.gnu.org Fri Jan 18 05:47:10 2019 Received: (at submit) by debbugs.gnu.org; 18 Jan 2019 10:47:11 +0000 Received: from localhost ([127.0.0.1]:35731 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gkRg6-0004qE-6T for submit@debbugs.gnu.org; Fri, 18 Jan 2019 05:47:10 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42924) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gkRUZ-0002h1-4N for submit@debbugs.gnu.org; Fri, 18 Jan 2019 05:35:15 -0500 Received: from lists.gnu.org ([209.51.188.17]:54490) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gkRUS-0000pS-5A for submit@debbugs.gnu.org; Fri, 18 Jan 2019 05:35:09 -0500 Received: from eggs.gnu.org ([209.51.188.92]:53099) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkRUP-0000ho-6U for bug-gnu-emacs@gnu.org; Fri, 18 Jan 2019 05:35:08 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-0.5 required=5.0 tests=BAYES_05,FREEMAIL_FROM, HTML_MESSAGE autolearn=disabled version=3.3.2 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gkRUN-0000My-36 for bug-gnu-emacs@gnu.org; Fri, 18 Jan 2019 05:35:05 -0500 Received: from mail-lf1-x131.google.com ([2a00:1450:4864:20::131]:39934) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gkRUH-0007RJ-AH for bug-gnu-emacs@gnu.org; Fri, 18 Jan 2019 05:35:01 -0500 Received: by mail-lf1-x131.google.com with SMTP id n18so10112714lfh.6 for ; Fri, 18 Jan 2019 02:34:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=mhl7j8YuudxTapeE3gK7jnbbfVtT33M7T1PzeVtOHE4=; b=UKJ/n+OEkvG5bZD3QOO1C5JTN8Wz2HjiW/iu5+S4IkFySySvklb2pfseoj8lfrzty5 9q2owp18Xr9kr/hrXtoUwkNuBlqG3QAX9jP7zpIzQdMnkVWEmskD2ZVJBHGIqkki9tpO H6vY0DGaDDkpO+T7dBy5v/Pc99JstjhOmefBGgdKFsXMj9+x9phf4WeZk1pfVGxBlkNx EPNNs5W4FfSHOxHgoaEUIDAgRmc/uSvf8Zh3hjc6xcLU7Vgz9o1Ti4j4wPhwYr2f7Kd/ jMGcBQ5FtcV4I2Y0ChKV0m0CvtxXyt/dDzl5TAREnjqTJm360B171bc92tSDH4UBjuzh Wotw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=mhl7j8YuudxTapeE3gK7jnbbfVtT33M7T1PzeVtOHE4=; b=K/tXd3nsXlZaPz/onH7YaTeN9+940aV1Xi3KOf4gF7wr5eZ6tZVB0iF0tdgUmbEye8 u/o5e4k9Q5jYhPa96Q2rHTs3baqqP3IJRVYwQD/+JZgHRtM7nnqKaUukLZ116wdwfO90 MEK4XP4aeXpekijHfYPRbAd4nhGTT3TY355ekqeyFV/GA987+76CdsiLW/IYh2gQczee QZsH2N0Iv45CNcrzqwWBoQzF8rnohVMUMGRAwLVl5XYfYaKdg8w0W/qA+C5p1Ey410oh q4g/Wr9YTbAO7jQ9qyJVSV1Vd3HJ1wOs/ki2tCs0lvB1O+GOD5s8z5Rrast33+71NVHp TAJw== X-Gm-Message-State: AJcUukfm9LWFZX1Wu++OgA4S4DS02+JyjTVT8cJTYdNxKfTg/FrjI5RO ZNkRtcwuUeiJA2kEPjKZCPeQv6CA6/SNWDVqQrGNYDS2 X-Google-Smtp-Source: ALg8bN5J3wscW34biX1ZloZL2agtkPiUVUA6Xr2pF2H1H45mx6GGptRHzk/dR3+CGwYSSLDeZK3XrrriL8bs4PYpIBs= X-Received: by 2002:ac2:55a3:: with SMTP id y3mr11724971lfg.93.1547807689634; Fri, 18 Jan 2019 02:34:49 -0800 (PST) MIME-Version: 1.0 From: Shawn Presser Date: Fri, 18 Jan 2019 04:35:34 -0600 Message-ID: Subject: A patch to fix reading EOF characters in non-interactive mode To: bug-gnu-emacs@gnu.org Content-Type: multipart/mixed; boundary="00000000000085adee057fb90f67" X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::131 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Fri, 18 Jan 2019 05:47:09 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) --00000000000085adee057fb90f67 Content-Type: multipart/alternative; boundary="00000000000085adea057fb90f65" --00000000000085adea057fb90f65 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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=E2=80=99s currently impossible for non-interactive scripts t= o 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 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. */ --=20 2.19.1 Thanks! =E2=80=94 shawn --00000000000085adea057fb90f65 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hello,

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

$ git clone=C2=A0https://github.com/shawwn/y
$ cd y
$ bin/y> (read t)
Lisp expression: 42
42
> (read t)
Lisp expre= ssion: ^Derror: Error reading from stdin
> Error reading from stdin
<= font face=3D"Courier New">$=C2=A0

Notice that it=E2=80=99s cu= rrently impossible for non-interactive scripts to recover from EOF when rea= ding from tty. After the user sends an EOF character by pressing C-d, calli= ng read-from-minibuffer will always result in an error.

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

<= div style=3D"color:rgb(0,0,0);font-family:Helvetica;font-size:12px">Here is= the patch:

From 685452ca4a098bbd7c1062a350647= 55c1d09512a 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 readi= ng EOF characters in batch mode.

= * src/minibuf.c (read_minibuf_noninteractive= ): Handle EOF characters by
clearing stdi= n and returning Qnil.
---<= /div>
=C2=A0src/minibuf.c | 3 ++-
=C2=A01 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src= /minibuf.c b/src/minibuf.c
index 321fda1b= a8..8c88a316a7 100644
--- a/src/minibuf.= c
+++ b/src/minibuf.c
=
@@ -250,7 +250,8 @@ read_minibuf_noninteractive (Lisp_Object= prompt, bool expflag,
=C2=A0 =C2=A0else<= /span>
=C2=A0 =C2=A0 =C2=A0{
=
=C2=A0 =C2=A0 =C2=A0 =C2=A0xfree (line);
=
-=C2=A0 =C2=A0 =C2=A0 error ("Error reading from stdin&= quot;);
+=C2=A0 =C2=A0 =C2=A0 clearerr(st= din);
+=C2=A0 =C2=A0 =C2=A0 return Qnil;<= /span>
=C2=A0 =C2=A0 =C2=A0}
=
=C2=A0
=C2=A0 =C2=A0/* If= Lisp form desired instead of string, parse it.=C2=A0 */
--=C2=A0
2.19.1

Thanks!
=E2=80=94 shawn



=
--00000000000085adea057fb90f65-- --00000000000085adee057fb90f67 Content-Type: application/octet-stream; name="0001-Fix-reading-EOF-characters-in-batch-mode.patch" Content-Disposition: attachment; filename="0001-Fix-reading-EOF-characters-in-batch-mode.patch" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_jr1wp1to0 RnJvbSA2ODU0NTJjYTRhMDk4YmJkN2MxMDYyYTM1MDY0NzU1YzFkMDk1MTJhIE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiBTaGF3biBQcmVzc2VyIDxzaGF3bnByZXNzZXJAZ21haWwuY29t PgpEYXRlOiBGcmksIDE4IEphbiAyMDE5IDAzOjU3OjM3IC0wNjAwClN1YmplY3Q6IFtQQVRDSF0g Rml4IHJlYWRpbmcgRU9GIGNoYXJhY3RlcnMgaW4gYmF0Y2ggbW9kZS4KCiogc3JjL21pbmlidWYu YyAocmVhZF9taW5pYnVmX25vbmludGVyYWN0aXZlKTogSGFuZGxlIEVPRiBjaGFyYWN0ZXJzIGJ5 CmNsZWFyaW5nIHN0ZGluIGFuZCByZXR1cm5pbmcgUW5pbC4KLS0tCiBzcmMvbWluaWJ1Zi5jIHwg MyArKy0KIDEgZmlsZSBjaGFuZ2VkLCAyIGluc2VydGlvbnMoKyksIDEgZGVsZXRpb24oLSkKCmRp ZmYgLS1naXQgYS9zcmMvbWluaWJ1Zi5jIGIvc3JjL21pbmlidWYuYwppbmRleCAzMjFmZGExYmE4 Li44Yzg4YTMxNmE3IDEwMDY0NAotLS0gYS9zcmMvbWluaWJ1Zi5jCisrKyBiL3NyYy9taW5pYnVm LmMKQEAgLTI1MCw3ICsyNTAsOCBAQCByZWFkX21pbmlidWZfbm9uaW50ZXJhY3RpdmUgKExpc3Bf T2JqZWN0IHByb21wdCwgYm9vbCBleHBmbGFnLAogICBlbHNlCiAgICAgewogICAgICAgeGZyZWUg KGxpbmUpOwotICAgICAgZXJyb3IgKCJFcnJvciByZWFkaW5nIGZyb20gc3RkaW4iKTsKKyAgICAg IGNsZWFyZXJyKHN0ZGluKTsKKyAgICAgIHJldHVybiBRbmlsOwogICAgIH0KIAogICAvKiBJZiBM aXNwIGZvcm0gZGVzaXJlZCBpbnN0ZWFkIG9mIHN0cmluZywgcGFyc2UgaXQuICAqLwotLSAKMi4x OS4xCgo= --00000000000085adee057fb90f67-- From debbugs-submit-bounces@debbugs.gnu.org Fri Jan 18 08:25:28 2019 Received: (at 34123) by debbugs.gnu.org; 18 Jan 2019 13:25:28 +0000 Received: from localhost ([127.0.0.1]:35808 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gkU9I-0004NY-7B for submit@debbugs.gnu.org; Fri, 18 Jan 2019 08:25:28 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34967) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gkU9G-0004NL-E3 for 34123@debbugs.gnu.org; Fri, 18 Jan 2019 08:25:26 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]:60448) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkU95-00048D-Do; Fri, 18 Jan 2019 08:25:18 -0500 Received: from [176.228.60.248] (port=1797 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1gkU93-0000a0-RF; Fri, 18 Jan 2019 08:25:15 -0500 Date: Fri, 18 Jan 2019 15:25:02 +0200 Message-Id: <8336pqcd3l.fsf@gnu.org> From: Eli Zaretskii To: Shawn Presser In-reply-to: (message from Shawn Presser on Fri, 18 Jan 2019 04:35:34 -0600) Subject: Re: bug#34123: A patch to fix reading EOF characters in non-interactive mode References: MIME-version: 1.0 Content-type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 34123 Cc: 34123@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) > From: Shawn Presser > Date: Fri, 18 Jan 2019 04:35:34 -0600 > > $ 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. What would you want such non-interactive scripts to do after recovery? From debbugs-submit-bounces@debbugs.gnu.org Fri Jan 18 09:21:54 2019 Received: (at 34123) by debbugs.gnu.org; 18 Jan 2019 14:21:54 +0000 Received: from localhost ([127.0.0.1]:35823 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gkV1u-0005e0-3r for submit@debbugs.gnu.org; Fri, 18 Jan 2019 09:21:54 -0500 Received: from mail-ot1-f50.google.com ([209.85.210.50]:36013) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gkV1s-0005dn-0Y for 34123@debbugs.gnu.org; Fri, 18 Jan 2019 09:21:52 -0500 Received: by mail-ot1-f50.google.com with SMTP id k98so14505274otk.3 for <34123@debbugs.gnu.org>; Fri, 18 Jan 2019 06:21:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=QaV+hq2x1BEfqZ7mOI9CjrmKiK+6rx/06P3GIJPeI08=; b=OGB++7UXY9QJoPZUX+FbgbNmVKcJpZhby7MedJMYcMGs/4kvzLCsHSQrmeNrW1chpX 72Hr4OscYkkC/deX0mvQ4d1iZwhCE+8TnlVjcBsu+VyxVM4sAVqY/Hp+EyBk2YhauqlI Fa08+GjASicl0pkYDsPWFf9lKld6cSLnSnOcHM6sRULT1B0p/YKc2j6qquF8x6XxnJmr E1ZKQYQl+oHRWoJVIPPOuVPGFynCn0Bo0V3IAA8dTkCW3+oUd/YuZghL6h3wFnBZw+3H 139D3ZpCFnRUXRm8YC3uWZKNI9FEO5LG1Hh3qMaFI/0CLz1i9MiI4TYHiXNOD8LM+cL+ JwaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=QaV+hq2x1BEfqZ7mOI9CjrmKiK+6rx/06P3GIJPeI08=; b=SehCRqnvmmfMCyboO/ZhsRUD6c7Wkw73lvi1llFuySyqWkbII25NTXHAXtM8I6UyEO zMoaqShXrwwnTliGIOyUBAlFFHKDHb/ibb9ezJ9F8XAzfJlPkvMyakNPffiN4vOoxCwK VZO11awDe33vFjYBVr7xXWeuVFfWHDU8aHB5xwp5f38UwEPLbtQqWzCk5Rb/sR6MHeTt NF+sGGMR7YjoXuFFIcsFIkz41SDGTurz3aCDUZBxyfBJg9sMxTxtAoOyK6hOnxA9n8Kj mqgnep6JKJGxZ5wFtRmNQk+mzCuBOMXfmdkkmhHe0/ZIyon1XY0dCDrEMmf3bOWUMArq eoLg== X-Gm-Message-State: AJcUukeBa+W05mEMhV5SUVdEVimjcZ3pRIVQ4vvqfg2V7451HmpN9wGS ViFnSRZzrmbh2oAva/yTIo89kPm4aTRe5Xuck4o= X-Google-Smtp-Source: ALg8bN7XhJq3p06DrvllBDcGfbK1WRHICRR8nADNuwMpbayh609WUHGrHm8uGjVqVQxbNjxoZuHRLzl5rwCH62OAAKU= X-Received: by 2002:a9d:32c7:: with SMTP id u65mr11538520otb.236.1547821306140; Fri, 18 Jan 2019 06:21:46 -0800 (PST) MIME-Version: 1.0 References: <8336pqcd3l.fsf@gnu.org> In-Reply-To: <8336pqcd3l.fsf@gnu.org> From: Shawn Presser Date: Fri, 18 Jan 2019 08:22:31 -0600 Message-ID: Subject: Re: bug#34123: A patch to fix reading EOF characters in non-interactive mode To: Eli Zaretskii Content-Type: multipart/alternative; boundary="00000000000020dca5057fbc3bdd" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 34123 Cc: 34123@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) --00000000000020dca5057fbc3bdd Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable I use Emacs Lisp as a runtime for Arc (https://github.com/shawwn/arcmacs) a= nd for Lumen (https://github.com/shawwn/y). The goal is to be able to run a Lisp REPL from the terminal. For example, in Arc: $ git clone https://github.com/laarc/laarc $ cd laarc $ make $ bin/arc Use (quit) to quit, (tl) to return here after an interrupt. arc> 1 1 arc> (def my-repl () (pr "> ") (whilet expr (read) (write (eval expr)) (prn) (pr "> "))) *** redefining repl # arc> (my-repl) > 1 ; we can exit this inner REPL with control-D, without exiting the program. 1 > (+ 1 2) 3 > ^D arc> "If this were emacs in batch mode, the program would have exited with errors here." "If this were emacs in batch mode, the program would have exited with errors here." arc> "Instead, control-D returned us to the toplevel REPL. Let's type another control-D to quit." "Instead, control-D returned us to the toplevel REPL. Let's type another control-D to quit." arc> ^D $ Please compare this with arcmacs, which runs in Emacs Lisp: $ git clone https://github.com/shawwn/arcmacs $ cd arcmacs $ ./y-arc Use (quit) to quit, (tl) to return here after an interrupt. arc> 1 1 arc> (def my-repl () (pr "> ") (whilet expr (read) (write (eval expr)) (prn) (pr "> "))) arc> (my-repl) > 1 ; if we enter control-D, every REPL exits immediately and the program quits 1 > 2 2 > ^D arc> $ echo We didn't intend to quit yet! A single ^D exits the entire program, not just the inner REPL. This is because after the user enters control-D, any attempt to call `read-from-minibuffer` will always result in emacs throwing an error with the message "Error reading from stdin". The only way to gracefully handle this case in a script is to trap the internal emacs error with (ignore-errors (read-from-minibuffer "")) and to treat a nil result as if it were EOF. But that causes every nested REPL to exit, since every attempt to (read-from-minibuffer "") will throw "Error reading from stdin". In other words, emacs is always failing to read from stdin after the user sends an EOF. This patch fixes the problem by causing (read-from-minibuffer "") to return nil if the user types control-D. On Fri, Jan 18, 2019 at 7:25 AM Eli Zaretskii wrote: > > From: Shawn Presser > > Date: Fri, 18 Jan 2019 04:35:34 -0600 > > > > $ 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=E2=80=99s currently impossible for non-interactive scrip= ts to > recover from EOF when reading from tty. > > What would you want such non-interactive scripts to do after recovery? > --00000000000020dca5057fbc3bdd Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I use Emacs Lisp as a runtime for Arc (https://github.com/shawwn/arcmacs)=C2=A0and for Lum= en (https://github.com/shawwn/y= ). The goal is to be able to run a Lisp REPL from the terminal.

For example, in Arc:

=C2=A0 $ cd laarc
=C2=A0 $ make
=C2=A0 $ bin/arc
=C2=A0 Use (quit) to quit, (tl) to return here after a= n interrupt.
=C2=A0 ar= c> 1
=C2=A0 1
=C2=A0 arc> (def my-repl= ()
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0(pr "> ")
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(whilet expr (read)
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0(write (eval expr))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(prn) (pr ">= ; ")))
=C2=A0 ***= redefining repl
=C2= =A0 #<procedure: repl>
=C2=A0 arc> (my-repl)
=C2=A0 > 1=C2=A0; we can exit this inner REPL with control-D, without exiting the = program.
=C2=A0 1
=C2=A0 > (+ 1 2)=
=C2=A0 3
=C2=A0 > ^D
=C2=A0 arc> "If this were emacs in batch= mode, the program would have exited with errors here."
=C2=A0 "If this were emacs in b= atch mode, the program would have exited with errors here."
=C2=A0 arc> "Instead, co= ntrol-D returned us to the toplevel REPL. Let's type another control-D = to quit."
=C2=A0 = "Instead, control-D returned us to the toplevel REPL. Let's type a= nother control-D to quit."
=C2=A0 arc> ^D
=C2=A0 $

Please compare this wi= th arcmacs, which runs in Emacs Lisp:

<= font face=3D"monospace, monospace">=C2=A0 $ cd arcmacs
=C2=A0 $ ./y-arc
=C2=A0 Use (quit) to quit, (tl) to return here = after an interrupt.
= =C2=A0 arc> 1
=C2= =A0 1
=C2=A0 arc> (= def my-repl ()
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0(pr "> ")
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(whilet expr = (read)
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0(write (eval expr))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(prn) (p= r "> ")))
=C2=A0 arc> (my-repl)
=C2=A0 > 1=C2=A0=C2=A0; if we ent= er control-D, every REPL exits immediately and the program quits
=C2=A0 1
=C2=A0 > 2
=C2=A0 2
=C2=A0 > ^D
=C2=A0 $ echo=C2=A0= We didn't intend to quit yet!

A single = ^D exits the entire program, not just the inner REPL. This is
bec= ause after the user enters control-D, any attempt to call
`read-f= rom-minibuffer` will always result in emacs throwing an error
wit= h the message "Error reading from stdin".

The only way to gracefully handle this case in a script is to trap the
internal emacs error with (ignore-errors (read-from-minibuffer &quo= t;"))
and to treat a nil result as if it were EOF. But that = causes every
nested REPL to exit, since every attempt to (read-fr= om-minibuffer "")
will throw "Error reading from s= tdin". In other words, emacs is
always failing to read from = stdin after the user sends an EOF.

This patch fixe= s the problem by causing (read-from-minibuffer "") to
r= eturn nil if the user types control-D.


On Fri, Jan 18, 2019 at 7:25 AM Eli Zaretskii <eliz@gnu.org> wrote:
> From: Shawn Presser <shawnpresser@gmail.com>
> Date: Fri, 18 Jan 2019 04:35:34 -0600
>
> $ 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=E2=80=99s currently impossible for non-interactive scri= pts to recover from EOF when reading from tty.

What would you want such non-interactive scripts to do after recovery?
--00000000000020dca5057fbc3bdd-- From debbugs-submit-bounces@debbugs.gnu.org Fri Jan 18 11:04:09 2019 Received: (at 34123) by debbugs.gnu.org; 18 Jan 2019 16:04:09 +0000 Received: from localhost ([127.0.0.1]:36955 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gkWcr-0000DY-5N for submit@debbugs.gnu.org; Fri, 18 Jan 2019 11:04:09 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50786) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gkWcq-0000DK-1O for 34123@debbugs.gnu.org; Fri, 18 Jan 2019 11:04:08 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]:35050) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkWck-0003FV-Rt; Fri, 18 Jan 2019 11:04:02 -0500 Received: from [176.228.60.248] (port=3602 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1gkWck-0004wa-EO; Fri, 18 Jan 2019 11:04:02 -0500 Date: Fri, 18 Jan 2019 18:03:49 +0200 Message-Id: <831s5ac5qy.fsf@gnu.org> From: Eli Zaretskii To: Shawn Presser In-reply-to: (message from Shawn Presser on Fri, 18 Jan 2019 08:22:31 -0600) Subject: Re: bug#34123: A patch to fix reading EOF characters in non-interactive mode References: <8336pqcd3l.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 34123 Cc: 34123@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) > From: Shawn Presser > Date: Fri, 18 Jan 2019 08:22:31 -0600 > Cc: 34123@debbugs.gnu.org > > I use Emacs Lisp as a runtime for Arc (https://github.com/shawwn/arcmacs) and for Lumen > (https://github.com/shawwn/y). The goal is to be able to run a Lisp REPL from the terminal. So the usage you describe, and are interested in, is not non-interactive, as far as Emacs is concerned, right? Or am I missing something? From debbugs-submit-bounces@debbugs.gnu.org Fri Jan 18 11:20:16 2019 Received: (at 34123) by debbugs.gnu.org; 18 Jan 2019 16:20:16 +0000 Received: from localhost ([127.0.0.1]:36981 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gkWsS-0000d3-64 for submit@debbugs.gnu.org; Fri, 18 Jan 2019 11:20:16 -0500 Received: from mail-lj1-f169.google.com ([209.85.208.169]:44653) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gkWsQ-0000cm-Ez for 34123@debbugs.gnu.org; Fri, 18 Jan 2019 11:20:14 -0500 Received: by mail-lj1-f169.google.com with SMTP id k19-v6so12063403lji.11 for <34123@debbugs.gnu.org>; Fri, 18 Jan 2019 08:20:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=vZ2V0omD9mNShgaCa2UopjfoOHo9yoyGXpjgQxIiG88=; b=FAExk7U03a9trxg8bj9fEpTA2WImrWvf8gdZ+KWFNXrXXIlAYxyVaKtfYO9P/70oow o2VG0myU0dQflRbh8hPRbQKAS4Vwv9cyK1enBIe5bnYEnWyUjWuqx/deXrCYX4sFCS3W 50NR1kfL58xLi8kdM43VqX6P9LRkNBjFRZK2YKzIIQfjMT4ygtpGZZC8NGoxDGs8QJMb BjiwGIhwQNTr7ag3hWVKlxt3WPeYs7/ESJfBAcu/E24Dc6myihgeTMd9QThZKffFLCDA e1A8N9l4u79gZ1rqNOnDXRQIX65shPEX5bCR47YEDe3EuuPkZk/dXFq6GlzMzS9y0AYu x/MQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=vZ2V0omD9mNShgaCa2UopjfoOHo9yoyGXpjgQxIiG88=; b=goL/NfRc10pCWpcfJK0jch0WjQcfurZWRx3Qi1qwU/4WdFy7RFK6H1PZ9+2EwchrFg PLK/dwjPXMEAq2eaDl0U9SlqYOCgTCS6SrWdJRPh5DYLGm3L0W7uCgXf36nfjs5dRQg4 VQ6EevD2GFRGkKdWyk3vK/1aonIBo04iQZVEqpsZ7TN7Gx70RKpFUixyr9AuR4aRdFhh /ZbxbLk1WTK5vx0Cic9PD4In0EWgxy9MDt9ZSfqLYuAE688V4YJa/NR/KmQ2slxMHh7u G9AqwwixmZCRlIw5r64BqPy2H+9xmt9l0zlrO5fgCOunX7xZtGYwFN0tIevwY75r/+w2 aDpQ== X-Gm-Message-State: AJcUukcjaaQOh9Qo92k1IZdk0uSPP/gmh+IJDaNEeob0d+16ZBBU0jKx KaX5UPVAuXZtKo4Mg4KpVvOnyYblgFqJqqtiPjs= X-Google-Smtp-Source: ALg8bN4iHmoW6kuIADIcUfmaUBtXY+Q95Tj2fSu+N00fNZxYv4qdAGbc2PpibTX6XA71cjWvOsriNV6g0fG+kTKrRwU= X-Received: by 2002:a2e:5555:: with SMTP id j82-v6mr13924775ljb.69.1547828408370; Fri, 18 Jan 2019 08:20:08 -0800 (PST) MIME-Version: 1.0 References: <8336pqcd3l.fsf@gnu.org> <831s5ac5qy.fsf@gnu.org> In-Reply-To: <831s5ac5qy.fsf@gnu.org> From: Shawn Presser Date: Fri, 18 Jan 2019 10:20:54 -0600 Message-ID: Subject: Re: bug#34123: A patch to fix reading EOF characters in non-interactive mode To: Eli Zaretskii Content-Type: multipart/alternative; boundary="000000000000746c3e057fbde2f3" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 34123 Cc: 34123@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) --000000000000746c3e057fbde2f3 Content-Type: text/plain; charset="UTF-8" It's non-interactive: arc> |noninteractive| t (The expression |noninteractive| in arcmacs is equivalent to evaluating 'noninteractive in emacs lisp.) The runtimes start by invoking emacs using `emacs -Q --script ...`, so it's always noninteractive. And in general for writing shell scripts rather than repls, it's important to be in noninteractive mode. But it's equally important to have the ability to prompt the user from a shell script, and for the user to be able to cancel by using ^D without causing stdin errors on all subsequent prompts. On Fri, Jan 18, 2019 at 10:04 AM Eli Zaretskii wrote: > > From: Shawn Presser > > Date: Fri, 18 Jan 2019 08:22:31 -0600 > > Cc: 34123@debbugs.gnu.org > > > > I use Emacs Lisp as a runtime for Arc (https://github.com/shawwn/arcmacs) > and for Lumen > > (https://github.com/shawwn/y). The goal is to be able to run a Lisp > REPL from the terminal. > > So the usage you describe, and are interested in, is not > non-interactive, as far as Emacs is concerned, right? Or am I missing > something? > --000000000000746c3e057fbde2f3 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
It's non-interactive:

<= div>
arc> |noninteractive|
t

(The expression |noninteractive| in arcmacs is equivalent to evaluating &= #39;noninteractive in emacs lisp.)

The runtimes st= art by invoking emacs using `emacs -Q --script ...`, so it's always non= interactive. And in general for writing shell scripts rather than repls, it= 's important to be in noninteractive mode. But it's equally importa= nt to have the ability to prompt the user from a shell script, and for the = user to be able to cancel by using ^D without causing stdin errors on all s= ubsequent prompts.



On Fri, Jan 18,= 2019 at 10:04 AM Eli Zaretskii <eliz@gn= u.org> wrote:
> From: Shawn Presser <shawnpresser@gmail.com>
> Date: Fri, 18 Jan 2019 08:22:31 -0600
> Cc: 34123@d= ebbugs.gnu.org
>
> I use Emacs Lisp as a runtime for Arc (https://github.com/shaw= wn/arcmacs) and for Lumen
> (https://github.com/shawwn/y). The goal is to be able to run a L= isp REPL from the terminal.

So the usage you describe, and are interested in, is not
non-interactive, as far as Emacs is concerned, right?=C2=A0 Or am I missing=
something?
--000000000000746c3e057fbde2f3-- From debbugs-submit-bounces@debbugs.gnu.org Fri Jan 18 11:29:43 2019 Received: (at 34123) by debbugs.gnu.org; 18 Jan 2019 16:29:43 +0000 Received: from localhost ([127.0.0.1]:36985 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gkX1b-0000r0-Bd for submit@debbugs.gnu.org; Fri, 18 Jan 2019 11:29:43 -0500 Received: from eggs.gnu.org ([209.51.188.92]:56961) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gkX1Z-0000qn-Ks for 34123@debbugs.gnu.org; Fri, 18 Jan 2019 11:29:42 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]:35347) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkX1K-0007nk-0j; Fri, 18 Jan 2019 11:29:27 -0500 Received: from [176.228.60.248] (port=1438 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1gkX1H-0002ij-GY; Fri, 18 Jan 2019 11:29:25 -0500 Date: Fri, 18 Jan 2019 18:29:10 +0200 Message-Id: <83zhryaq09.fsf@gnu.org> From: Eli Zaretskii To: Shawn Presser In-reply-to: (message from Shawn Presser on Fri, 18 Jan 2019 10:20:54 -0600) Subject: Re: bug#34123: A patch to fix reading EOF characters in non-interactive mode References: <8336pqcd3l.fsf@gnu.org> <831s5ac5qy.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 34123 Cc: 34123@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) > From: Shawn Presser > Date: Fri, 18 Jan 2019 10:20:54 -0600 > Cc: 34123@debbugs.gnu.org > > It's non-interactive: > > arc> |noninteractive| > t > > (The expression |noninteractive| in arcmacs is equivalent to evaluating 'noninteractive in emacs lisp.) > > The runtimes start by invoking emacs using `emacs -Q --script ...`, so it's always noninteractive. And in > general for writing shell scripts rather than repls, it's important to be in noninteractive mode. But it's equally > important to have the ability to prompt the user from a shell script, and for the user to be able to cancel by > using ^D without causing stdin errors on all subsequent prompts. I think we are miscommunicating, since your usage involves Emacs reading from the terminal. That is not noninteractive in my book. What I mean by noninteractive is when stdin is not connected to a terminal. Your proposed patch affects that case as well, doesn't it? From debbugs-submit-bounces@debbugs.gnu.org Fri Jan 18 12:22:34 2019 Received: (at 34123) by debbugs.gnu.org; 18 Jan 2019 17:22:34 +0000 Received: from localhost ([127.0.0.1]:37005 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gkXqk-000264-06 for submit@debbugs.gnu.org; Fri, 18 Jan 2019 12:22:34 -0500 Received: from mail-lj1-f176.google.com ([209.85.208.176]:34610) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gkXqh-00025q-9M for 34123@debbugs.gnu.org; Fri, 18 Jan 2019 12:22:32 -0500 Received: by mail-lj1-f176.google.com with SMTP id u89-v6so12283964lje.1 for <34123@debbugs.gnu.org>; Fri, 18 Jan 2019 09:22:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=6td9l9DXAldh4D18RYhkuuOeDQ/aHD3peQC62O8maKU=; b=kjfn/dLNzmWCXeJN/f0ZRtCuG6DFItdaGWU0ejIjqSQL2k7IfG/7XKRo0ALx5ErbPl Bx0/8eRJl1fdxck+1HUQR9VKg7+rrar4rMm1RZ9OrXWpzyZsk91IRStiFRUYvbJkVVxh jYAbc8oQYN7JhRvC/wDWGkMEqYmzMk3rZOrWEFyjixp4K5Eh4PRl9SYTjJ7rpOqVdbko vv5G7EI4VSB9L2XKpW+8/w/SZc/Xf3aXLfBfDHF43QRXq/39MsnMqnc4K7EjcJrXn4xf O4zbgAecX25mJFhB9eAvmVfGvUGnK3Aa4JprLxZax4CLkvbTkQdKrdrf2wT3H/Fl8dI+ TUBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=6td9l9DXAldh4D18RYhkuuOeDQ/aHD3peQC62O8maKU=; b=kqyCm6qBr8JllYs3X6O8CVipOFsi0HjFCEsZk709UjKJJf782TtDYdw3xbh7lgpnvb LO+9aQtzFKsUs41yd7S2e2Lnz0XH6WG6i9Knrvst3EcYapuLrpY9eFoBr218vkOrmBxH FkXRj1OsmzaB2q3rhe1kjYguCp7IkIbvh7Xsni+3SXuj83GOJNftN+esh+dKaMFL8MxW ifQeCaK/9Nve5sLxmpjcou7tt3ruGR7w0fcr75Bgj9RNXyo6xravXDffPbqyqlJZ8kFl bnGDmiJcdRI2Ga5OAn1fFNGOwSnIM+UR5O7v/l3+iUbJfmVcMSZM8W+jl391s937M4mF XrGQ== X-Gm-Message-State: AJcUukd7dZVQpX1l17U6yLfCPOLyIEzJfjs+wrAYi9HVOxiLn3mDKfO4 itwOAk705ZlqVCSHIW06UE5s06F7dQG4X4POue8= X-Google-Smtp-Source: ALg8bN45CUtFTFFEBGgZ5GWC9pj/zVeL/EzC55PhYQfmEoCknozBPUDyyo0O0oxREf7uJgEVcAHMZzcCrcp5/lvjepA= X-Received: by 2002:a2e:1f01:: with SMTP id f1-v6mr12588754ljf.129.1547832145077; Fri, 18 Jan 2019 09:22:25 -0800 (PST) MIME-Version: 1.0 References: <8336pqcd3l.fsf@gnu.org> <831s5ac5qy.fsf@gnu.org> <83zhryaq09.fsf@gnu.org> In-Reply-To: <83zhryaq09.fsf@gnu.org> From: Shawn Presser Date: Fri, 18 Jan 2019 11:23:11 -0600 Message-ID: Subject: Re: bug#34123: A patch to fix reading EOF characters in non-interactive mode To: Eli Zaretskii Content-Type: multipart/alternative; boundary="0000000000002dec5c057fbec195" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 34123 Cc: 34123@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) --0000000000002dec5c057fbec195 Content-Type: text/plain; charset="UTF-8" > What I mean by noninteractive is when stdin is not connected to a terminal. Your proposed patch affects that case as well, doesn't it? I don't think so, because the only case that this patch affects is the case where emacs would signal "error reading from stdin". I don't think I've ever seen emacs throw that error during normal emacs usage, even when reading from stdin not connected to a terminal. But admittedly, I am not certain in all cases. It's probably better to phrase this as a question: Has any elisp code been written to handle "error reading from stdin"? For example, (ignore-error ...) would mask the error message, if it could somehow be generated during normal emacs operation. However, even in that case, the operation of emacs would end up exactly the same, since `nil` is now returned, which is exactly what the `(ignore-error ...)` expression would return (if such code already exists). That said, it would be surprising if this were expected behavior, because the only way for user code to detect and handle it would be to parse the error message, since it's a regular 'error type rather than a type that can be handled via condition-case. I don't think this situation has been covered till now, because emacs users typically don't care about reading from stdin in batch mode. Actually, I just found a blog post from 2014 that complains about this very case: http://joelmccracken.github.io/entries/reading-writing-data-in-emacs-batch-via-stdin-stdout/ > When EOF is read, an error is thrown, which is useless to us. Instead of worrying about the error, we can wrap the function call in an ignore-errors macro, which will return nil when an EOF occurs. They don't seem to care about being able to call read-from-minibuffer multiple times. But if they did care, they would find it quite impossible after the first EOF. On Fri, Jan 18, 2019 at 10:29 AM Eli Zaretskii wrote: > > From: Shawn Presser > > Date: Fri, 18 Jan 2019 10:20:54 -0600 > > Cc: 34123@debbugs.gnu.org > > > > It's non-interactive: > > > > arc> |noninteractive| > > t > > > > (The expression |noninteractive| in arcmacs is equivalent to evaluating > 'noninteractive in emacs lisp.) > > > > The runtimes start by invoking emacs using `emacs -Q --script ...`, so > it's always noninteractive. And in > > general for writing shell scripts rather than repls, it's important to > be in noninteractive mode. But it's equally > > important to have the ability to prompt the user from a shell script, > and for the user to be able to cancel by > > using ^D without causing stdin errors on all subsequent prompts. > > I think we are miscommunicating, since your usage involves Emacs > reading from the terminal. That is not noninteractive in my book. > What I mean by noninteractive is when stdin is not connected to a > terminal. Your proposed patch affects that case as well, doesn't it? > --0000000000002dec5c057fbec195 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
> What I mean by noni= nteractive is when stdin is not connected to a
terminal.=C2=A0 Your prop= osed patch affects that case as well, doesn't it?

I = don't think so, because the only case that this patch affects is the ca= se where emacs would signal "error reading from stdin". I don'= ;t think I've ever seen emacs throw that error during normal emacs usag= e, even when reading from stdin not connected to a terminal.

= But admittedly, I am not certain in all cases. It's probably better to = phrase this as a question: Has any elisp code been written to handle "= error reading from stdin"? For example, (ignore-error ...) would mask = the error message, if it could somehow be generated during normal emacs ope= ration.

However, even in that case, the operation = of emacs would end up exactly the same, since `nil` is now returned, which = is exactly what the `(ignore-error ...)` expression would return (if such c= ode already exists).

That said, it would be surpri= sing if this were expected behavior, because the only way for user code to = detect and handle it would be to parse the error message, since it's a = regular 'error type rather than a type that can be handled via conditio= n-case. I don't think this situation has been covered till now, because= emacs users typically don't care about reading from stdin in batch mod= e.

Actually, I just found a blog post from 2014 th= at complains about this very case:=C2=A0http:= //joelmccracken.github.io/entries/reading-writing-data-in-emacs-batch-via-s= tdin-stdout/

>=C2=A0When EOF is read, an er= ror is thrown, which is useless to us. Instead of worrying about the error,= we can wrap the function call in an ignore-errors macro, which will return= nil when an EOF occurs.

They don't seem to ca= re about being able to call read-from-minibuffer multiple times. But if the= y did care, they would find it quite impossible after the first EOF.
<= div>

On Fri, Jan 18, 2019 at 10:29 AM Eli Zaretskii &l= t;eliz@gnu.org> wrote:
> From: Shawn Presser <= shawnpresser@gm= ail.com>
> Date: Fri, 18 Jan 2019 10:20:54 -0600
> Cc: 34123@d= ebbugs.gnu.org
>
> It's non-interactive:
>
> arc> |noninteractive|
> t
>
> (The expression |noninteractive| in arcmacs is equivalent to evaluatin= g 'noninteractive in emacs lisp.)
>
> The runtimes start by invoking emacs using `emacs -Q --script ...`, so= it's always noninteractive. And in
> general for writing shell scripts rather than repls, it's importan= t to be in noninteractive mode. But it's equally
> important to have the ability to prompt the user from a shell script, = and for the user to be able to cancel by
> using ^D without causing stdin errors on all subsequent prompts.

I think we are miscommunicating, since your usage involves Emacs
reading from the terminal.=C2=A0 That is not noninteractive in my book.
What I mean by noninteractive is when stdin is not connected to a
terminal.=C2=A0 Your proposed patch affects that case as well, doesn't = it?
--0000000000002dec5c057fbec195-- From debbugs-submit-bounces@debbugs.gnu.org Sat Jan 19 20:21:25 2019 Received: (at 34123) by debbugs.gnu.org; 20 Jan 2019 01:21:25 +0000 Received: from localhost ([127.0.0.1]:38184 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gl1ng-0001h6-MU for submit@debbugs.gnu.org; Sat, 19 Jan 2019 20:21:24 -0500 Received: from mail-lj1-f181.google.com ([209.85.208.181]:41036) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gl1nd-0001gr-Ps for 34123@debbugs.gnu.org; Sat, 19 Jan 2019 20:21:22 -0500 Received: by mail-lj1-f181.google.com with SMTP id k15-v6so14659059ljc.8 for <34123@debbugs.gnu.org>; Sat, 19 Jan 2019 17:21:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=t1H6NNJeN6tcxPn7ZG98Sqkl6sTAQyWfOwJT8Dj/84k=; b=F6duZRYz1KlKTU7qdyyqOjIk+XOGgeq7QBV3UfhTWOglHVp8Dz/9xeXM6KzePl2LSy eHKtVWs8UvjO741bBG8UCT1vDyc08AcR9eD1xMsMKDhmsjXtUzXt7r3GqMGEtYPdAyWQ yfx3+cq/3P7Mvv6SjVvOJM/IBD3PDgbF8yKwJoDptYOKlS84cpPNcXRcEtD2z9B9lonT zA5Bq6Af0Y56NztiQ1Ox1wyIQEl/KoJorh78fclpb8iCA2peYTeZ3Zu9Vo3Nb3hBWTmK Y4Fsot8GS4PcFheLGtqnxYEZU0WNnuZhxzNWVRCn/r2SGuvibRMtQ1RvdbqcVDEYXifS 8avg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=t1H6NNJeN6tcxPn7ZG98Sqkl6sTAQyWfOwJT8Dj/84k=; b=MQRLZjsbBr31481anSmbRpUl2bQEvOnUd6C0WrvZmgeD6ZaTVwQyxCA4SPNyYaomQA p1CfXqaFHALus+Dlx7CC4d5/vXbBv8h277mVL6CCM6GBczAUu+Txv9AY+ygaQfgaP+5K iWmV6nV6gNQSo65x8amSTOLu8Ks9qWh0tEgDQV1WR7Ondvwi8cpEfi3hgeYEgh888tro 6OFmuH9YwfOhgAoeBUW4r/BaWG9i3IGVz+8bE9ZfTd2ipFmMLSveHK0FweWmt3q07HQb TgGV2bhJxq6+JJo48PF9g19mPENI68ZwrUGdqCiAehbDPQRz2vN+czUNv3ceL88GwE+h 0v+w== X-Gm-Message-State: AJcUukf91+UNKoxMMKKv8j395R/HVArjxYhC/VenJj+/7cz9fs+1NQnJ RNM6J3xsf5/OmqOwh3EaM6srzj+sE+p9DGL7CmM= X-Google-Smtp-Source: ALg8bN7Qoh6SI6QTj1dEkm8Ebdfh3GFqvPiew/7lurdMhci3CPBJ9YtDpooJ5VfHtLZh/znVlViFAxJavMsIFiLSV6k= X-Received: by 2002:a2e:8596:: with SMTP id b22-v6mr15106982lji.122.1547947275186; Sat, 19 Jan 2019 17:21:15 -0800 (PST) MIME-Version: 1.0 References: <8336pqcd3l.fsf@gnu.org> <831s5ac5qy.fsf@gnu.org> <83zhryaq09.fsf@gnu.org> In-Reply-To: <83zhryaq09.fsf@gnu.org> From: Shawn Presser Date: Sat, 19 Jan 2019 19:22:06 -0600 Message-ID: Subject: Re: bug#34123: A patch to fix reading EOF characters in non-interactive mode To: Eli Zaretskii Content-Type: multipart/alternative; boundary="00000000000077f71b057fd98f8d" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 34123 Cc: 34123@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) --00000000000077f71b057fd98f8d Content-Type: text/plain; charset="UTF-8" Is there another way I can address the concern here? I'm willing to put in the work to get this in. To put it more simply, it seems like an error that emacs doesn't call clearerr(stdin) after reading EOF. Without that, it's impossible to ever read from stdin after the first EOF. Should that be changed? On Fri, Jan 18, 2019 at 10:29 AM Eli Zaretskii wrote: > > From: Shawn Presser > > Date: Fri, 18 Jan 2019 10:20:54 -0600 > > Cc: 34123@debbugs.gnu.org > > > > It's non-interactive: > > > > arc> |noninteractive| > > t > > > > (The expression |noninteractive| in arcmacs is equivalent to evaluating > 'noninteractive in emacs lisp.) > > > > The runtimes start by invoking emacs using `emacs -Q --script ...`, so > it's always noninteractive. And in > > general for writing shell scripts rather than repls, it's important to > be in noninteractive mode. But it's equally > > important to have the ability to prompt the user from a shell script, > and for the user to be able to cancel by > > using ^D without causing stdin errors on all subsequent prompts. > > I think we are miscommunicating, since your usage involves Emacs > reading from the terminal. That is not noninteractive in my book. > What I mean by noninteractive is when stdin is not connected to a > terminal. Your proposed patch affects that case as well, doesn't it? > --00000000000077f71b057fd98f8d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Is there another way I can address the concern here? I'= ;m willing to put in the work to get this in.

To put it = more simply, it seems like an error that emacs doesn't call clearerr(st= din) after reading EOF. Without that, it's impossible to ever read from= stdin after the first EOF. Should that be changed?

On Fri, Jan 18, 20= 19 at 10:29 AM Eli Zaretskii <eliz@gnu.o= rg> wrote:
shawnpresser@gmail.com>
> Date: Fri, 18 Jan 2019 10:20:54 -0600
> Cc: 34123@d= ebbugs.gnu.org
>
> It's non-interactive:
>
> arc> |noninteractive|
> t
>
> (The expression |noninteractive| in arcmacs is equivalent to evaluatin= g 'noninteractive in emacs lisp.)
>
> The runtimes start by invoking emacs using `emacs -Q --script ...`, so= it's always noninteractive. And in
> general for writing shell scripts rather than repls, it's importan= t to be in noninteractive mode. But it's equally
> important to have the ability to prompt the user from a shell script, = and for the user to be able to cancel by
> using ^D without causing stdin errors on all subsequent prompts.

I think we are miscommunicating, since your usage involves Emacs
reading from the terminal.=C2=A0 That is not noninteractive in my book.
What I mean by noninteractive is when stdin is not connected to a
terminal.=C2=A0 Your proposed patch affects that case as well, doesn't = it?
--00000000000077f71b057fd98f8d-- From debbugs-submit-bounces@debbugs.gnu.org Mon Jan 21 03:58:53 2019 Received: (at 34123) by debbugs.gnu.org; 21 Jan 2019 08:58:53 +0000 Received: from localhost ([127.0.0.1]:39405 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1glVPw-00053L-Ar for submit@debbugs.gnu.org; Mon, 21 Jan 2019 03:58:52 -0500 Received: from mail-lj1-f175.google.com ([209.85.208.175]:35656) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1glVPt-000536-MS for 34123@debbugs.gnu.org; Mon, 21 Jan 2019 03:58:50 -0500 Received: by mail-lj1-f175.google.com with SMTP id x85-v6so16850040ljb.2 for <34123@debbugs.gnu.org>; Mon, 21 Jan 2019 00:58:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=D0EXWKJ4rGf8xSxUlZpUgsa819s0U+oMySp3PhWglWY=; b=CeDQenpliKRCCPZUVXHLBbW5/P2Z/0MKGjmMO5nvTXqwTrxG5kdxvIjnX55kKuZH+w x+QwzAkOrB67/krhVznkmRlGPV75+xhXzGfQFNCZW8c/Qs5OksLAUmmJNFhlDddcuTs1 zzo5Rzaug7k3GgS6kXIwBAts5BaDjvQmtvw3fBYbUAg4XUgN4NYdtDW3a1tf2oTPopAI NHMDubB1fRjFSshHNEfsGjk+OrAfgeE8UtJx8yyVrI0yTnS974jaZDmgzA0b+ersmp28 2JrpDHnbT1OafRj1o53xo+OwTBmWW+1tEBw4bmj8YfXBartTHqc6wHvZ5C33CNLWg/xw AlTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=D0EXWKJ4rGf8xSxUlZpUgsa819s0U+oMySp3PhWglWY=; b=OcoQHgxNps52gRYR4J5LSIyaoNvqhLbv9bx56lJAPa96CGGvxMI1jl6o6NXBEoaJ52 2KVQ6rnwQQmSomU8kxoDCT45k/yn8r6gLPp1Go1awcl0JXmlPqxTCco4AF+x6c5dyQOm reQYZTTqYvAfkGHCDcjvpY7n5CWVGVym4dji6oWoZC7o4sEtdjURTvaulRDOgyFRJpt4 J08PMFc9BcpfinlQCE+V16M15AhukX5euajgJNOif3XOHnL51kRwLoU9SwrWRXWpezb7 Kh25/lVQCQJqF3RCyX3SdmkO0XggbC1GGdT2xsb0j5XPChcygqCOLSoyijusa7YcgAfO WbNg== X-Gm-Message-State: AJcUukdQwQGRyFLiNcRXHj7UtBCayK0hpXCasyBx+KsXt5ui5AivCkv/ 7OdgTTqNDiKb+FuXjshE7JU8LoSP4vwVAPxtcxw= X-Google-Smtp-Source: ALg8bN4hhFEwb2yLe1ay6TEKWVtZdSfG4LXzYpDFc1/PvmWZsMFneHTj/H1XwlCrKS9C5xsCCJ6TLpGfaHAVbHydInI= X-Received: by 2002:a2e:5555:: with SMTP id j82-v6mr19411734ljb.69.1548061123414; Mon, 21 Jan 2019 00:58:43 -0800 (PST) MIME-Version: 1.0 References: <8336pqcd3l.fsf@gnu.org> <831s5ac5qy.fsf@gnu.org> <83zhryaq09.fsf@gnu.org> In-Reply-To: <83zhryaq09.fsf@gnu.org> From: Shawn Presser Date: Mon, 21 Jan 2019 02:59:36 -0600 Message-ID: Subject: Re: bug#34123: A patch to fix reading EOF characters in non-interactive mode To: Eli Zaretskii Content-Type: multipart/alternative; boundary="0000000000005a0fa4057ff411f6" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 34123 Cc: 34123@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) --0000000000005a0fa4057ff411f6 Content-Type: text/plain; charset="UTF-8" Hi, just checking in. I wanted to thank you for taking the time to reply and ask about this bug. It's my first emacs patch and I'm not entirely sure if I'm following the process correctly here. I'd like to try answering your questions more succinctly. Is there a "next step" at this point, or something that I can do to help with emacs in general? On Fri, Jan 18, 2019 at 10:29 AM Eli Zaretskii wrote: > > From: Shawn Presser > > Date: Fri, 18 Jan 2019 10:20:54 -0600 > > Cc: 34123@debbugs.gnu.org > > > > It's non-interactive: > > > > arc> |noninteractive| > > t > > > > (The expression |noninteractive| in arcmacs is equivalent to evaluating > 'noninteractive in emacs lisp.) > > > > The runtimes start by invoking emacs using `emacs -Q --script ...`, so > it's always noninteractive. And in > > general for writing shell scripts rather than repls, it's important to > be in noninteractive mode. But it's equally > > important to have the ability to prompt the user from a shell script, > and for the user to be able to cancel by > > using ^D without causing stdin errors on all subsequent prompts. > > I think we are miscommunicating, since your usage involves Emacs > reading from the terminal. That is not noninteractive in my book. > What I mean by noninteractive is when stdin is not connected to a > terminal. Your proposed patch affects that case as well, doesn't it? > --0000000000005a0fa4057ff411f6 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi, just checking in. I wanted to thank you for taking the= time to reply and ask about this bug. It's my first emacs patch and I&= #39;m not entirely sure if I'm following the process correctly here. I&= #39;d like to try answering your questions more succinctly.

<= div>Is there a "next step" at this point, or something that I can= do to help with emacs in general?

=



On Fri, Jan 18, 2019 at 10:29 AM Eli Zaretskii <eliz@gnu.org> wrote:
> From: Shawn Presser <shawnpresser@gmail.com>
> Date: Fri, 18 Jan 2019 10:20:54 -0600
> Cc: 34123@d= ebbugs.gnu.org
>
> It's non-interactive:
>
> arc> |noninteractive|
> t
>
> (The expression |noninteractive| in arcmacs is equivalent to evaluatin= g 'noninteractive in emacs lisp.)
>
> The runtimes start by invoking emacs using `emacs -Q --script ...`, so= it's always noninteractive. And in
> general for writing shell scripts rather than repls, it's importan= t to be in noninteractive mode. But it's equally
> important to have the ability to prompt the user from a shell script, = and for the user to be able to cancel by
> using ^D without causing stdin errors on all subsequent prompts.

I think we are miscommunicating, since your usage involves Emacs
reading from the terminal.=C2=A0 That is not noninteractive in my book.
What I mean by noninteractive is when stdin is not connected to a
terminal.=C2=A0 Your proposed patch affects that case as well, doesn't = it?
--0000000000005a0fa4057ff411f6-- From debbugs-submit-bounces@debbugs.gnu.org Mon Jan 21 10:44:48 2019 Received: (at 34123) by debbugs.gnu.org; 21 Jan 2019 15:44:48 +0000 Received: from localhost ([127.0.0.1]:40349 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1glbkm-0000bx-2X for submit@debbugs.gnu.org; Mon, 21 Jan 2019 10:44:48 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39346) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1glbki-0000bi-8c for 34123@debbugs.gnu.org; Mon, 21 Jan 2019 10:44:44 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]:39498) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1glbkY-00059U-Gi; Mon, 21 Jan 2019 10:44:36 -0500 Received: from [176.228.60.248] (port=3106 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1glbkY-00059k-4T; Mon, 21 Jan 2019 10:44:34 -0500 Date: Mon, 21 Jan 2019 17:44:20 +0200 Message-Id: <83tvi29fsb.fsf@gnu.org> From: Eli Zaretskii To: Shawn Presser In-reply-to: (message from Shawn Presser on Mon, 21 Jan 2019 02:59:36 -0600) Subject: Re: bug#34123: A patch to fix reading EOF characters in non-interactive mode References: <8336pqcd3l.fsf@gnu.org> <831s5ac5qy.fsf@gnu.org> <83zhryaq09.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 34123 Cc: 34123@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) > From: Shawn Presser > Date: Mon, 21 Jan 2019 02:59:36 -0600 > Cc: 34123@debbugs.gnu.org > > Hi, just checking in. I wanted to thank you for taking the time to reply and ask about this bug. It's my first > emacs patch and I'm not entirely sure if I'm following the process correctly here. I'd like to try answering your > questions more succinctly. > > Is there a "next step" at this point, or something that I can do to help with emacs in general? I'm still considering the implications of your suggestion on the other use cases. One possible alternative would be to add a function that will clear the error condition, and let users/Lisp programs call it. This way, the default response to EOF will remain intact. Perhaps someone else will chime in with opinions and ideas. Thanks. From debbugs-submit-bounces@debbugs.gnu.org Sat Jun 22 20:18:46 2019 Received: (at 34123) by debbugs.gnu.org; 23 Jun 2019 00:18:46 +0000 Received: from localhost ([127.0.0.1]:52721 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1heqDW-00083A-6K for submit@debbugs.gnu.org; Sat, 22 Jun 2019 20:18:46 -0400 Received: from mail-io1-f45.google.com ([209.85.166.45]:42573) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1heqDU-00082y-3V for 34123@debbugs.gnu.org; Sat, 22 Jun 2019 20:18:44 -0400 Received: by mail-io1-f45.google.com with SMTP id u19so56725ior.9 for <34123@debbugs.gnu.org>; Sat, 22 Jun 2019 17:18:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=EPeRXe5/6Q/GRH4szJHAAWnxrXOi3pMdG1JeDRJAIxg=; b=ipl47JYcjxQe71gvFd0AsWFkKuZsqVl3tXZXdgnFIAurvA8cl9CwUayIXYgLlbIvFh CGvSmV1MVyVzkGQ6WNP3oyvUrpjK8sG7dWVD7PZJ4X0fljJ1zSPfQvhHveYeWAp3v2MW 6S8hHuJBTKmHJblEvSHJFfXfziT9OiGmc4Y9vF60prtL0ncB4CFF5wpBcc3mZc15v6VM 4CN+eR0i1+Xj6DjPKfb96W7adCs53xkFfK4l2OtaOB51uUycYHT8lrEPrCQrjLFuWNSt W22AyCjGdnNddm2xbxNLD6L/ClZiAxiKxJZtr1R69QBT447gQfXxudvMDsW1ThtBxMWH RgNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=EPeRXe5/6Q/GRH4szJHAAWnxrXOi3pMdG1JeDRJAIxg=; b=YYPR6AvEX6y7vGl87ivAvISH7WBF7at2fpvN2CpDvtparTb04pRHItAV81V/LjzDn3 uXg3lGC/UTB99CHTr8IEPxghlZffFHnGAAMqMcPxX6T8l33A41nsW5puhB916be08lA0 Yk1zAkWz3YX8/xF0ShjPKhdu07ft2lTRy2p+0tB3FXFa5/SQrVhUk5wktv1uyL1z2S1S xA0NTg69CeWgBdvJEjqOovnttK8lW5DmGVfisV21ZgZEc6TLwykP/NwZ/BTRE1NzEulw LNMqAsVkekY8uVrSaap33tClJFQwtjJoa4k/eb8XYCn6qtWQWAkOnEx9vFiMvk14WXLj +u5g== X-Gm-Message-State: APjAAAWqRZ0YSCFvZUuAIGSvuTWdQfntqX3KaVltE7SiYVHY414OXY1D RIXWipMH7A7oottQ54KDDc9KMILG X-Google-Smtp-Source: APXvYqyNMXzYDihp48JfWPelUlcJkxIBMozRZymMCPZm9FAbATBfCVCBuMX0ng7kxH1FncDmNspdgg== X-Received: by 2002:a6b:e608:: with SMTP id g8mr30968403ioh.88.1561249118262; Sat, 22 Jun 2019 17:18:38 -0700 (PDT) Received: from minid (cbl-45-2-119-34.yyz.frontiernetworks.ca. [45.2.119.34]) by smtp.gmail.com with ESMTPSA id f17sm16506235ioc.2.2019.06.22.17.18.36 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 22 Jun 2019 17:18:37 -0700 (PDT) From: Noam Postavsky To: Shawn Presser Subject: Re: bug#34123: A patch to fix reading EOF characters in non-interactive mode References: Date: Sat, 22 Jun 2019 20:18:36 -0400 In-Reply-To: (Shawn Presser's message of "Fri, 18 Jan 2019 04:35:34 -0600") Message-ID: <87lfxttaqr.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 34123 Cc: 34123@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Shawn Presser writes: > Notice that it=E2=80=99s 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 isn't quite true, see the attached script which catches the error and only exits after two EOFs. --=-=-= Content-Type: text/plain Content-Disposition: attachment; filename=bug-34123-read-script.el Content-Description: script demoing eof handling (require 'cl-lib) (cl-loop with eofs = 0 for i from 0 while (< eofs 2) do (condition-case err (princ (format "line%d: %S\n" i (read-from-minibuffer "> "))) (error (if (equal err '(error "Error reading from stdin")) (message "EOF%d" (cl-incf eofs)) (signal (car err) (cdr err)))))) --=-=-= Content-Type: text/plain A sample usage: $ emacs -Q --script ../bug-34123-read-script.el > one line0: "one" > EOF1 > two line2: "two" > EOF2 > xfree (line); > - error ("Error reading from stdin"); > + clearerr(stdin); > + return Qnil; I think it would make sense to change that error to be an end-of-file error, to make it easier to catch (having to examine the error message, as I did in my script is not so nice). --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Mon Aug 10 07:56:25 2020 Received: (at 34123) by debbugs.gnu.org; 10 Aug 2020 11:56:25 +0000 Received: from localhost ([127.0.0.1]:34728 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1k56Pg-00012H-Pn for submit@debbugs.gnu.org; Mon, 10 Aug 2020 07:56:25 -0400 Received: from quimby.gnus.org ([95.216.78.240]:46816) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1k56Pf-000124-01 for 34123@debbugs.gnu.org; Mon, 10 Aug 2020 07:56:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Message-ID :In-Reply-To:Date:References:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=m+tShq0QmrZI/wkJaJ2c0PoMuPiZvMYDx3wJncH58gw=; b=NJODheGb8LrIFXsNrXyFoIGAWN muWZz2/SJbKQ5rNV+r80+UvYW1STG9qrA2EXwDtJL/vMcvTJl6120l/2t0NVWHvgkAAqTuHIDrN0A BDuYh2Y+7kyI3Nyx5zEYYM9+wPS6YffFjTv9iKzopG4XF30H79pp8VpH+FJaEgIejna0=; Received: from cm-84.212.202.86.getinternet.no ([84.212.202.86] helo=xo) by quimby with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k56PU-0003X4-Rq; Mon, 10 Aug 2020 13:56:16 +0200 From: Lars Ingebrigtsen To: Eli Zaretskii Subject: Re: bug#34123: A patch to fix reading EOF characters in non-interactive mode References: <8336pqcd3l.fsf@gnu.org> <831s5ac5qy.fsf@gnu.org> <83zhryaq09.fsf@gnu.org> <83tvi29fsb.fsf@gnu.org> Date: Mon, 10 Aug 2020 13:56:11 +0200 In-Reply-To: <83tvi29fsb.fsf@gnu.org> (Eli Zaretskii's message of "Mon, 21 Jan 2019 17:44:20 +0200") Message-ID: <87tuxa67fo.fsf@gnus.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see @@CONTACT_ADDRESS@@ for details. Content preview: Eli Zaretskii writes: > I'm still considering the implications of your suggestion on the other > use cases. One possible alternative would be to add a function that > will clear the error condition, and let users/Lisp prog [...] Content analysis details: (-2.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 34123 Cc: Shawn Presser , 34123@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Eli Zaretskii writes: > I'm still considering the implications of your suggestion on the other > use cases. One possible alternative would be to add a function that > will clear the error condition, and let users/Lisp programs call it. > This way, the default response to EOF will remain intact. > > Perhaps someone else will chime in with opinions and ideas. And then Noam answered a few months later: Noam Postavsky writes: > Shawn Presser writes: > >> Notice that it=E2=80=99s currently impossible for non-interactive script= s 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 resu= lt >> in an error. > > This isn't quite true, see the attached script which catches the error > and only exits after two EOFs. Shawn, does Noam's solution work for you? Noam also had this suggestion: >> xfree (line); >> - error ("Error reading from stdin"); >> + clearerr(stdin); >> + return Qnil; > > I think it would make sense to change that error to be an end-of-file > error, to make it easier to catch (having to examine the error message, > as I did in my script is not so nice). And I think that's true? It happens here in read_minibuf_noninteractive: if (len || c =3D=3D '\n' || c =3D=3D '\r') { val =3D make_string (line, len); xfree (line); } else { xfree (line); error ("Error reading from stdin"); } So I think that error can only happen on an end-of-file? Anybody objecting to changing that to and end-of-file error? --=20 (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no From debbugs-submit-bounces@debbugs.gnu.org Wed Aug 19 06:57:32 2020 Received: (at 34123) by debbugs.gnu.org; 19 Aug 2020 10:57:32 +0000 Received: from localhost ([127.0.0.1]:38104 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1k8Lme-00072R-9k for submit@debbugs.gnu.org; Wed, 19 Aug 2020 06:57:32 -0400 Received: from quimby.gnus.org ([95.216.78.240]:43350) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1k8Lmb-00071i-G6 for 34123@debbugs.gnu.org; Wed, 19 Aug 2020 06:57:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=9n95PPR+0R0UL5gBvjeNYh0+Vy6jQ4Qo6v8cJLxp7Lo=; b=fwg11UAIDHFvrzkkteGWJWLbuV ZV0WExLasDXghMJVjYd/Bh2nUHY3SRkWBBG+ei0A6KLeSKqpVXbNmg1Gw6bd7LmyVUjY69dzKCdLH epXYSYEymalxds3mSSf1wKfEE99Q1qGxIOyW8V6wx5TtF34BNDl66oO54hb3KefaXsUM=; Received: from cm-84.212.202.86.getinternet.no ([84.212.202.86] helo=xo) by quimby with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k8LmS-0003nH-4P; Wed, 19 Aug 2020 12:57:22 +0200 From: Lars Ingebrigtsen To: Eli Zaretskii Subject: Re: bug#34123: A patch to fix reading EOF characters in non-interactive mode References: <8336pqcd3l.fsf@gnu.org> <831s5ac5qy.fsf@gnu.org> <83zhryaq09.fsf@gnu.org> <83tvi29fsb.fsf@gnu.org> <87tuxa67fo.fsf@gnus.org> X-Now-Playing: Various's _Lonely is an Eyesore_: "Dead Can Dance - The Protagonist" Date: Wed, 19 Aug 2020 12:57:18 +0200 In-Reply-To: <87tuxa67fo.fsf@gnus.org> (Lars Ingebrigtsen's message of "Mon, 10 Aug 2020 13:56:11 +0200") Message-ID: <87k0xu7vjl.fsf@gnus.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see @@CONTACT_ADDRESS@@ for details. Content preview: Lars Ingebrigtsen writes: > And I think that's true? It happens here in read_minibuf_noninteractive: > > if (len || c == '\n' || c == '\r') > { > val = make_string (line, len); > xfree (line); > } > else > { > xfree (line); > [...] Content analysis details: (-2.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 34123 Cc: Shawn Presser , 34123@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Lars Ingebrigtsen writes: > And I think that's true? It happens here in read_minibuf_noninteractive: > > if (len || c == '\n' || c == '\r') > { > val = make_string (line, len); > xfree (line); > } > else > { > xfree (line); > error ("Error reading from stdin"); > } > > So I think that error can only happen on an end-of-file? Anybody > objecting to changing that to and end-of-file error? There were no objections, so I've now done this in Emacs 28. (It didn't seem NEWS-worthy, so I didn't add a NEWS item.) Witch that change, I think Noam's approach to handling EOF characters in non-interactive Emacsen should work fine, so I'm closing this bug report. If more work needs to be done here, please respond and we'll reopen the bug report. -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no From debbugs-submit-bounces@debbugs.gnu.org Wed Aug 19 06:57:36 2020 Received: (at control) by debbugs.gnu.org; 19 Aug 2020 10:57:36 +0000 Received: from localhost ([127.0.0.1]:38109 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1k8Lmi-00072k-Ix for submit@debbugs.gnu.org; Wed, 19 Aug 2020 06:57:36 -0400 Received: from quimby.gnus.org ([95.216.78.240]:43366) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1k8Lmg-000729-Sa for control@debbugs.gnu.org; Wed, 19 Aug 2020 06:57:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Subject:From:To:Message-Id:Date:Sender:Reply-To:Cc: MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=fgRZ5oW4aY56m9ZfJqrvRrHaeHizcNhrkPhFUitTPUA=; b=rE/WuY46wgUxCUw7rl/38oXie3 tOZ9tDr3X5am304bc9UyfYr/fifNRAtgoUGqAsndOMRhI0Wpqm8sm3e+dLznJzIp4BNZhKcH0x0Gf ayTqtK4+h+0VdcbVTeETzAt1LMlXFHu3R3DD2ZrMTeGgDeSIZS8VORsry3UnsRxMuD3s=; Received: from cm-84.212.202.86.getinternet.no ([84.212.202.86] helo=xo) by quimby with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k8LmZ-0003nR-3B for control@debbugs.gnu.org; Wed, 19 Aug 2020 12:57:29 +0200 Date: Wed, 19 Aug 2020 12:57:26 +0200 Message-Id: <87imde7vjd.fsf@gnus.org> To: control@debbugs.gnu.org From: Lars Ingebrigtsen Subject: control message for bug #34123 X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see @@CONTACT_ADDRESS@@ for details. Content preview: tags 34123 fixed close 34123 28.1 quit Content analysis details: (-2.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) tags 34123 fixed close 34123 28.1 quit From unknown Mon Aug 18 17:58:55 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Wed, 16 Sep 2020 11:24:06 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator