GNU bug report logs - #69342
query-replace: ignore events not binded in query-replace-map

Previous Next

Package: emacs;

Reported by: Gabriele Nicolardi <gabriele <at> medialab.sissa.it>

Date: Fri, 23 Feb 2024 22:18:01 UTC

Severity: normal

Fixed in version 30.0.50

Done: Juri Linkov <juri <at> linkov.net>

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 69342 in the body.
You can then email your comments to 69342 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#69342; Package emacs. (Fri, 23 Feb 2024 22:18:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Gabriele Nicolardi <gabriele <at> medialab.sissa.it>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Fri, 23 Feb 2024 22:18:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Gabriele Nicolardi <gabriele <at> medialab.sissa.it>
To: bug-gnu-emacs <at> gnu.org
Subject: query-replace: ignore events not binded in query-replace-map
Date: Fri, 23 Feb 2024 23:16:15 +0100
[Message part 1 (text/plain, inline)]
Hi,

I have this function:

|(defun my-replacements () (interactive) (query-replace "foo" "bar" nil 
(point-min) (point-max)) (query-replace "baz" "quz" nil (point-min) 
(point-max)) (query-replace "fred" "thud" nil (point-min) (point-max))) |

If I run it and accidentally type, for example, ‘k’ during one of the 
replacements, the function is interrupted, skipping all the remaining 
replacements.

I know that |query-replace| (and |query-replace-regexp|) accepts only 
events binded in the |query-replace-map| and from the manual I know that:

   Aside from this, any other character exits the query-replace, and is
   then reread as part of a key sequence. Thus, if you type C-k, it exits
   the query-replace and then kills to end of line. In particular, C-g
   simply exits the query-replace.

I would like to circumvent this behavior by ensuring that events not 
defined in the |query-replace-map| are simply ignored. Is there a way to 
achieve this?

I thought it could be done with a macro, e.g.:

|(with-ignore-qr-unbinded-events MY CODE HERE) |

but I have no idea how to do it.

As a feature request (this would be my first choice), I would like to 
add an optional argument to the function(s) so that I can have control 
over this behavior. Does it make sense to you?

Best regards,

Gabriele Nicolardi

​
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69342; Package emacs. (Fri, 23 Feb 2024 22:35:02 GMT) Full text and rfc822 format available.

Message #8 received at 69342 <at> debbugs.gnu.org (full text, mbox):

From: Gabriele Nicolardi <gabriele <at> medialab.sissa.it>
To: 69342 <at> debbugs.gnu.org
Subject: Re: bug#69342: Acknowledgement (query-replace: ignore events not
 binded in query-replace-map)
Date: Fri, 23 Feb 2024 23:33:29 +0100
I just realized that a better idea would be using a variable to control 
this feature i request.

Best regards

Gabriele Nicolardi

Il 23/02/24 23:18, GNU bug Tracking System ha scritto:
> Thank you for filing a new bug report with debbugs.gnu.org.
>
> This is an automatically generated reply to let you know your message
> has been received.
>
> Your message is being forwarded to the package maintainers and other
> interested parties for their attention; they will reply in due course.
>
> Your message has been sent to the package maintainer(s):
>   bug-gnu-emacs <at> gnu.org
>
> If you wish to submit further information on this problem, please
> send it to 69342 <at> debbugs.gnu.org.
>
> Please do not send mail to help-debbugs <at> gnu.org unless you wish
> to report a problem with the Bug-tracking system.
>




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69342; Package emacs. (Sun, 25 Feb 2024 07:36:02 GMT) Full text and rfc822 format available.

Message #11 received at 69342 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Gabriele Nicolardi <gabriele <at> medialab.sissa.it>
Cc: 69342 <at> debbugs.gnu.org
Subject: Re: bug#69342: query-replace: ignore events not binded in
 query-replace-map
Date: Sun, 25 Feb 2024 09:28:52 +0200
> (defun my-replacements ()
>   (interactive)
>   (query-replace "foo" "bar" nil (point-min) (point-max))
>   (query-replace "baz" "quz" nil (point-min) (point-max))
>   (query-replace "fred" "thud" nil (point-min) (point-max)))
> [...]
> As a feature request (this would be my first choice), I would like to add
> an optional argument to the function(s) so that I can have control over
> this behavior. Does it make sense to you?

Thanks for the feature request.  Or maybe this is a bug report,
since currently query-replace doesn't allow you using such a simple
configuration to ignore all unbound keys:

  (define-key query-replace-map [t] 'ignore)

To give you the freedom of using such configuration we need
to set the optional argument ACCEPT-DEFAULTS of 'lookup-key' to t
with this patch:

diff --git a/lisp/replace.el b/lisp/replace.el
index f8f5c415273..750ca9c1ee3 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -2924,7 +2924,7 @@ perform-replace
 
     ;; 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)) 'automatic-all)
