unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#69342: query-replace: ignore events not binded in query-replace-map
@ 2024-02-23 22:16 Gabriele Nicolardi
       [not found] ` <handler.69342.B.170872663926258.ack@debbugs.gnu.org>
  2024-02-25  7:28 ` bug#69342: query-replace: ignore events not binded in query-replace-map Juri Linkov
  0 siblings, 2 replies; 6+ messages in thread
From: Gabriele Nicolardi @ 2024-02-23 22:16 UTC (permalink / raw)
  To: 69342

[-- Attachment #1: Type: text/plain, Size: 1329 bytes --]

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

​

[-- Attachment #2: Type: text/html, Size: 6754 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#69342: Acknowledgement (query-replace: ignore events not binded in query-replace-map)
       [not found] ` <handler.69342.B.170872663926258.ack@debbugs.gnu.org>
@ 2024-02-23 22:33   ` Gabriele Nicolardi
  0 siblings, 0 replies; 6+ messages in thread
From: Gabriele Nicolardi @ 2024-02-23 22:33 UTC (permalink / raw)
  To: 69342

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@gnu.org
>
> If you wish to submit further information on this problem, please
> send it to 69342@debbugs.gnu.org.
>
> Please do not send mail to help-debbugs@gnu.org unless you wish
> to report a problem with the Bug-tracking system.
>





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#69342: query-replace: ignore events not binded in query-replace-map
  2024-02-23 22:16 bug#69342: query-replace: ignore events not binded in query-replace-map Gabriele Nicolardi
       [not found] ` <handler.69342.B.170872663926258.ack@debbugs.gnu.org>
@ 2024-02-25  7:28 ` Juri Linkov
  2024-02-25  8:19   ` Gabriele Nicolardi
  2024-03-02 17:22   ` Juri Linkov
  1 sibling, 2 replies; 6+ messages in thread
From: Juri Linkov @ 2024-02-25  7:28 UTC (permalink / raw)
  To: Gabriele Nicolardi; +Cc: 69342

> (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





^ permalink raw reply related	[flat|nested] 6+ messages in thread

* bug#69342: query-replace: ignore events not binded in query-replace-map
  2024-02-25  7:28 ` bug#69342: query-replace: ignore events not binded in query-replace-map Juri Linkov
@ 2024-02-25  8:19   ` Gabriele Nicolardi
  2024-02-29 17:34     ` Juri Linkov
  2024-03-02 17:22   ` Juri Linkov
  1 sibling, 1 reply; 6+ messages in thread
From: Gabriele Nicolardi @ 2024-02-25  8:19 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 69342

[-- Attachment #1: Type: text/plain, Size: 2240 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 3118 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#69342: query-replace: ignore events not binded in query-replace-map
  2024-02-25  8:19   ` Gabriele Nicolardi
@ 2024-02-29 17:34     ` Juri Linkov
  0 siblings, 0 replies; 6+ messages in thread
From: Juri Linkov @ 2024-02-29 17:34 UTC (permalink / raw)
  To: Gabriele Nicolardi; +Cc: 69342

> 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.





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#69342: query-replace: ignore events not binded in query-replace-map
  2024-02-25  7:28 ` bug#69342: query-replace: ignore events not binded in query-replace-map Juri Linkov
  2024-02-25  8:19   ` Gabriele Nicolardi
@ 2024-03-02 17:22   ` Juri Linkov
  1 sibling, 0 replies; 6+ messages in thread
From: Juri Linkov @ 2024-03-02 17:22 UTC (permalink / raw)
  To: Gabriele Nicolardi; +Cc: 69342

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.





^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-03-02 17:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-23 22:16 bug#69342: query-replace: ignore events not binded in query-replace-map Gabriele Nicolardi
     [not found] ` <handler.69342.B.170872663926258.ack@debbugs.gnu.org>
2024-02-23 22:33   ` bug#69342: Acknowledgement (query-replace: ignore events not binded in query-replace-map) Gabriele Nicolardi
2024-02-25  7:28 ` bug#69342: query-replace: ignore events not binded in query-replace-map Juri Linkov
2024-02-25  8:19   ` Gabriele Nicolardi
2024-02-29 17:34     ` Juri Linkov
2024-03-02 17:22   ` Juri Linkov

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).