Subject: Re: bug#78916: 31.0.50; C-g fails to exit loop

From: Pip Cet <[email-masked]>
Date: Sun, 06 Jul 2025 11:12:49 +0000

"Stefan Monnier" <[email-masked]> writes:

>>>> (However, there are other good reason not to apply this patch, and
>>>> simply fix read-key to optionally allow quitting instead.
>>>
>>> The way I see it, part of this bug-report points out a bug in Q&R which
>>> applies not just to `C-g` but also to `C-]`, i.e. to any key bound to
>>> `quit` in `query-replace-map`, so what you suggest would just
>>> re-circumvent that bug for the `C-g` case, leaving the other case broken.
>>
>> Serious question: doesn't it apply to ESC, too?  It's exit-prefix, not
>> quit, but rereading it over and over again also breaks Mike's loop, I
>> think.
>
> ESC is bound to `exit-prefix` which is documented as:
>
>     ‘exit-prefix’
>          Like ‘exit’, but add the key that was pressed to
>          ‘unread-command-events’ (*note Event Input Misc::).
>
> so it looks OK to me: maybe it's not the behavior Mike would prefer, but
> at least it's in line with what the doc says.

I think I'm terminally confused now.

I'm fine with ESC and C-] behaving in whatever way seems best to the
rest of you.

They're not mentioned in query-replace-help, and they're not mentioned
in emacs.info, so the only way to get an idea (correct or incorrect) of
how they behave is to read some Lisp (inspect a variable, at least) as
well as some of the documentation, right?

So I no longer think there are good reasons not to apply this patch;
some further work seems necessary (see below), but fixing this bug
should have priority.

We might want to consider offering a customization option to disable the
entire "unhandled commands cause an exit and get reread" behavior.  It
seems extremely surprising to me, and it means any addition to
query-replace-map will break someone's muscle memory.

I'm still thinking about whether it's really the right thing to give
read-key a "quit" argument; we might want to invoke keyboard-quit
instead (this would require fixing the interrupted-timer thing), or we
might want to use new functions (read-key-sequence already has five
optional arguments, making it painful to use from Lisp even with eldoc).

Pip