From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Johan =?UTF-8?Q?Bockg=C3=A5rd?= Newsgroups: gmane.emacs.bugs Subject: bug#6808: 24.0.50; Incomplete match highlighting with `query-replace-regexp' Date: Sat, 07 Aug 2010 02:01:24 +0200 Message-ID: <87r5ibwasr.fsf@gnu.org> References: <878w4kqlw0.fsf@member.fsf.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1281139720 26338 80.91.229.12 (7 Aug 2010 00:08:40 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 7 Aug 2010 00:08:40 +0000 (UTC) Cc: Tassilo Horn , 6808@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Aug 07 02:08:38 2010 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1OhWxm-0000yQ-7y for geb-bug-gnu-emacs@m.gmane.org; Sat, 07 Aug 2010 02:08:38 +0200 Original-Received: from localhost ([127.0.0.1]:58067 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OhWxe-0003jM-S0 for geb-bug-gnu-emacs@m.gmane.org; Fri, 06 Aug 2010 20:08:26 -0400 Original-Received: from [140.186.70.92] (port=50859 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OhWxW-0003hA-Dc for bug-gnu-emacs@gnu.org; Fri, 06 Aug 2010 20:08:21 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OhWxT-0000Ha-Ap for bug-gnu-emacs@gnu.org; Fri, 06 Aug 2010 20:08:16 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:54121) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OhWxT-0000HW-6b for bug-gnu-emacs@gnu.org; Fri, 06 Aug 2010 20:08:15 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1OhWrS-0001Se-58; Fri, 06 Aug 2010 20:02:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Johan =?UTF-8?Q?Bockg=C3=A5rd?= Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 07 Aug 2010 00:02:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 6808 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 6808-submit@debbugs.gnu.org id=B6808.12811392785606 (code B ref 6808); Sat, 07 Aug 2010 00:02:02 +0000 Original-Received: (at 6808) by debbugs.gnu.org; 7 Aug 2010 00:01:18 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OhWqj-0001SN-Eo for submit@debbugs.gnu.org; Fri, 06 Aug 2010 20:01:17 -0400 Original-Received: from smtprelay-h21.telenor.se ([195.54.99.196]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OhWqg-0001SG-Nn for 6808@debbugs.gnu.org; Fri, 06 Aug 2010 20:01:16 -0400 Original-Received: from ipb3.telenor.se (ipb3.telenor.se [195.54.127.166]) by smtprelay-h21.telenor.se (Postfix) with ESMTP id DC246EA8BD for <6808@debbugs.gnu.org>; Sat, 7 Aug 2010 02:01:48 +0200 (CEST) X-SENDER-IP: [85.228.198.191] X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ans2AM4/XExV5Ma/PGdsb2JhbACHZ5hjDAEBAQE1LcZmhToE X-IronPort-AV: E=Sophos;i="4.55,331,1278280800"; d="scan'208";a="558437004" Original-Received: from c-bfc6e455.04-211-6c6b701.cust.bredbandsbolaget.se (HELO muon.localdomain) ([85.228.198.191]) by ipb3.telenor.se with ESMTP; 07 Aug 2010 02:01:26 +0200 Original-Received: by muon.localdomain (Postfix, from userid 1000) id 7D1CF484494; Sat, 7 Aug 2010 02:01:25 +0200 (CEST) Mail-Copies-To: never In-Reply-To: (Stefan Monnier's message of "Fri, 06 Aug 2010 15:13:55 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Fri, 06 Aug 2010 20:02:02 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:39299 Archived-At: Stefan Monnier writes: >> The matches to be replaced by `query-replace-regexp' aren't highlighted >> completely, although the replacement is correct. [...] > I'd guess that those incorrect matches are search with > re-search-backward rather than re-search-forward. Yes. replace-highlight does not update isearch-forward, so you get this behavior if the previous isearch was a backward search (or in emacs -Q). The following patch fixes this and two other problems: * There is no lazy highlighting during replacement if the previous isearch set isearch-error (invalid regexp). * A search that is started with C-s uses forward search for highlighting and one that is started with C-r uses backward search, but the highlighting is not updated if one switches direction in the middle (C-s followed by C-r or vice versa). diff --git a/lisp/isearch.el b/lisp/isearch.el index 89d50d6..1fe604d 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -2581,6 +2581,7 @@ since they have special meaning in a regexp." (defvar isearch-lazy-highlight-case-fold-search nil) (defvar isearch-lazy-highlight-regexp nil) (defvar isearch-lazy-highlight-space-regexp nil) +(defvar isearch-lazy-highlight-forward nil) (defun lazy-highlight-cleanup (&optional force) "Stop lazy highlighting and remove extra highlighting from current buffer. @@ -2620,7 +2621,9 @@ by other Emacs features." (not (= (window-start) isearch-lazy-highlight-window-start)) (not (= (window-end) ; Window may have been split/joined. - isearch-lazy-highlight-window-end)))) + isearch-lazy-highlight-window-end)) + (not (eq isearch-forward + isearch-lazy-highlight-forward)))) ;; something important did indeed change (lazy-highlight-cleanup t) ;kill old loop & remove overlays (when (not isearch-error) @@ -2635,7 +2638,8 @@ by other Emacs features." isearch-lazy-highlight-case-fold-search isearch-case-fold-search isearch-lazy-highlight-regexp isearch-regexp isearch-lazy-highlight-wrapped nil - isearch-lazy-highlight-space-regexp search-whitespace-regexp) + isearch-lazy-highlight-space-regexp search-whitespace-regexp + isearch-lazy-highlight-forward isearch-forward) (unless (equal isearch-string "") (setq isearch-lazy-highlight-timer (run-with-idle-timer lazy-highlight-initial-delay nil @@ -2651,7 +2655,8 @@ Attempt to do the search exactly the way the pending Isearch would." (search-invisible nil) ; don't match invisible text (retry t) (success nil) - (bound (if isearch-forward + (isearch-forward isearch-lazy-highlight-forward) + (bound (if isearch-lazy-highlight-forward (min (or isearch-lazy-highlight-end-limit (point-max)) (if isearch-lazy-highlight-wrapped isearch-lazy-highlight-start @@ -2687,7 +2692,7 @@ Attempt to do the search exactly the way the pending Isearch would." (select-window isearch-lazy-highlight-window)) (save-excursion (save-match-data - (goto-char (if isearch-forward + (goto-char (if isearch-lazy-highlight-forward isearch-lazy-highlight-end isearch-lazy-highlight-start)) (while looping @@ -2700,7 +2705,7 @@ Attempt to do the search exactly the way the pending Isearch would." (let ((mb (match-beginning 0)) (me (match-end 0))) (if (= mb me) ;zero-length match - (if isearch-forward + (if isearch-lazy-highlight-forward (if (= mb (if isearch-lazy-highlight-wrapped isearch-lazy-highlight-start (window-end))) @@ -2720,7 +2725,7 @@ Attempt to do the search exactly the way the pending Isearch would." (overlay-put ov 'priority 1000) (overlay-put ov 'face lazy-highlight-face) (overlay-put ov 'window (selected-window)))) - (if isearch-forward + (if isearch-lazy-highlight-forward (setq isearch-lazy-highlight-end (point)) (setq isearch-lazy-highlight-start (point))))) @@ -2730,7 +2735,7 @@ Attempt to do the search exactly the way the pending Isearch would." (setq looping nil nomore t) (setq isearch-lazy-highlight-wrapped t) - (if isearch-forward + (if isearch-lazy-highlight-forward (progn (setq isearch-lazy-highlight-end (window-start)) (goto-char (max (or isearch-lazy-highlight-start-limit (point-min)) diff --git a/lisp/replace.el b/lisp/replace.el index d73692c..01d971f 100644 --- a/lisp/replace.el +++ b/lisp/replace.el @@ -1979,7 +1979,9 @@ make, or the user didn't cancel the call." (let ((isearch-string string) (isearch-regexp regexp) (search-whitespace-regexp nil) - (isearch-case-fold-search case-fold)) + (isearch-case-fold-search case-fold) + (isearch-forward t) + (isearch-error nil)) ;; Set isearch-word to nil because word-replace is regexp-based, ;; so `isearch-search-fun' should not use `word-search-forward'. (if (and isearch-word isearch-regexp) (setq isearch-word nil))