Subject: Re: bug#32257: 26.1; read-multiple-choice inf loops on mouse clicks

From: Noam Postavsky <[email-masked]>
Date: Tue, 21 May 2019 20:52:34 -0400

tags 32257 + patch
quit

Andy Moreton <[email-masked]> writes:

> On Wed 01 Aug 2018, Eli Zaretskii wrote:
>>> 
>>> Noam's original patch may bring some possibility of new problems,
>>> but it does at least fix the original problem (on emacs-26 and
>>> master).
>>
>> Fixing a problem and introducing another doesn't sound wise to me.
>> We've been there several times during the last years, and I don't want
>> to make the same mistake again.  Sorry.
>
> Perhaps reverting the patches that introduced read-multiple-choice
> is the right answer then.

How about for emacs-26, we call read-event only after receiving the
problematic error.  This works around the problem, and should be safe
enough, since it only triggers when we would otherwise be ending up in
an infloop anyway.

>From 8545e36df343cc169d7ae1ab3a43c9805cd51015 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <[email-masked]>
Date: Tue, 21 May 2019 20:33:09 -0400
Subject: [PATCH] Avoid infloop in read-multiple-choice (Bug#32257)

* lisp/emacs-lisp/rmc.el (read-multiple-choice): When `read-char'
signals an error "Non-character input-event", call `read-event' to
take the non-character event out of the queue.  Don't merge to master,
we just use `read-event' directly there, rather than this solution
which relies a particular error message.
---
 lisp/emacs-lisp/rmc.el | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/lisp/emacs-lisp/rmc.el b/lisp/emacs-lisp/rmc.el
index 6d1adae974..5411f2ba77 100644
--- a/lisp/emacs-lisp/rmc.el
+++ b/lisp/emacs-lisp/rmc.el
@@ -116,10 +116,15 @@ read-multiple-choice
                               (cons (capitalize (cadr elem))
                                     (car elem)))
                             choices)))
-                  (condition-case nil
+                  (condition-case err
                       (let ((cursor-in-echo-area t))
                         (read-char))
-                    (error nil))))
+                    (error (when (equal (cadr err) "Non-character input-event")
+                             ;; Use up the non-character input-event.
+                             ;; Otherwise we'll just keep reading it
+                             ;; again and again (Bug#32257).
+                             (read-event))
+                           nil))))
           (setq answer (lookup-key query-replace-map (vector tchar) t))
           (setq tchar
                 (cond
-- 
2.11.0

And master can just use read-event.

>From f1f32043f65dc19b6d63cf1ce52ef19b46c14e22 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <[email-masked]>
Date: Tue, 21 May 2019 20:38:00 -0400
Subject: [PATCH] Avoid infloop in read-multiple-choice (Bug#32257)

* lisp/emacs-lisp/rmc.el (read-multiple-choice): Use `read-event'
which won't get stuck (return the same event over and over again) for
non-character events, unlike `read-char'.
---
 lisp/emacs-lisp/rmc.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/emacs-lisp/rmc.el b/lisp/emacs-lisp/rmc.el
index 6d1adae974..47f3b8dc9c 100644
--- a/lisp/emacs-lisp/rmc.el
+++ b/lisp/emacs-lisp/rmc.el
@@ -118,7 +118,7 @@ read-multiple-choice
                             choices)))
                   (condition-case nil
                       (let ((cursor-in-echo-area t))
-                        (read-char))
+                        (read-event))
                     (error nil))))
           (setq answer (lookup-key query-replace-map (vector tchar) t))
           (setq tchar
-- 
2.11.0