emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: query-replace highlighting


From: Juri Linkov
Subject: Re: query-replace highlighting
Date: Wed, 12 Jan 2005 03:54:09 +0200
User-agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3.50 (gnu/linux)

For commands that use lazy highlighting it would be cleaner
to use the values of global variables active at the time of calling
`isearch-lazy-highlight-new-loop', than values that are active
at the time of calling the timer function `isearch-lazy-highlight-update'.

In other words, I propose to use in `isearch-lazy-highlight-search'
the values `isearch-lazy-highlight-last-string',
`isearch-lazy-highlight-regexp', `isearch-lazy-highlight-case-fold-search'
with the values set during calling `isearch-lazy-highlight-new-loop'
instead of the values of `isearch-string', `isearch-case-fold-search'.

The main reason for this change is to avoid the need to change and
maintain the global values of `isearch-string', `isearch-regexp'
and `isearch-case-fold-search' for the timer function.  It should be
the care of code that calls `isearch-lazy-highlight-new-loop' to call
it again with new parameters when the matching string changes.

Index: lisp/isearch.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/isearch.el,v
retrieving revision 1.254
diff -u -r1.254 isearch.el
--- lisp/isearch.el     11 Jan 2005 23:03:01 -0000      1.254
+++ lisp/isearch.el     12 Jan 2005 00:52:53 -0000
@@ -2377,10 +2377,11 @@
 (defun isearch-lazy-highlight-search ()
   "Search ahead for the next or previous match, for lazy highlighting.
 Attempt to do the search exactly the way the pending isearch would."
-  (let ((case-fold-search isearch-case-fold-search)
+  (let ((case-fold-search isearch-lazy-highlight-case-fold-search)
+       (isearch-regexp isearch-lazy-highlight-regexp)
        (search-spaces-regexp search-whitespace-regexp))
     (funcall (isearch-search-fun)
-             isearch-string
+             isearch-lazy-highlight-last-string
              (if isearch-forward
                  (if isearch-lazy-highlight-wrapped
                      isearch-lazy-highlight-start

And below is the consequently simplified code in replace.el.

Index: lisp/replace.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/replace.el,v
retrieving revision 1.201
diff -u -r1.201 replace.el
--- lisp/replace.el     11 Jan 2005 23:04:16 -0000      1.201
+++ lisp/replace.el     12 Jan 2005 00:56:42 -0000
@@ -1322,9 +1322,6 @@
        ;; (match-data); otherwise it is t if a match is possible at point.
        (match-again t)
 
-       (isearch-string isearch-string)
-       (isearch-regexp isearch-regexp)
-       (isearch-case-fold-search isearch-case-fold-search)
        (message
         (if query-flag
             (substitute-command-keys
@@ -1358,10 +1355,7 @@
                                      (regexp-quote from-string))
                                    "\\b")))
     (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))
+      (setq isearch-lazy-highlight-last-string nil))
 
     (push-mark)
     (undo-boundary)
@@ -1431,8 +1425,10 @@
                (let ((inhibit-read-only
                       query-replace-skip-read-only))
                  (unless (or literal noedit)
-                   (replace-highlight (nth 0 real-match-data)
-                                      (nth 1 real-match-data)))
+                   (replace-highlight
+                    (nth 0 real-match-data) (nth 1 real-match-data)
+                    search-string (or delimited-flag regexp-flag)
+                    case-fold-search))
                  (setq noedit
                        (replace-match-maybe-edit
                         next-replacement nocasify literal
@@ -1448,7 +1444,10 @@
                ;; `real-match-data'.
                (while (not done)
                  (set-match-data real-match-data)
-                 (replace-highlight (match-beginning 0) (match-end 0))
+                 (replace-highlight
+                  (match-beginning 0) (match-end 0)
+                  search-string (or delimited-flag regexp-flag)
+                  case-fold-search)
                  ;; Bind message-log-max so we don't fill up the message log
                  ;; with a bunch of identical messages.
                  (let ((message-log-max nil))
@@ -1580,11 +1579,6 @@
                                       unread-command-events))
                         (setq done t)))
                  (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))))
@@ -1624,7 +1618,7 @@
 
 (defvar replace-overlay nil)
 
-(defun replace-highlight (beg end)
+(defun replace-highlight (beg end &optional string regexp case-fold)
   (if query-replace-highlight
       (if replace-overlay
          (move-overlay replace-overlay beg end (current-buffer))
@@ -1632,7 +1626,10 @@
        (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)))
+      (let ((isearch-string string)
+           (isearch-regexp regexp)
+           (isearch-case-fold-search case-fold))
+       (isearch-lazy-highlight-new-loop))))
 
 (defun replace-dehighlight ()
   (when replace-overlay

-- 
Juri Linkov
http://www.jurta.org/emacs/





reply via email to

[Prev in Thread] Current Thread [Next in Thread]