all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@jurta.org>
Subject: Re: query-replace highlighting
Date: Wed, 12 Jan 2005 03:54:09 +0200	[thread overview]
Message-ID: <873bx7we42.fsf@jurta.org> (raw)
In-Reply-To: <87ekhy6h5i.fsf@jurta.org> (Juri Linkov's message of "Fri, 10 Dec 2004 04:06:33 +0200")

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/

      parent reply	other threads:[~2005-01-12  1:54 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-10  2:06 query-replace highlighting Juri Linkov
2004-12-13 19:51 ` Richard Stallman
2004-12-14 10:34   ` Juri Linkov
2004-12-15 14:58     ` Richard Stallman
2004-12-15 12:00   ` Juri Linkov
2005-01-12  1:54 ` Juri Linkov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=873bx7we42.fsf@jurta.org \
    --to=juri@jurta.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.