Subject: 31.0.50; read-multiple-choice / read-key and input-decode-map

From: Gerd Möllmann <[email-masked]>
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.