Subject: Re: bug#69342: query-replace: ignore events not binded in query-replace-map

From: Juri Linkov <[email-masked]>
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