GNU bug report logs - #78113
make F-keys work in perform-replace when running Emacs in terminal

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Toomas Rosin <toomas@HIDDEN>; dated Mon, 28 Apr 2025 13:05:04 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.

Message received at 78113 <at> debbugs.gnu.org:


Received: (at 78113) by debbugs.gnu.org; 17 May 2025 08:12:43 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat May 17 04:12:43 2025
Received: from localhost ([127.0.0.1]:45213 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1uGCew-0004OX-Rx
	for submit <at> debbugs.gnu.org; Sat, 17 May 2025 04:12:43 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:48356)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1uGCeu-0004O9-FU
 for 78113 <at> debbugs.gnu.org; Sat, 17 May 2025 04:12:41 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1uGCen-0007hl-MM; Sat, 17 May 2025 04:12:33 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=hej+U31yxAw15zkNtzA0yXov7V11EsT3bhz7D34i/18=; b=Qb3F+xt8lttp
 9FxrRGGtMc8clcVsCYd3PpNp40lFjDrIKRvsXj9XeYwntv74KrMg+nVzS4wcWk7hZuT7u35TkLUlF
 Y8qAqbtc0INeI32UVFenazvoZVsw2UhCijaMD4b32uDY/Rxw62Vv7FLPy2WO1QYuAa4LMeG505Yup
 srTIXb+jawysj6GlPUxBwfzRiW20vsKqomcv4kiGB4pAwWlgwAxgrxAlQQjtmachOfukdqEHULN+M
 UcJy8OqdQ6LVhwD6oDhqjoTW9T4AgIIr263f+cH4lTDrpuDhGLlJ8POQelwimcsms8Wx1lTIT/Sq4
 jlFQGj30oOcI8EGPl+ybww==;
Date: Sat, 17 May 2025 11:12:31 +0300
Message-Id: <86ldqvwt8w.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Stefan Monnier <monnier@HIDDEN>
In-Reply-To: <jwvo6w93hmj.fsf-monnier+emacs@HIDDEN> (message from Stefan
 Monnier on Sat, 03 May 2025 10:30:43 -0400)
Subject: Re: bug#78113: make F-keys work in perform-replace when running
 Emacs in terminal
References: <20250428155358.16333@localhost> <86o6wajc7l.fsf@HIDDEN>
 <jwvo6w93hmj.fsf-monnier+emacs@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 78113
Cc: toomas@HIDDEN, 78113 <at> debbugs.gnu.org, juri@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

Ping!  How should we proceed with this issue?

> From: Stefan Monnier <monnier@HIDDEN>
> Cc: Toomas Rosin <toomas@HIDDEN>,  Juri Linkov <juri@HIDDEN>,
>   78113 <at> debbugs.gnu.org
> Date: Sat, 03 May 2025 10:30:43 -0400
> 
> >> @@ -3092,14 +3093,14 @@
> >>  			       (match-substitute-replacement next-replacement
> >>  							     nocasify literal))
> >>  			   next-replacement)))
> >> -		    (message message
> >> -                             (query-replace-descr from-string)
> >> -                             (query-replace-descr replacement-presentation)))
> >> -		  (setq key (read-event))
> >> +		    (setq key (read-key-sequence
> >> +			       (format message
> >> +				       (query-replace-descr from-string)
> >> +				       (query-replace-descr replacement-presentation))))
> >> +		    (setq last-input-key-sequence key))
> 
> > Stefan and Juri, any comments?
> 
> I generally like the direction this is going.
> 
> > As usual, when replacing one input function by another, there be
> > dragons.  So if there's a safer way of fixing this, which would not
> > affect every other use case with replace commands, I'd prefer that.
> 
> Using `read-key` instead of `read-key-sequence` should also allow the
> use of F-keys (and arrow keys, ...) but would minimize the differences
> with `read-event` (since `read-key` is exactly that: a wrapper around
> `read-key-sequence` which tries to minimize the differences with
> `read-event`).
> 
> 
>         Stefan
> 
> 
> @@ -3091,18 +3091,18 @@ perform-replace
>                              next-replacement nocasify literal))))
>  		  ;; Bind message-log-max so we don't fill up the
>  		  ;; message log with a bunch of identical messages.
> -		  (let ((message-log-max nil)
> -			(replacement-presentation
> -			 (if query-replace-show-replacement
> -			     (save-match-data
> -			       (set-match-data real-match-data)
> -			       (match-substitute-replacement next-replacement
> -							     nocasify literal))
> -			   next-replacement)))
> -		    (message message
> -                             (query-replace-descr from-string)
> -                             (query-replace-descr replacement-presentation)))
> -		  (setq key (read-event))
> +		  (let* ((replacement-presentation
> +			  (if query-replace-show-replacement
> +			      (save-match-data
> +			        (set-match-data real-match-data)
> +			        (match-substitute-replacement next-replacement
> +							      nocasify literal))
> +			    next-replacement))
> +			 (prompt
> +			  (format message
> +                                  (query-replace-descr from-string)
> +                                  (query-replace-descr replacement-presentation))))
> +		    (setq key (read-key prompt)))
>  		  ;; Necessary in case something happens during
>  		  ;; read-event that clobbers the match data.
>  		  (set-match-data real-match-data)
> 
> 




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#78113; Package emacs. Full text available.

