changeset 58973:7fed010105d9

(perform-replace): Add isearch-case-fold-search. Use delimited-flag for isearch-regexp. Reset isearch-lazy-highlight-last-string to force lazy highlighting when called from isearch mode. (query-replace-highlight): Revert defcustom type to boolean. (query-replace-lazy-highlight): New defcustom. (query-replace): New face. (perform-replace, replace-highlight, replace-dehighlight): Test query-replace-lazy-highlight instead of special value `isearch' of query-replace-highlight. (replace-dehighlight): Don't call isearch-dehighlight. (replace-highlight): Don't call isearch-highlight. Use face `query-replace' unconditionally.
author Juri Linkov <juri@jurta.org>
date Wed, 15 Dec 2004 10:10:54 +0000
parents 71d0bc7835fb
children f23a14da8463
files lisp/replace.el
diffstat 1 files changed, 48 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/replace.el	Wed Dec 15 10:08:51 2004 +0000
+++ b/lisp/replace.el	Wed Dec 15 10:10:54 2004 +0000
@@ -1283,6 +1283,7 @@
 
 	(isearch-string isearch-string)
 	(isearch-regexp isearch-regexp)
+	(isearch-case-fold-search isearch-case-fold-search)
 	(message
 	 (if query-flag
 	     (substitute-command-keys
@@ -1315,9 +1316,11 @@
 				    (if regexp-flag from-string
 				      (regexp-quote from-string))
 				    "\\b")))
-    (if (eq query-replace-highlight 'isearch)
-	(setq isearch-string search-string
-	      isearch-regexp regexp-flag))
+    (when query-replace-lazy-highlight
+      (setq isearch-string search-string
+	    isearch-regexp (or delimited-flag regexp-flag)
+	    isearch-case-fold-search case-fold-search
+	    isearch-lazy-highlight-last-string nil))
 
     (push-mark)
     (undo-boundary)
@@ -1535,13 +1538,15 @@
 			       (append (listify-key-sequence key)
 				       unread-command-events))
 			 (setq done t)))
-		  (when (eq query-replace-highlight 'isearch)
-		    ;; Force isearch rehighlighting
+		  (when query-replace-lazy-highlight
+		    ;; Restore isearch data for lazy highlighting
+		    ;; in case of isearching during recursive edit
+		    (setq isearch-string search-string
+			  isearch-regexp (or delimited-flag regexp-flag)
+			  isearch-case-fold-search case-fold-search)
+		    ;; Force lazy rehighlighting only after replacements
 		    (if (not (memq def '(skip backup)))
-			(setq isearch-lazy-highlight-last-string nil))
-		    ;; Restore isearch data in case of isearching during edit
-		    (setq isearch-string search-string
-			  isearch-regexp regexp-flag)))
+			(setq isearch-lazy-highlight-last-string nil))))
 		;; Record previous position for ^ when we move on.
 		;; Change markers to numbers in the match data
 		;; since lots of markers slow down editing.
@@ -1576,38 +1581,45 @@
 		 (if (= replace-count 1) "" "s")))
     (and keep-going stack)))
 
-(defcustom query-replace-highlight
-  (if (and search-highlight isearch-lazy-highlight) 'isearch t)
-  "*Non-nil means to highlight words during query replacement.
-If `isearch', use isearch highlighting for query replacement."
-  :type '(choice (const :tag "Highlight" t)
-                 (const :tag "No highlighting" nil)
-                 (const :tag "Isearch highlighting" 'isearch))
+(defcustom query-replace-highlight t
+  "*Non-nil means to highlight matches during query replacement."
+  :type 'boolean
   :group 'matching)
 
+(defcustom query-replace-lazy-highlight t
+  "*Controls the lazy-highlighting during query replacements.
+When non-nil, all text in the buffer matching the current match
+is highlighted lazily using isearch lazy highlighting (see
+`isearch-lazy-highlight-initial-delay' and
+`isearch-lazy-highlight-interval')."
+  :type 'boolean
+  :group 'matching
+  :version "21.4")
+
+(defface query-replace
+  '((t (:inherit isearch)))
+  "Face for highlighting query replacement matches."
+  :group 'matching
+  :version "21.4")
+
 (defvar replace-overlay nil)
 
-(defun replace-dehighlight ()
-  (cond ((eq query-replace-highlight 'isearch)
-	 (isearch-dehighlight t)
-	 (isearch-lazy-highlight-cleanup isearch-lazy-highlight-cleanup)
-	 (setq isearch-lazy-highlight-last-string nil))
-	(query-replace-highlight
-	 (when replace-overlay
-	   (delete-overlay replace-overlay)
-	   (setq replace-overlay nil)))))
+(defun replace-highlight (beg end)
+  (if query-replace-highlight
+      (if replace-overlay
+	  (move-overlay replace-overlay beg end (current-buffer))
+	(setq replace-overlay (make-overlay beg end))
+	(overlay-put replace-overlay 'priority 1) ;higher than lazy overlays
+	(overlay-put replace-overlay 'face 'query-replace)))
+  (if query-replace-lazy-highlight
+      (isearch-lazy-highlight-new-loop)))
 
-(defun replace-highlight (start end)
-  (cond ((eq query-replace-highlight 'isearch)
-	 (isearch-highlight start end)
-	 (isearch-lazy-highlight-new-loop))
-	(query-replace-highlight
-	 (if replace-overlay
-	     (move-overlay replace-overlay start end (current-buffer))
-	   (setq replace-overlay (make-overlay start end))
-	   (overlay-put replace-overlay 'face
-			(if (facep 'query-replace)
-			    'query-replace 'region))))))
+(defun replace-dehighlight ()
+  (when replace-overlay
+    (delete-overlay replace-overlay))
+  (when query-replace-lazy-highlight
+    (isearch-lazy-highlight-cleanup isearch-lazy-highlight-cleanup)
+    (setq isearch-lazy-highlight-last-string nil)))
 
 ;; arch-tag: 16b4cd61-fd40-497b-b86f-b667c4cf88e4
 ;;; replace.el ends here