+    (when (eq (lookup-key map (vector last-input-event) t) 'automatic-all)
       (setq query-flag nil multi-buffer t))
 
     (cond
@@ -3111,7 +3111,7 @@ perform-replace
 		  ;; read-event that clobbers the match data.
 		  (set-match-data real-match-data)
 		  (setq key (vector key))
-		  (setq def (lookup-key map key))
+		  (setq def (lookup-key map key t))
 		  ;; Restore the match data while we process the command.
 		  (cond ((eq def 'help)
 			 (let ((display-buffer-overriding-action




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69342; Package emacs. (Sun, 25 Feb 2024 08:56:02 GMT) Full text and rfc822 format available.

Message #14 received at 69342 <at> debbugs.gnu.org (full text, mbox):

From: Gabriele Nicolardi <gabriele <at> medialab.sissa.it>
To: Juri Linkov <juri <at> linkov.net>
Cc: 69342 <at> debbugs.gnu.org
Subject: Re: bug#69342: query-replace: ignore events not binded in
 query-replace-map
Date: Sun, 25 Feb 2024 09:19:29 +0100
[Message part 1 (text/plain, inline)]
Thanks!

I suppose this feature will be available starting from Emacs version 30, 
right?

In the meantime, I was suggested this code on StackExchange 
(https://emacs.stackexchange.com/a/80494/15606):

|(defvar my-do-nothing-map (let ((map (make-keymap))) 
(set-char-table-range (nth 1 map) t 'ignore) map)) (set-keymap-parent 
query-replace-map my-do-nothing-map) and it seems to work with the 
actual version of query-replace. |

Il 25/02/24 08:28, Juri Linkov ha scritto:
>> (defun my-replacements ()
>>    (interactive)
>>    (query-replace "foo" "bar" nil (point-min) (point-max))
>>    (query-replace "baz" "quz" nil (point-min) (point-max))
>>    (query-replace "fred" "thud" nil (point-min) (point-max)))
>> [...]
>> As a feature request (this would be my first choice), I would like to add
>> an optional argument to the function(s) so that I can have control over
>> this behavior. Does it make sense to you?
> Thanks for the feature request.  Or maybe this is a bug report,
> since currently query-replace doesn't allow you using such a simple
> configuration to ignore all unbound keys:
>
>    (define-key query-replace-map [t] 'ignore)
>
> To give you the freedom of using such configuration we need
> to set the optional argument ACCEPT-DEFAULTS of 'lookup-key' to t
> with this patch:
>
> diff --git a/lisp/replace.el b/lisp/replace.el
> index f8f5c415273..750ca9c1ee3 100644
> --- a/lisp/replace.el
> +++ b/lisp/replace.el
> @@ -2924,7 +2924,7 @@ perform-replace
>   
>       ;; 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)) 'automatic-all)
> +    (when (eq (lookup-key map (vector last-input-event) t) 'automatic-all)
>         (setq query-flag nil multi-buffer t))
>   
>       (cond
> @@ -3111,7 +3111,7 @@ perform-replace
>   		  ;; read-event that clobbers the match data.
>   		  (set-match-data real-match-data)
>   		  (setq key (vector key))
> -		  (setq def (lookup-key map key))
> +		  (setq def (lookup-key map key t))
>   		  ;; Restore the match data while we process the command.
>   		  (cond ((eq def 'help)
>   			 (let ((display-buffer-overriding-action
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69342; Package emacs. (Thu, 29 Feb 2024 17:51:02 GMT) Full text and rfc822 format available.

Message #17 received at 69342 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Gabriele Nicolardi <gabriele <at> medialab.sissa.it>
Cc: 69342 <at> debbugs.gnu.org
Subject: Re: bug#69342: query-replace: ignore events not binded in
 query-replace-map
Date: Thu, 29 Feb 2024 19:34:19 +0200
> I suppose this feature will be available starting from Emacs version 30,
> right?

Yes, not before the next release.

> In the meantime, I was suggested this code on StackExchange
> (https://emacs.stackexchange.com/a/80494/15606):
>
> (defvar my-do-nothing-map
>   (let ((map (make-keymap)))
>     (set-char-table-range (nth 1 map) t 'ignore)
>     map))
>
> (set-keymap-parent query-replace-map my-do-nothing-map)
>
> and it seems to work with the actual version of query-replace.

Interesting hack.

> @@ -3111,7 +3111,7 @@ perform-replace
>  		  ;; read-event that clobbers the match data.
>  		  (set-match-data real-match-data)
>  		  (setq key (vector key))
> -		  (setq def (lookup-key map key))
> +		  (setq def (lookup-key map key t))
>  		  ;; Restore the match data while we process the command.
>  		  (cond ((eq def 'help)
>  			 (let ((display-buffer-overriding-action

Still this could be fixed as well.  Only one thing that I don't understand
is why lookup-key ignores bindings for [t] by default.  This requires adding
ACCEPT-DEFAULT=t to all calls.  But ok, this can't be changed now.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69342; Package emacs. (Sat, 02 Mar 2024 17:25:01 GMT) Full text and rfc822 format available.

Message #20 received at 69342 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Gabriele Nicolardi <gabriele <at> medialab.sissa.it>
Cc: 69342 <at> debbugs.gnu.org
Subject: Re: bug#69342: query-replace: ignore events not binded in
 query-replace-map
Date: Sat, 02 Mar 2024 19:22:38 +0200
close 69342 30.0.50
thanks

> Thanks for the feature request.  Or maybe this is a bug report,
> since currently query-replace doesn't allow you using such a simple
> configuration to ignore all unbound keys:
>
>   (define-key query-replace-map [t] 'ignore)
>
> To give you the freedom of using such configuration we need
> to set the optional argument ACCEPT-DEFAULTS of 'lookup-key' to t
> with this patch:

Now the patch is pushed to master, so you can use this in Emacs 30.




bug marked as fixed in version 30.0.50, send any further explanations to 69342 <at> debbugs.gnu.org and Gabriele Nicolardi <gabriele <at> medialab.sissa.it> Request was from Juri Linkov <juri <at> linkov.net> to control <at> debbugs.gnu.org. (Sat, 02 Mar 2024 17:25:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 31 Mar 2024 11:24:10 GMT) Full text and rfc822 format available.

This bug report was last modified 1 year and 136 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.