Message received at 78113 <at> debbugs.gnu.org:


Received: (at 78113) by debbugs.gnu.org; 3 May 2025 14:30:54 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat May 03 10:30:54 2025
Received: from localhost ([127.0.0.1]:42066 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1uBDtG-0002Nb-1I
	for submit <at> debbugs.gnu.org; Sat, 03 May 2025 10:30:54 -0400
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:62788)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <monnier@HIDDEN>)
 id 1uBDtD-0002NJ-N8
 for 78113 <at> debbugs.gnu.org; Sat, 03 May 2025 10:30:52 -0400
Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1])
 by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 05E7380964;
 Sat,  3 May 2025 10:30:46 -0400 (EDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1746282645;
 bh=Yf9p9ohJG+q4u0ve2Abw8Ya65q+lPS9V9uFbObhgcfc=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=TLjGv99EYvhKMOHALYP3ZOzW2NZTrxbsA6rIdkqMcuywHSRZ60MBzT0kwu5qWAj7n
 sHgUwFerzEB6t9kXDQZYxaVdmovSZ0ZsoT1mWNB1lxCiIdUf7onw8QErkru/pkCyFx
 N46Bpnjt5/RoUP3PE5MNYfPWTsfFDV3zVzDFPaC6EJhybTWDs+z3hk9zR2Qw9wPsEn
 Z7ZLKxTDiHk1jnRF4g18WPDIIZ0lPuA+Xm5GzcrXMzPGtx+UZuVIXYhkwBsxycQlu1
 M+Vyxok4L+kZIwaB8Vsr4ZT5qurBNJyIYqJ7p4aMyZCXWCN7T0GLcfGHiFCVSJ6T23
 4qgYo7qka30+A==
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id F3FA3807B7;
 Sat,  3 May 2025 10:30:44 -0400 (EDT)
Received: from pastel (104-195-232-56.cpe.teksavvy.com [104.195.232.56])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 7D9D7120192;
 Sat,  3 May 2025 10:30:44 -0400 (EDT)
From: Stefan Monnier <monnier@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#78113: make F-keys work in perform-replace when running
 Emacs in terminal
In-Reply-To: <86o6wajc7l.fsf@HIDDEN>
Message-ID: <jwvo6w93hmj.fsf-monnier+emacs@HIDDEN>
References: <20250428155358.16333@localhost> <86o6wajc7l.fsf@HIDDEN>
Date: Sat, 03 May 2025 10:30:43 -0400
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-SPAM-INFO: Spam detection results:  0
 ALL_TRUSTED                -1 Passed through trusted hosts only via SMTP
 AWL -0.058 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DKIM_SIGNED               0.1 Message has a DKIM or DK signature,
 not necessarily valid
 DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature
 DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's
 domain
 DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from
 domain
X-SPAM-LEVEL: 
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 78113
Cc: Toomas Rosin <toomas@HIDDEN>, 78113 <at> debbugs.gnu.org,
 Juri Linkov <juri@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

>> @@ -3092,14 +3093,14 @@
>>  			       (match-substitute-replacement next-replacement
>>  							     nocasify literal))
>>  			   next-replacement)))
>> -		    (message message
>> -                             (query-replace-descr from-string)
>> -                             (query-replace-descr replacement-presentation)))
>> -		  (setq key (read-event))
>> +		    (setq key (read-key-sequence
>> +			       (format message
>> +				       (query-replace-descr from-string)
>> +				       (query-replace-descr replacement-presentation))))
>> +		    (setq last-input-key-sequence key))

> Stefan and Juri, any comments?

I generally like the direction this is going.

> As usual, when replacing one input function by another, there be
> dragons.  So if there's a safer way of fixing this, which would not
> affect every other use case with replace commands, I'd prefer that.

Using `read-key` instead of `read-key-sequence` should also allow the
use of F-keys (and arrow keys, ...) but would minimize the differences
with `read-event` (since `read-key` is exactly that: a wrapper around
`read-key-sequence` which tries to minimize the differences with
`read-event`).


        Stefan


@@ -3091,18 +3091,18 @@ perform-replace
                             next-replacement nocasify literal))))
 		  ;; Bind message-log-max so we don't fill up the
 		  ;; message log with a bunch of identical messages.
