From: Stefan Monnier Date: Thu, 22 May 2025 13:32:33 +0000 (-0400) Subject: (perform-replace): Make it work with F-keys in TTYs (bug#78113) X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=3b96753d8de64f612dd3c43272e082b344c386c4;p=emacs.git (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. (cherry picked from commit 772c4f036c38efd2a81d3643ad0bd718033d3b7f) --- diff --git a/lisp/replace.el b/lisp/replace.el index 2d60dcae939..f88c181f33b 100644 --- a/lisp/replace.el +++ b/lisp/replace.el @@ -3068,20 +3068,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 288e8865dc5..be849185f69 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