From 772c4f036c38efd2a81d3643ad0bd718033d3b7f Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Thu, 22 May 2025 09:32:33 -0400 Subject: [PATCH] (perform-replace): Make it work with F-keys in TTYs (bug#78113) * lisp/replace.el (perform-replace): Use `read-key`. * test/lisp/replace-tests.el (replace-tests-with-undo): Adjust accordingly. --- lisp/replace.el | 29 +++++++++++++++-------------- test/lisp/replace-tests.el | 2 +- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/lisp/replace.el b/lisp/replace.el index a6ba6387dc9..9939273594f 100644 --- a/lisp/replace.el +++ b/lisp/replace.el @@ -3089,20 +3089,21 @@ characters." (set-match-data real-match-data) (match-substitute-replacement 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)))) + ;; Use `read-key' so that escape sequences on TTYs + ;; are properly mapped back to the intended key. + (setq key (read-key prompt))) ;; Necessary in case something happens during ;; read-event that clobbers the match data. (set-match-data real-match-data) diff --git a/test/lisp/replace-tests.el b/test/lisp/replace-tests.el index fd3ecda2b72..d8f2060c5f1 100644 --- a/test/lisp/replace-tests.el +++ b/test/lisp/replace-tests.el @@ -538,7 +538,7 @@ Return the last evalled form in BODY." ;; Bind `read-event' to simulate user input. ;; If `replace-tests-bind-read-string' is non-nil, then ;; bind `read-string' as well. - (cl-letf (((symbol-function 'read-event) + (cl-letf (((symbol-function 'read-key) (lambda (&rest _args) (incf ,count) (pcase ,count ; Build the clauses from CHAR-NUMS