-		  (let ((message-log-max nil)
-			(replacement-presentation
-			 (if query-replace-show-replacement
-			     (save-match-data
-			       (set-match-data real-match-data)
-			       (match-substitute-replacement next-replacement
-							     nocasify literal))
-			   next-replacement)))
-		    (message message
-                             (query-replace-descr from-string)
-                             (query-replace-descr replacement-presentation)))
-		  (setq key (read-event))
+		  (let* ((replacement-presentation
+			  (if query-replace-show-replacement
+			      (save-match-data
+			        (set-match-data real-match-data)
+			        (match-substitute-replacement next-replacement
+							      nocasify literal))
+			    next-replacement))
+			 (prompt
+			  (format message
+                                  (query-replace-descr from-string)
+                                  (query-replace-descr replacement-presentation))))
+		    (setq key (read-key prompt)))
 		  ;; Necessary in case something happens during
 		  ;; read-event that clobbers the match data.
 		  (set-match-data real-match-data)





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#78113; Package emacs. Full text available.

Message received at 78113 <at> debbugs.gnu.org:


Received: (at 78113) by debbugs.gnu.org; 3 May 2025 09:06:04 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat May 03 05:06:04 2025
Received: from localhost ([127.0.0.1]:38186 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1uB8ot-0007DG-Ty
	for submit <at> debbugs.gnu.org; Sat, 03 May 2025 05:06:04 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:39942)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <eliz@HIDDEN>) id 1uB8or-0007Cl-5C
 for 78113 <at> debbugs.gnu.org; Sat, 03 May 2025 05:06:01 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1uB8oj-00069E-Fa; Sat, 03 May 2025 05:05:53 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=Wd5AMTmmYxGWH5d6kLGxCnUWfxzV52KurwCoKaANXT4=; b=dteLZoTEdBm9
 /GLJ+jasx2vf49i+jB20yj3Vb4KHWHe2AuSm2Zh6O8CkLfvuP4jtQJKhR1Yd1QKguGXK3Budp+lXj
 3rvoVxWFt7c6kzPKm9o/0bdEvbZ7NAJBUUB1+5mAAeC4HwvZXDad61yhm/R0kQJ6H69G7OWiXjwiy
 Ne+bcf8v+oMYEtZs2nHiBtA9hUyM3CBB5PW4uEjwddXsh48Zmee0C0kJ38WeGKqQhxPrVJ9KEShso
 JIu61iyu0ES+SxHE9K9ljEEdbeFZnO77q/qctbyML0fU5Ot6wF8O7glLAQGTler4/QqntPjADu8gS
 y0OuH62dZB6+b8hb4QNwnQ==;
Date: Sat, 03 May 2025 12:05:50 +0300
Message-Id: <86o6wajc7l.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Toomas Rosin <toomas@HIDDEN>,
 Stefan Monnier <monnier@HIDDEN>, Juri Linkov <juri@HIDDEN>
In-Reply-To: <20250428155358.16333@localhost> (message from Toomas Rosin on
 Mon, 28 Apr 2025 15:53:58 +0300)
Subject: Re: bug#78113: make F-keys work in perform-replace when running Emacs
 in terminal
