(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.
This commit is contained in:
Stefan Monnier 2025-05-22 09:32:33 -04:00
parent 6e98316f04
commit 772c4f036c
2 changed files with 16 additions and 15 deletions

View file

@ -3089,20 +3089,21 @@ characters."
(set-match-data real-match-data) (set-match-data real-match-data)
(match-substitute-replacement (match-substitute-replacement
next-replacement nocasify literal)))) next-replacement nocasify literal))))
;; Bind message-log-max so we don't fill up the (let* ((replacement-presentation
;; message log with a bunch of identical messages. (if query-replace-show-replacement
(let ((message-log-max nil) (save-match-data
(replacement-presentation (set-match-data real-match-data)
(if query-replace-show-replacement (match-substitute-replacement next-replacement
(save-match-data nocasify literal))
(set-match-data real-match-data) next-replacement))
(match-substitute-replacement next-replacement (prompt
nocasify literal)) (format message
next-replacement))) (query-replace-descr from-string)
(message message (query-replace-descr
(query-replace-descr from-string) replacement-presentation))))
(query-replace-descr replacement-presentation))) ;; Use `read-key' so that escape sequences on TTYs
(setq key (read-event)) ;; are properly mapped back to the intended key.
(setq key (read-key prompt)))
;; Necessary in case something happens during ;; Necessary in case something happens during
;; read-event that clobbers the match data. ;; read-event that clobbers the match data.
(set-match-data real-match-data) (set-match-data real-match-data)

View file

@ -538,7 +538,7 @@ Return the last evalled form in BODY."
;; Bind `read-event' to simulate user input. ;; Bind `read-event' to simulate user input.
;; If `replace-tests-bind-read-string' is non-nil, then ;; If `replace-tests-bind-read-string' is non-nil, then
;; bind `read-string' as well. ;; bind `read-string' as well.
(cl-letf (((symbol-function 'read-event) (cl-letf (((symbol-function 'read-key)
(lambda (&rest _args) (lambda (&rest _args)
(incf ,count) (incf ,count)
(pcase ,count ; Build the clauses from CHAR-NUMS (pcase ,count ; Build the clauses from CHAR-NUMS