GNU bug report logs -
#75886
31.0.50; read-multiple-choice / read-key and input-decode-map
Previous Next
To reply to this bug, email your comments to 75886 AT debbugs.gnu.org.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#75886
; Package
emacs
.
(Mon, 27 Jan 2025 06:09:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Gerd Möllmann <gerd.moellmann <at> gmail.com>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Mon, 27 Jan 2025 06:09:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
I am running emacs -nw on a terminal supporting the Kitty Keyboard
Protocol, and I am using the kkp package from MELPA to make use of the
additional keys KKP makes possible to use.
Must know:
1. Kkp works by adding entries to input-decode-map, among them a binding
for C-g, which arrives from the terminal as an escape sequence which
input-decode-map maps to ^G.
2. read-event does not consult input-decode-map:
#+begin_src eemacs-lisp
(read-event) ;; press C-g
=> 27
[103;5u
#+end_src
3. read-multiple-choice uses read-event.
Bug 1:
Modify a buffer and C-x k it. A prompt appears asking what to do. The
prompt comes from read-multiple-choice. Press C-g. That results in
"invalid choice" because read-multiple-choice gets (part of) the escape
sequence the terminal sends from read-event.
Bug 2:
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.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#75886
; Package
emacs
.
(Mon, 27 Jan 2025 06:59:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 75886 <at> debbugs.gnu.org (full text, mbox):
Gerd Möllmann <gerd.moellmann <at> gmail.com> 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
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#75886
; Package
emacs
.
(Mon, 27 Jan 2025 08:05:02 GMT)
Full text and
rfc822 format available.
Message #11 received at 75886 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Gerd Möllmann <gerd.moellmann <at> gmail.com> writes:
> Gerd Möllmann <gerd.moellmann <at> gmail.com> 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.
[0001-Use-read-key-in-read-multiple-choice-bug-75886.patch (text/x-patch, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#75886
; Package
emacs
.
(Mon, 27 Jan 2025 12:39:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 75886 <at> debbugs.gnu.org (full text, mbox):
> From: Gerd Möllmann <gerd.moellmann <at> gmail.com>
> Date: Mon, 27 Jan 2025 07:07:46 +0100
>
> I am running emacs -nw on a terminal supporting the Kitty Keyboard
> Protocol, and I am using the kkp package from MELPA to make use of the
> additional keys KKP makes possible to use.
>
> Must know:
>
> 1. Kkp works by adding entries to input-decode-map, among them a binding
> for C-g, which arrives from the terminal as an escape sequence which
> input-decode-map maps to ^G.
>
> 2. read-event does not consult input-decode-map:
>
> #+begin_src eemacs-lisp
> (read-event) ;; press C-g
> => 27
> [103;5u
> #+end_src
>
> 3. read-multiple-choice uses read-event.
>
> Bug 1:
>
> Modify a buffer and C-x k it. A prompt appears asking what to do. The
> prompt comes from read-multiple-choice. Press C-g. That results in
> "invalid choice" because read-multiple-choice gets (part of) the escape
> sequence the terminal sends from read-event.
>
> Bug 2:
>
> 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.
This is a dark corner in Emacs, so I'm adding Stefan to the discussion
in the hope that he might have comments and ideas to suggest.
Thanks.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#75886
; Package
emacs
.
(Sun, 02 Feb 2025 23:26:02 GMT)
Full text and
rfc822 format available.
Message #17 received at 75886 <at> debbugs.gnu.org (full text, mbox):
>> I am running emacs -nw on a terminal supporting the Kitty Keyboard
>> Protocol, and I am using the kkp package from MELPA to make use of the
>> additional keys KKP makes possible to use.
>>
>> Must know:
>>
>> 1. Kkp works by adding entries to input-decode-map, among them a binding
>> for C-g, which arrives from the terminal as an escape sequence which
>> input-decode-map maps to ^G.
>>
>> 2. read-event does not consult input-decode-map:
>>
>> #+begin_src eemacs-lisp
>> (read-event) ;; press C-g
>> => 27
>> [103;5u
>> #+end_src
>>
>> 3. read-multiple-choice uses read-event.
>>
>> Bug 1:
>>
>> Modify a buffer and C-x k it. A prompt appears asking what to do. The
>> prompt comes from read-multiple-choice. Press C-g. That results in
>> "invalid choice" because read-multiple-choice gets (part of) the escape
>> sequence the terminal sends from read-event.
`read_char` usually doesn't return `C-g` but signals `quit` instead.
IOW the handling that makes `C-g` abort `C-x k` and friends is done at
a very low-level. IIRC whether it (should) return(s) `C-g` or signal(s)
quit depends on `immediate_quit` which is not reflected in ELisp.
>> Without input-decode-map for C-g.
>>
>> #+begin_src emacs-lisp
>> (read-key) ;; press C-g
>> => Quit
>> #+end_src
That's not what I see here. I get 7 (aka `C-g`) in an `emacs -Q`.
> This is a dark corner in Emacs, so I'm adding Stefan to the discussion
> in the hope that he might have comments and ideas to suggest.
Indeed `C-g` is handled (read: hard coded) at a very low-level.
Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#75886
; Package
emacs
.
(Mon, 03 Feb 2025 05:04:01 GMT)
Full text and
rfc822 format available.
Message #20 received at 75886 <at> debbugs.gnu.org (full text, mbox):
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:
>
>>> Without input-decode-map for C-g.
>>>
>>> #+begin_src emacs-lisp
>>> (read-key) ;; press C-g
>>> => Quit
>>> #+end_src
>
> That's not what I see here. I get 7 (aka `C-g`) in an `emacs -Q`.
Right, sorry. I corrected that else-mail.
>
>> This is a dark corner in Emacs, so I'm adding Stefan to the discussion
>> in the hope that he might have comments and ideas to suggest.
>
> Indeed `C-g` is handled (read: hard coded) at a very low-level.
In light of input-decode-map, it seems to me that using read-event is
always wrong. Should read-event be deprecated, maybe?
Should read-key be changed to signal quit? I find it a bit strange that
one can write Lisp that one cannot C-g out.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#75886
; Package
emacs
.
(Mon, 03 Feb 2025 11:14:02 GMT)
Full text and
rfc822 format available.
Message #23 received at 75886 <at> debbugs.gnu.org (full text, mbox):
>>> This is a dark corner in Emacs, so I'm adding Stefan to the discussion
>>> in the hope that he might have comments and ideas to suggest.
>> Indeed `C-g` is handled (read: hard coded) at a very low-level.
> In light of input-decode-map, it seems to me that using read-event is
> always wrong. Should read-event be deprecated, maybe?
I introduced `read-key` in the hope to replace `read-char` and
`read-event`. But so far it's been hard to switch existing code (some
of those switches have been reverted, for example (and often without
understanding the root of the problem)).
> Should read-key be changed to signal quit?
I think this would break the use of `C-g` to exit from the minibuffer.
Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#75886
; Package
emacs
.
(Mon, 03 Feb 2025 19:14:02 GMT)
Full text and
rfc822 format available.
Message #26 received at 75886 <at> debbugs.gnu.org (full text, mbox):
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:
>>>> This is a dark corner in Emacs, so I'm adding Stefan to the discussion
>>>> in the hope that he might have comments and ideas to suggest.
>>> Indeed `C-g` is handled (read: hard coded) at a very low-level.
>> In light of input-decode-map, it seems to me that using read-event is
>> always wrong. Should read-event be deprecated, maybe?
>
> I introduced `read-key` in the hope to replace `read-char` and
> `read-event`. But so far it's been hard to switch existing code (some
> of those switches have been reverted, for example (and often without
> understanding the root of the problem)).
>
>> Should read-key be changed to signal quit?
>
> I think this would break the use of `C-g` to exit from the minibuffer.
Too bad :-(.
Do you mind if I replace read-event with read-key in
read-multiple-choice? Maybe it sicks if I put a prominent comments why.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#75886
; Package
emacs
.
(Tue, 04 Feb 2025 13:41:02 GMT)
Full text and
rfc822 format available.
Message #29 received at 75886 <at> debbugs.gnu.org (full text, mbox):
>>> Should read-key be changed to signal quit?
>> I think this would break the use of `C-g` to exit from the minibuffer.
> Too bad :-(.
Of course, there's probably some way to fix the breakage, but basically,
it's a non-trivial change messing with a "delicate" issue (meaning one
where we currently have an undocumented balance of behaviors accumulated
over the years, and we're not even aware of it).
> Do you mind if I replace read-event with read-key in
> read-multiple-choice?
Not at all!
> Maybe it sticks if I put a prominent comments why.
I suggest you add a test for it as well (ideally in a separate commit so
`git revert` won't remove the test).
Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#75886
; Package
emacs
.
(Tue, 04 Feb 2025 14:43:02 GMT)
Full text and
rfc822 format available.
Message #32 received at 75886 <at> debbugs.gnu.org (full text, mbox):
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:
>>>> Should read-key be changed to signal quit?
>>> I think this would break the use of `C-g` to exit from the minibuffer.
>> Too bad :-(.
>
> Of course, there's probably some way to fix the breakage, but basically,
> it's a non-trivial change messing with a "delicate" issue (meaning one
> where we currently have an undocumented balance of behaviors accumulated
> over the years, and we're not even aware of it).
Yeah :-/.
>
>> Do you mind if I replace read-event with read-key in
>> read-multiple-choice?
>
> Not at all!
Now done and closing in a minute.
>> Maybe it sticks if I put a prominent comments why.
>
> I suggest you add a test for it as well (ideally in a separate commit so
> `git revert` won't remove the test).
Slick idea, but I "trust" people to not want to drive me mad :-).
bug marked as fixed in version 31.1, send any further explanations to
75886 <at> debbugs.gnu.org and Gerd Möllmann <gerd.moellmann <at> gmail.com>
Request was from
Gerd Möllmann <gerd.moellmann <at> gmail.com>
to
control <at> debbugs.gnu.org
.
(Tue, 04 Feb 2025 14:43:02 GMT)
Full text and
rfc822 format available.
bug No longer marked as fixed in versions 31.1 and reopened.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Thu, 06 Feb 2025 04:24:01 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#75886
; Package
emacs
.
(Thu, 06 Feb 2025 04:31:02 GMT)
Full text and
rfc822 format available.
Message #39 received at 75886 <at> debbugs.gnu.org (full text, mbox):
Re-opened because map-y-or-n-p has the exact same problem.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#75886
; Package
emacs
.
(Fri, 13 Jun 2025 15:29:03 GMT)
Full text and
rfc822 format available.
Message #42 received at 75886 <at> debbugs.gnu.org (full text, mbox):
> 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
LGTM,
Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#75886
; Package
emacs
.
(Sat, 14 Jun 2025 03:45:04 GMT)
Full text and
rfc822 format available.
Message #45 received at 75886 <at> debbugs.gnu.org (full text, mbox):
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:
>> 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
>
> LGTM,
>
>
> Stefan
Thanks.
This bug report was last modified 57 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.