References: <20250428155358.16333@localhost>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 78113
Cc: 78113 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> From: Toomas Rosin <toomas@HIDDEN>
> Date: Mon, 28 Apr 2025 15:53:58 +0300
> 
> Hi,
> 
> I have found it very convenient to run replace commands (query-replace and friends) with F11 mapped to #'skip and F12 to #'act in query-replace-map.  But because perform-replace reads commands via read-event, this does not work in terminal.  (Pressing F11 or F12 does nothing and terminates the search.)  I have modified replace.el to use read-key-sequence instead of read-event, and now my setup seems to work flawlessly in terminal too:
> 
> --- replace.el.orig
> +++ replace.el
> @@ -2895,7 +2895,8 @@
>                               "%s with %s: "
>                               (substitute-command-keys
>                                "(\\<query-replace-map>\\[help] for help) "))
> -                     minibuffer-prompt-properties))))
> +                     minibuffer-prompt-properties)))
> +	 (last-input-key-sequence []))
> 
>      ;; Unless a single contiguous chunk is selected, operate on multiple chunks.
>      (when region-noncontiguous-p
> @@ -2916,7 +2917,7 @@
> 
>      ;; 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) t) 'automatic-all)
> +    (when (eq (lookup-key map last-input-key-sequence t) 'automatic-all)
>        (setq query-flag nil multi-buffer t))
> 
>      (cond
> @@ -3092,14 +3093,14 @@
>  			       (match-substitute-replacement next-replacement
>  							     nocasify literal))
>  			   next-replacement)))
> -		    (message message
> -                             (query-replace-descr from-string)
> -                             (query-replace-descr replacement-presentation)))
> -		  (setq key (read-event))
> +		    (setq key (read-key-sequence
> +			       (format message
> +				       (query-replace-descr from-string)
> +				       (query-replace-descr replacement-presentation))))
> +		    (setq last-input-key-sequence key))
>  		  ;; Necessary in case something happens during
>  		  ;; read-event that clobbers the match data.
>  		  (set-match-data real-match-data)
> -		  (setq key (vector key))
>  		  (setq def (lookup-key map key t))
>  		  ;; Restore the match data while we process the command.
>  		  (cond ((eq def 'help)
> 
> Best regards,
> T.

Stefan and Juri, any comments?

As usual, when replacing one input function by another, there be
dragons.  So if there's a safer way of fixing this, which would not
affect every other use case with replace commands, I'd prefer that.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#78113; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 28 Apr 2025 13:04:42 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Apr 28 09:04:41 2025
Received: from localhost ([127.0.0.1]:55097 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1u9OA5-0005SO-28
	for submit <at> debbugs.gnu.org; Mon, 28 Apr 2025 09:04:41 -0400
Received: from lists.gnu.org ([2001:470:142::17]:52266)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <toomas@HIDDEN>) id 1u9OA1-0005IL-AW
 for submit <at> debbugs.gnu.org; Mon, 28 Apr 2025 09:04:38 -0400
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 <toomas@HIDDEN>) id 1u9O7p-0002eT-CJ
 for bug-gnu-emacs@HIDDEN; Mon, 28 Apr 2025 09:02:31 -0400
Received: from 92-115-235-80.sta.estpak.ee ([80.235.115.92] helo=rosin.ee)
 by eggs.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <toomas@HIDDEN>) id 1u9O7n-0003TS-2P
 for bug-gnu-emacs@HIDDEN; Mon, 28 Apr 2025 09:02:21 -0400
Received: by rosin.ee (Postfix, from userid 1000)
 id 46E56A2639; Mon, 28 Apr 2025 15:53:58 +0300 (EEST)
From: Toomas Rosin <toomas@HIDDEN>
To: <bug-gnu-emacs@HIDDEN>
Subject: make F-keys work in perform-replace when running Emacs in terminal
X-Mailer: MH-E 8.6+git; GNU Mailutils 3.18; Emacs 30.1
Date: Mon, 28 Apr 2025 15:53:58 +0300
Message-ID: <20250428155358.16333@localhost>
User-Agent: MH (GNU Mailutils 3.18)
Received-SPF: pass client-ip=80.235.115.92; envelope-from=toomas@HIDDEN;
 helo=rosin.ee
X-Spam_score_int: -8
X-Spam_score: -0.9
X-Spam_bar: /
X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9,
 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001,
 RDNS_DYNAMIC=0.982, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001,
 TVD_RCVD_IP=0.001 autolearn=no autolearn_force=no
X-Spam_action: no action
X-Spam-Score: 0.9 (/)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.1 (/)

Hi,

I have found it very convenient to run replace commands (query-replace and friends) with F11 mapped to #'skip and F12 to #'act in query-replace-map.  But because perform-replace reads commands via read-event, this does not work in terminal.  (Pressing F11 or F12 does nothing and terminates the search.)  I have modified replace.el to use read-key-sequence instead of read-event, and now my setup seems to work flawlessly in terminal too:

--- replace.el.orig
+++ replace.el
@@ -2895,7 +2895,8 @@
                              "%s with %s: "
                              (substitute-command-keys
                               "(\\<query-replace-map>\\[help] for help) "))
-                     minibuffer-prompt-properties))))
+                     minibuffer-prompt-properties)))
+	 (last-input-key-sequence []))

     ;; Unless a single contiguous chunk is selected, operate on multiple chunks.
     (when region-noncontiguous-p
@@ -2916,7 +2917,7 @@

     ;; 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) t) 'automatic-all)
+    (when (eq (lookup-key map last-input-key-sequence t) 'automatic-all)
       (setq query-flag nil multi-buffer t))

     (cond
@@ -3092,14 +3093,14 @@
 			       (match-substitute-replacement next-replacement
 							     nocasify literal))
 			   next-replacement)))
-		    (message message
-                             (query-replace-descr from-string)
-                             (query-replace-descr replacement-presentation)))
-		  (setq key (read-event))
+		    (setq key (read-key-sequence
+			       (format message
+				       (query-replace-descr from-string)
+				       (query-replace-descr replacement-presentation))))
+		    (setq last-input-key-sequence key))
 		  ;; Necessary in case something happens during
 		  ;; read-event that clobbers the match data.
 		  (set-match-data real-match-data)
-		  (setq key (vector key))
 		  (setq def (lookup-key map key t))
 		  ;; Restore the match data while we process the command.
 		  (cond ((eq def 'help)

Best regards,
T.




Acknowledgement sent to Toomas Rosin <toomas@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#78113; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Sat, 17 May 2025 08:15:01 UTC

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