From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Gabriele Nicolardi Newsgroups: gmane.emacs.bugs Subject: bug#69342: query-replace: ignore events not binded in query-replace-map Date: Sun, 25 Feb 2024 09:19:29 +0100 Message-ID: <93c69078-769f-460f-bfb6-4e942af7e102@medialab.sissa.it> References: <864jdx11qx.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="------------RXCD10SIDoJ95JzzYr5Ozq2f" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12401"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird Cc: 69342@debbugs.gnu.org To: Juri Linkov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Feb 25 09:55:53 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1reAIb-0002yt-AD for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 25 Feb 2024 09:55:53 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1reAIR-0002q1-PC; Sun, 25 Feb 2024 03:55:43 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1reAIQ-0002pq-1K for bug-gnu-emacs@gnu.org; Sun, 25 Feb 2024 03:55:42 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1reAIL-0007bu-Rd for bug-gnu-emacs@gnu.org; Sun, 25 Feb 2024 03:55:41 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1reAIk-0004T9-3J for bug-gnu-emacs@gnu.org; Sun, 25 Feb 2024 03:56:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Gabriele Nicolardi Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 25 Feb 2024 08:56:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 69342 X-GNU-PR-Package: emacs Original-Received: via spool by 69342-submit@debbugs.gnu.org id=B69342.170885132717074 (code B ref 69342); Sun, 25 Feb 2024 08:56:02 +0000 Original-Received: (at 69342) by debbugs.gnu.org; 25 Feb 2024 08:55:27 +0000 Original-Received: from localhost ([127.0.0.1]:55580 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1reAI9-0004RH-Oj for submit@debbugs.gnu.org; Sun, 25 Feb 2024 03:55:27 -0500 Original-Received: from smtp06.cbsolt.net ([185.97.217.45]:46798) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1re9jt-0002iQ-S0 for 69342@debbugs.gnu.org; Sun, 25 Feb 2024 03:20:03 -0500 Original-Received: from [10.0.2.15] (host-79-16-242-199.retail.telecomitalia.it [79.16.242.199]) by smtp06.cbsolt.net (Postfix) with ESMTPSA id 4TjGr21102z3whm; Sun, 25 Feb 2024 09:19:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cbsolt.net; s=201504-di4k2w; t=1708849171; bh=sEX2vgLVqaPi3jjLHk1862qBIRNjkld5zB52KgSdkTw=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=RfBh3tMF31nNQ7VjgrKsxDf2u/68MpG0weYWHD7lHPWMvHdtIpHIyBICIjRj4u1vI xSOSp1WVc6sD9gBb2JZAr/abANB47NofxJe5tf6UmQEn3KACb5ozRqqjE4zqtDdWcw dlH6q2MmleKC9tygrFCjJIc7dRxYh/kxIiwmGlmo= Content-Language: en-US In-Reply-To: <864jdx11qx.fsf@mail.linkov.net> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:280605 Archived-At: This is a multi-part message in MIME format. --------------RXCD10SIDoJ95JzzYr5Ozq2f Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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 --------------RXCD10SIDoJ95JzzYr5Ozq2f Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit

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