[Top][All Lists]

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

Re: query-replace-regexp vs. following blanks highlighting

From: Chris Moore
Subject: Re: query-replace-regexp vs. following blanks highlighting
Date: Wed, 14 Feb 2007 13:11:10 +0100
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.93 (gnu/linux)

Chong Yidong <address@hidden> writes:

> This is a new feature in Emacs 22.  Use "^[ ]" if you want to
> highlight exactly one space.

What's the rationale for this feature?  I thought the point of
highlighting was to show which parts of the buffer match the regular
expression being searched for, which is useful.  What is the use of
showing parts which don't match as well?

It seems that the intention was to only affect regular expression
incremental search (see the documentation for
search-whitespace-regexp) but it also affects query-replace-regexp.

If a buffer contains the following:

1  2
1 2
1  2

and you run:
  (query-replace-regexp "1 2" "3")
then all 3 lines are highlighted, but only the middle line is offered
for replacement.

It's not good that 3 lines are highlighted, but only 1 line is
replaced.  We should fix it such that either:

a) all 3 lines are highlighted, and offered for replacement or
b) only the middle line is highlighted and offered for replacement.

Since the documentation for search-whitespace-regexp says:
  "This applies to regular expression incremental search", I guess
that (b) would be the preferred fix, as follows:

Index: lisp/isearch.el
RCS file: /sources/emacs/emacs/lisp/isearch.el,v
retrieving revision 1.293
diff -u -r1.293 isearch.el
--- lisp/isearch.el     17 Jan 2007 13:20:47 -0000      1.293
+++ lisp/isearch.el     14 Feb 2007 12:09:30 -0000
@@ -2374,7 +2374,8 @@
             isearch-lazy-highlight-last-string  isearch-string
            isearch-lazy-highlight-case-fold-search isearch-case-fold-search
            isearch-lazy-highlight-regexp       isearch-regexp
-            isearch-lazy-highlight-wrapped      nil)
+            isearch-lazy-highlight-wrapped      nil
+           isearch-lazy-highlight-space-regexp search-whitespace-regexp)
       (unless (equal isearch-string "")
        (setq isearch-lazy-highlight-timer
              (run-with-idle-timer lazy-highlight-initial-delay nil
@@ -2385,7 +2386,7 @@
 Attempt to do the search exactly the way the pending isearch would."
   (let ((case-fold-search isearch-lazy-highlight-case-fold-search)
        (isearch-regexp isearch-lazy-highlight-regexp)
-       (search-spaces-regexp search-whitespace-regexp))
+       (search-spaces-regexp isearch-lazy-highlight-space-regexp))
     (condition-case nil
Index: lisp/replace.el
RCS file: /sources/emacs/emacs/lisp/replace.el,v
retrieving revision 1.249
diff -u -r1.249 replace.el
--- lisp/replace.el     21 Jan 2007 03:53:11 -0000      1.249
+++ lisp/replace.el     14 Feb 2007 12:09:31 -0000
@@ -1728,6 +1728,7 @@
   (if query-replace-lazy-highlight
       (let ((isearch-string string)
            (isearch-regexp regexp)
+           (search-whitespace-regexp nil)
            (isearch-case-fold-search case-fold))
        (isearch-lazy-highlight-new-loop range-beg range-end))))

reply via email to

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