Subject: Re: bug#75886: 31.0.50; read-multiple-choice / read-key and input-decode-map

From: Gerd Möllmann <[email-masked]>
Date: Mon, 27 Jan 2025 09:03:59 +0100

Gerd Möllmann <[email-masked]> writes:

> Gerd Möllmann <[email-masked]> writes:
>
>> I would have thought that replacing read-event with read-key in
>> reac-multiple-choice would have solved this, because read-key consults
>> input-decode-map. But that is not the case because read-key behaves
>> differently if input-decode-map has an entry for C-g or not.
>>
>> Without input-decode-map for C-g.
>>
>> #+begin_src emacs-lisp
>>   (read-key) ;; press C-g
>>   => Quit
>> #+end_src
>>
>>
>> With input-decode-map setting for C-g:
>>
>> #+begin_src emacs-lisp
>>   (read-key) ;; press C-g
>>   => 7
>> #+end_src
>>
>> Sorry for lumping these two bugs together, but I think it's easier to
>> understand this way.
>
> I have to correct that, I confused read-event and read-key.
>
> read-key never quits, it always returns ^G, input-decode-map or not
>
> #+begin_src emacs-lisp
>   (read-key) ;; press C-g
>   => 7
> #+end_src
>
>
> read-event quits if not input-decode-map
>
> #+begin_src emacs-lisp
>   (read-event) ;; press C-g
>   => Quit
> #+end_src

The attached patch fixes things for me. It changes only
read-multiple-choice because read-key not quitting on C-g seems to have
been that way already in Emacs 30.

>From 0dbe8060b375e317a0e2709141cda7ff6ea03a76 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gerd=20M=C3=B6llmann?= <[email-masked]>
Date: Mon, 27 Jan 2025 08:58:30 +0100
Subject: [PATCH] Use read-key in read-multiple-choice (bug#75886)

* lisp/emacs-lisp/rmc.el (read-multiple-choice--short-answers):
Use read-key instead of read-event because read-event doesn't
use input-decode-map.
---
 lisp/emacs-lisp/rmc.el | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/lisp/emacs-lisp/rmc.el b/lisp/emacs-lisp/rmc.el
index ad3c86cfd00..63f97fb006e 100644
--- a/lisp/emacs-lisp/rmc.el
+++ b/lisp/emacs-lisp/rmc.el
@@ -219,8 +219,11 @@ read-multiple-choice--short-answers
                                     (car elem)))
                             prompt-choices)))
                   (condition-case nil
-                      (let ((cursor-in-echo-area t))
-                        (read-event))
+                      (let ((cursor-in-echo-area t)
+                            (key (read-key)))
+                        (when (eq key ?\C-g)
+                          (signal 'quit nil))
+                        key)
                     (error nil))))
           (if (memq (car-safe tchar) '(touchscreen-begin
                                        touchscreen-end
-- 
2.48.1