GNU bug report logs -
#78113
make F-keys work in perform-replace when running Emacs in terminal
Previous Next
Reported by: Toomas Rosin <toomas <at> rosin.ee>
Date: Mon, 28 Apr 2025 13:05:04 UTC
Severity: normal
Done: Stefan Monnier <monnier <at> iro.umontreal.ca>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 78113 in the body.
You can then email your comments to 78113 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#78113
; Package
emacs
.
(Mon, 28 Apr 2025 13:05:05 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Toomas Rosin <toomas <at> rosin.ee>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Mon, 28 Apr 2025 13:05:05 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
Hi,
I have found it very convenient to run replace commands (query-replace and friends) with F11 mapped to #'skip and F12 to #'act in query-replace-map. But because perform-replace reads commands via read-event, this does not work in terminal. (Pressing F11 or F12 does nothing and terminates the search.) I have modified replace.el to use read-key-sequence instead of read-event, and now my setup seems to work flawlessly in terminal too:
--- replace.el.orig
+++ replace.el
@@ -2895,7 +2895,8 @@
"%s with %s: "
(substitute-command-keys
"(\\<query-replace-map>\\[help] for help) "))
- minibuffer-prompt-properties))))
+ minibuffer-prompt-properties)))
+ (last-input-key-sequence []))
;; Unless a single contiguous chunk is selected, operate on multiple chunks.
(when region-noncontiguous-p
@@ -2916,7 +2917,7 @@
;; If last typed key in previous call of multi-buffer perform-replace
;; was `automatic-all', don't ask more questions in next files
- (when (eq (lookup-key map (vector last-input-event) t) 'automatic-all)
+ (when (eq (lookup-key map last-input-key-sequence t) 'automatic-all)
(setq query-flag nil multi-buffer t))
(cond
@@ -3092,14 +3093,14 @@
(match-substitute-replacement next-replacement
nocasify literal))
next-replacement)))
- (message message
- (query-replace-descr from-string)
- (query-replace-descr replacement-presentation)))
- (setq key (read-event))
+ (setq key (read-key-sequence
+ (format message
+ (query-replace-descr from-string)
+ (query-replace-descr replacement-presentation))))
+ (setq last-input-key-sequence key))
;; Necessary in case something happens during
;; read-event that clobbers the match data.
(set-match-data real-match-data)
- (setq key (vector key))
(setq def (lookup-key map key t))
;; Restore the match data while we process the command.
(cond ((eq def 'help)
Best regards,
T.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#78113
; Package
emacs
.
(Sat, 03 May 2025 09:07:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 78113 <at> debbugs.gnu.org (full text, mbox):
> From: Toomas Rosin <toomas <at> rosin.ee>
> Date: Mon, 28 Apr 2025 15:53:58 +0300
>
> Hi,
>
> I have found it very convenient to run replace commands (query-replace and friends) with F11 mapped to #'skip and F12 to #'act in query-replace-map. But because perform-replace reads commands via read-event, this does not work in terminal. (Pressing F11 or F12 does nothing and terminates the search.) I have modified replace.el to use read-key-sequence instead of read-event, and now my setup seems to work flawlessly in terminal too:
>
> --- replace.el.orig
> +++ replace.el
> @@ -2895,7 +2895,8 @@
> "%s with %s: "
> (substitute-command-keys
> "(\\<query-replace-map>\\[help] for help) "))
> - minibuffer-prompt-properties))))
> + minibuffer-prompt-properties)))
> + (last-input-key-sequence []))
>
> ;; Unless a single contiguous chunk is selected, operate on multiple chunks.
> (when region-noncontiguous-p
> @@ -2916,7 +2917,7 @@
>
> ;; If last typed key in previous call of multi-buffer perform-replace
> ;; was `automatic-all', don't ask more questions in next files
> - (when (eq (lookup-key map (vector last-input-event) t) 'automatic-all)
> + (when (eq (lookup-key map last-input-key-sequence t) 'automatic-all)
> (setq query-flag nil multi-buffer t))
>
> (cond
> @@ -3092,14 +3093,14 @@
> (match-substitute-replacement next-replacement
> nocasify literal))
> next-replacement)))
> - (message message
> - (query-replace-descr from-string)
> - (query-replace-descr replacement-presentation)))
> - (setq key (read-event))
> + (setq key (read-key-sequence
> + (format message
> + (query-replace-descr from-string)
> + (query-replace-descr replacement-presentation))))
> + (setq last-input-key-sequence key))
> ;; Necessary in case something happens during
> ;; read-event that clobbers the match data.
> (set-match-data real-match-data)
> - (setq key (vector key))
> (setq def (lookup-key map key t))
> ;; Restore the match data while we process the command.
> (cond ((eq def 'help)
>
> Best regards,
> T.
Stefan and Juri, any comments?
As usual, when replacing one input function by another, there be
dragons. So if there's a safer way of fixing this, which would not
affect every other use case with replace commands, I'd prefer that.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#78113
; Package
emacs
.
(Sat, 03 May 2025 14:31:01 GMT)
Full text and
rfc822 format available.
Message #11 received at 78113 <at> debbugs.gnu.org (full text, mbox):
>> @@ -3092,14 +3093,14 @@
>> (match-substitute-replacement next-replacement
>> nocasify literal))
>> next-replacement)))
>> - (message message
>> - (query-replace-descr from-string)
>> - (query-replace-descr replacement-presentation)))
>> - (setq key (read-event))
>> + (setq key (read-key-sequence
>> + (format message
>> + (query-replace-descr from-string)
>> + (query-replace-descr replacement-presentation))))
>> + (setq last-input-key-sequence key))
> Stefan and Juri, any comments?
I generally like the direction this is going.
> As usual, when replacing one input function by another, there be
> dragons. So if there's a safer way of fixing this, which would not
> affect every other use case with replace commands, I'd prefer that.
Using `read-key` instead of `read-key-sequence` should also allow the
use of F-keys (and arrow keys, ...) but would minimize the differences
with `read-event` (since `read-key` is exactly that: a wrapper around
`read-key-sequence` which tries to minimize the differences with
`read-event`).
Stefan
@@ -3091,18 +3091,18 @@ perform-replace
next-replacement nocasify literal))))
;; Bind message-log-max so we don't fill up the
;; message log with a bunch of identical messages.
- (let ((message-log-max nil)
- (replacement-presentation
- (if query-replace-show-replacement
- (save-match-data
- (set-match-data real-match-data)
- (match-substitute-replacement next-replacement
- nocasify literal))
- next-replacement)))
- (message message
- (query-replace-descr from-string)
- (query-replace-descr replacement-presentation)))
- (setq key (read-event))
+ (let* ((replacement-presentation
+ (if query-replace-show-replacement
+ (save-match-data
+ (set-match-data real-match-data)
+ (match-substitute-replacement next-replacement
+ nocasify literal))
+ next-replacement))
+ (prompt
+ (format message
+ (query-replace-descr from-string)
+ (query-replace-descr replacement-presentation))))
+ (setq key (read-key prompt)))
;; Necessary in case something happens during
;; read-event that clobbers the match data.
(set-match-data real-match-data)
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#78113
; Package
emacs
.
(Sat, 17 May 2025 08:13:03 GMT)
Full text and
rfc822 format available.
Message #14 received at 78113 <at> debbugs.gnu.org (full text, mbox):
Ping! How should we proceed with this issue?
> From: Stefan Monnier <monnier <at> iro.umontreal.ca>
> Cc: Toomas Rosin <toomas <at> rosin.ee>, Juri Linkov <juri <at> linkov.net>,
> 78113 <at> debbugs.gnu.org
> Date: Sat, 03 May 2025 10:30:43 -0400
>
> >> @@ -3092,14 +3093,14 @@
> >> (match-substitute-replacement next-replacement
> >> nocasify literal))
> >> next-replacement)))
> >> - (message message
> >> - (query-replace-descr from-string)
> >> - (query-replace-descr replacement-presentation)))
> >> - (setq key (read-event))
> >> + (setq key (read-key-sequence
> >> + (format message
> >> + (query-replace-descr from-string)
> >> + (query-replace-descr replacement-presentation))))
> >> + (setq last-input-key-sequence key))
>
> > Stefan and Juri, any comments?
>
> I generally like the direction this is going.
>
> > As usual, when replacing one input function by another, there be
> > dragons. So if there's a safer way of fixing this, which would not
> > affect every other use case with replace commands, I'd prefer that.
>
> Using `read-key` instead of `read-key-sequence` should also allow the
> use of F-keys (and arrow keys, ...) but would minimize the differences
> with `read-event` (since `read-key` is exactly that: a wrapper around
> `read-key-sequence` which tries to minimize the differences with
> `read-event`).
>
>
> Stefan
>
>
> @@ -3091,18 +3091,18 @@ perform-replace
> next-replacement nocasify literal))))
> ;; Bind message-log-max so we don't fill up the
> ;; message log with a bunch of identical messages.
> - (let ((message-log-max nil)
> - (replacement-presentation
> - (if query-replace-show-replacement
> - (save-match-data
> - (set-match-data real-match-data)
> - (match-substitute-replacement next-replacement
> - nocasify literal))
> - next-replacement)))
> - (message message
> - (query-replace-descr from-string)
> - (query-replace-descr replacement-presentation)))
> - (setq key (read-event))
> + (let* ((replacement-presentation
> + (if query-replace-show-replacement
> + (save-match-data
> + (set-match-data real-match-data)
> + (match-substitute-replacement next-replacement
> + nocasify literal))
> + next-replacement))
> + (prompt
> + (format message
> + (query-replace-descr from-string)
> + (query-replace-descr replacement-presentation))))
> + (setq key (read-key prompt)))
> ;; Necessary in case something happens during
> ;; read-event that clobbers the match data.
> (set-match-data real-match-data)
>
>
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#78113
; Package
emacs
.
(Wed, 21 May 2025 20:11:02 GMT)
Full text and
rfc822 format available.
Message #17 received at 78113 <at> debbugs.gnu.org (full text, mbox):
> Ping! How should we proceed with this issue?
Any objection to installing my patch?
Stefan
>> From: Stefan Monnier <monnier <at> iro.umontreal.ca>
>> Cc: Toomas Rosin <toomas <at> rosin.ee>, Juri Linkov <juri <at> linkov.net>,
>> 78113 <at> debbugs.gnu.org
>> Date: Sat, 03 May 2025 10:30:43 -0400
>>
>> >> @@ -3092,14 +3093,14 @@
>> >> (match-substitute-replacement next-replacement
>> >> nocasify literal))
>> >> next-replacement)))
>> >> - (message message
>> >> - (query-replace-descr from-string)
>> >> - (query-replace-descr replacement-presentation)))
>> >> - (setq key (read-event))
>> >> + (setq key (read-key-sequence
>> >> + (format message
>> >> + (query-replace-descr from-string)
>> >> + (query-replace-descr replacement-presentation))))
>> >> + (setq last-input-key-sequence key))
>>
>> > Stefan and Juri, any comments?
>>
>> I generally like the direction this is going.
>>
>> > As usual, when replacing one input function by another, there be
>> > dragons. So if there's a safer way of fixing this, which would not
>> > affect every other use case with replace commands, I'd prefer that.
>>
>> Using `read-key` instead of `read-key-sequence` should also allow the
>> use of F-keys (and arrow keys, ...) but would minimize the differences
>> with `read-event` (since `read-key` is exactly that: a wrapper around
>> `read-key-sequence` which tries to minimize the differences with
>> `read-event`).
>>
>>
>> Stefan
>>
>>
>> @@ -3091,18 +3091,18 @@ perform-replace
>> next-replacement nocasify literal))))
>> ;; Bind message-log-max so we don't fill up the
>> ;; message log with a bunch of identical messages.
>> - (let ((message-log-max nil)
>> - (replacement-presentation
>> - (if query-replace-show-replacement
>> - (save-match-data
>> - (set-match-data real-match-data)
>> - (match-substitute-replacement next-replacement
>> - nocasify literal))
>> - next-replacement)))
>> - (message message
>> - (query-replace-descr from-string)
>> - (query-replace-descr replacement-presentation)))
>> - (setq key (read-event))
>> + (let* ((replacement-presentation
>> + (if query-replace-show-replacement
>> + (save-match-data
>> + (set-match-data real-match-data)
>> + (match-substitute-replacement next-replacement
>> + nocasify literal))
>> + next-replacement))
>> + (prompt
>> + (format message
>> + (query-replace-descr from-string)
>> + (query-replace-descr replacement-presentation))))
>> + (setq key (read-key prompt)))
>> ;; Necessary in case something happens during
>> ;; read-event that clobbers the match data.
>> (set-match-data real-match-data)
>>
>>
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#78113
; Package
emacs
.
(Thu, 22 May 2025 05:02:02 GMT)
Full text and
rfc822 format available.
Message #20 received at 78113 <at> debbugs.gnu.org (full text, mbox):
> From: Stefan Monnier <monnier <at> iro.umontreal.ca>
> Cc: toomas <at> rosin.ee, juri <at> linkov.net, 78113 <at> debbugs.gnu.org
> Date: Wed, 21 May 2025 16:10:19 -0400
>
> > Ping! How should we proceed with this issue?
>
> Any objection to installing my patch?
I wasn't aware you suggested a patch. You've posted what looks like
part of a diff, not a full one. Also, you removed binding
message-log-max (why?), so the comment before the code no longer
describes what the code does.
Other than that, if you feel lucky and/or bold, and you've run all the
relevant tests without any failures, feel free to install, and let's
see what will be broken as result ;-)
P.S. The known "dark corners" with reading keyboard input are keyboard
macros and input methods. I hope you've tried this code when those
are used.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#78113
; Package
emacs
.
(Thu, 22 May 2025 12:53:02 GMT)
Full text and
rfc822 format available.
Message #23 received at 78113 <at> debbugs.gnu.org (full text, mbox):
>> Any objection to installing my patch?
> I wasn't aware you suggested a patch. You've posted what looks like
> part of a diff, not a full one.
Indeed, I see I cut off the beginning for some reason.
I think I had other local changes and just grabbed the relevant part of
the diff rather than remove the other hunks.
> Also, you removed binding message-log-max (why?),
Because the new code doesn't use `message` any more (it uses
a `read-key-sequence` prompt instead), so there's no need to prevent
inserting the message into the log.
> so the comment before the code no longer describes what the code does.
Indeed, I have removed it since sending the patch-hunk.
> Other than that, if you feel lucky and/or bold,
That would be me.
> and you've run all the relevant tests without any failures, feel free
> to install, and let's see what will be broken as result ;-)
Yay!
> P.S. The known "dark corners" with reading keyboard input are keyboard
> macros and input methods. I hope you've tried this code when those
> are used.
I did. I think the dark corners there depend on more than just "being
used" so the opportunities for problems are much too rich for my testing
to provide much guarantee, but at least my testing suggested that kbd
macros should work fine just as before, and that input methods already
have the same weird interaction before my patch as after my patch
(e.g. when query&replace prompts to do the replacement or not or exit
..., if I hit \ (in TeX input-method) it just seems to immediately exit
the Q&R).
Stefan
Reply sent
to
Stefan Monnier <monnier <at> iro.umontreal.ca>
:
You have taken responsibility.
(Thu, 22 May 2025 13:35:02 GMT)
Full text and
rfc822 format available.
Notification sent
to
Toomas Rosin <toomas <at> rosin.ee>
:
bug acknowledged by developer.
(Thu, 22 May 2025 13:35:03 GMT)
Full text and
rfc822 format available.
Message #28 received at 78113-done <at> debbugs.gnu.org (full text, mbox):
Pushed, closing,
Stefan
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Fri, 20 Jun 2025 11:24:08 GMT)
Full text and
rfc822 format available.
This bug report was last modified 15 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.