From: "Johan Bockgård" <bojohan@gnu.org>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Tassilo Horn <tassilo@member.fsf.org>, 6808@debbugs.gnu.org
Subject: bug#6808: 24.0.50; Incomplete match highlighting with `query-replace-regexp'
Date: Sat, 07 Aug 2010 02:01:24 +0200 [thread overview]
Message-ID: <87r5ibwasr.fsf@gnu.org> (raw)
In-Reply-To: <jwvvd7nanpn.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Fri, 06 Aug 2010 15:13:55 +0200")
Stefan Monnier <monnier@iro.umontreal.ca> 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))
next prev parent reply other threads:[~2010-08-07 0:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-06 6:46 bug#6808: 24.0.50; Incomplete match highlighting with `query-replace-regexp' Tassilo Horn
2010-08-06 13:13 ` Stefan Monnier
2010-08-06 17:43 ` Tassilo Horn
2010-08-07 0:01 ` Johan Bockgård [this message]
2010-08-08 20:56 ` Chong Yidong
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87r5ibwasr.fsf@gnu.org \
--to=bojohan@gnu.org \
--cc=6808@debbugs.gnu.org \
--cc=monnier@iro.umontreal.ca \
--cc=tassilo@member.fsf.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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).