From 8a24c1cc976e003494c3526304a02de8f37b5896 Mon Sep 17 00:00:00 2001 From: Augusto Stoffel Date: Sat, 8 Jan 2022 13:15:40 +0100 Subject: [PATCH 2/2] Lazy highlight when reading query-replace text * lisp/replace.el (query-replace-read-from): Add lazy highlighting. --- lisp/replace.el | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lisp/replace.el b/lisp/replace.el index 60e507c642..31478ee4a9 100644 --- a/lisp/replace.el +++ b/lisp/replace.el @@ -244,6 +244,19 @@ query-replace-read-from (query-replace-descr (cdar query-replace-defaults))))) (t (format-prompt prompt nil)))) + ;; Set up lazy highlighting while reading FROM regexp. + ;; TODO: Treat the `region-noncontiguous-p' case by setting + ;; `isearch-filter-predicate'. + (isearch-lazy-highlight query-replace-highlight) + (isearch-regexp regexp-flag) + (isearch-regexp-function nil) + (isearch-case-fold-search case-fold-search) ;; TODO: the case-folding rule here is complicated... + (isearch-read-with-highlight-transform + (lambda (string) + (let ((from (query-replace--split-string string))) + (if (consp from) (car from) from)))) + (isearch-lazy-count-display-function + #'isearch-read-with-highlight-count) (from ;; The save-excursion here is in case the user marks and copies ;; a region in order to specify the minibuffer input. @@ -251,6 +264,7 @@ query-replace-read-from (save-excursion (minibuffer-with-setup-hook (lambda () + (isearch-read-with-highlight-setup) (setq-local text-property-default-nonsticky (append '((separator . t) (face . t)) text-property-default-nonsticky))) -- 2.34.1