From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: query-replace highlighting Date: Wed, 12 Jan 2005 03:54:09 +0200 Organization: JURTA Message-ID: <873bx7we42.fsf@jurta.org> References: <87ekhy6h5i.fsf@jurta.org> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1105499717 29201 80.91.229.6 (12 Jan 2005 03:15:17 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 12 Jan 2005 03:15:17 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Jan 12 04:15:11 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1CoYyU-00086a-00 for ; Wed, 12 Jan 2005 04:15:10 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1CoZA4-0002Kj-Q7 for ged-emacs-devel@m.gmane.org; Tue, 11 Jan 2005 22:27:08 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1CoZ9U-00026p-5C for emacs-devel@gnu.org; Tue, 11 Jan 2005 22:26:32 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1CoZ9R-00025c-QB for emacs-devel@gnu.org; Tue, 11 Jan 2005 22:26:30 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1CoZ9R-00025K-MB for emacs-devel@gnu.org; Tue, 11 Jan 2005 22:26:29 -0500 Original-Received: from [194.126.101.98] (helo=MXR-2.estpak.ee) by monty-python.gnu.org with esmtp (Exim 4.34) id 1CoYxn-0000w3-2F for emacs-devel@gnu.org; Tue, 11 Jan 2005 22:14:27 -0500 Original-Received: from mail.neti.ee (80-235-40-7-dsl.mus.estpak.ee [80.235.40.7]) by MXR-2.estpak.ee (Postfix) with ESMTP id 9CC1515A75D for ; Wed, 12 Jan 2005 05:14:23 +0200 (EET) Original-To: emacs-devel@gnu.org In-Reply-To: <87ekhy6h5i.fsf@jurta.org> (Juri Linkov's message of "Fri, 10 Dec 2004 04:06:33 +0200") User-Agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3.50 (gnu/linux) X-Virus-Scanned: by amavisd-new-2.2.1 (20041222) (Debian) at neti.ee X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:32146 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:32146 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/