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

From: Gabriele Nicolardi <[email-masked]>
Date: Sun, 25 Feb 2024 09:19:29 +0100

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