bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#10885: Replace expressions: enhance functionality when searching in


From: Juri Linkov
Subject: bug#10885: Replace expressions: enhance functionality when searching in filled paragraphs
Date: Fri, 07 Sep 2012 12:28:59 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2.50 (x86_64-pc-linux-gnu)

> I think replace-regexp-lax-whitespace is needed while the Isearch
> counterpart (isearch-regexp-lax-whitespace) exists, if you want to
> support the option I was asking for, whereby the lax-whitespace
> settings in query-replace[-regexp] are "connected" (or "redirected")
> to the Isearch counterparts.
>
> And IMO this option is important, for a consistent user-experience.

The reason why replace-regexp-lax-whitespace is important to have
is not just for consistency but because replace-lax-whitespace
should not affect regexp replacements.  But currently its value applies
to regexp replacements because it depends on calls from isearch that has
a separate variable for regexp that starts a lax-whitespace regexp replacement
to replace the same regexp matches as in isearch.  So actually a lax-whitespace
regexp replacement feature exists in replace.el implicitly.  A clean way to
fix this problem is to add a new option replace-regexp-lax-whitespace:

=== modified file 'lisp/replace.el'
--- lisp/replace.el     2012-09-06 09:12:16 +0000
+++ lisp/replace.el     2012-09-07 09:27:35 +0000
@@ -35,7 +35,15 @@ (defcustom case-replace t
 
 (defcustom replace-lax-whitespace nil
   "Non-nil means `query-replace' matches a sequence of whitespace chars.
-When you enter a space or spaces in the strings or regexps to be replaced,
+When you enter a space or spaces in the strings to be replaced,
+it will match any sequence matched by the regexp `search-whitespace-regexp'."
+  :type 'boolean
+  :group 'matching
+  :version "24.3")
+
+(defcustom replace-regexp-lax-whitespace nil
+  "Non-nil means `query-replace-regexp' matches a sequence of whitespace chars.
+When you enter a space or spaces in the regexps to be replaced,
 it will match any sequence matched by the regexp `search-whitespace-regexp'."
   :type 'boolean
   :group 'matching
@@ -282,7 +290,7 @@ (defun query-replace-regexp (regexp to-s
 all caps, or capitalized, then its replacement is upcased or
 capitalized.)
 
-If `replace-lax-whitespace' is non-nil, a space or spaces in the regexp
+If `replace-regexp-lax-whitespace' is non-nil, a space or spaces in the regexp
 to be replaced will match a sequence of whitespace chars defined by the
 regexp in `search-whitespace-regexp'.
 
@@ -362,7 +370,7 @@ (defun query-replace-regexp-eval (regexp
 Preserves case in each replacement if `case-replace' and `case-fold-search'
 are non-nil and REGEXP has no uppercase letters.
 
-If `replace-lax-whitespace' is non-nil, a space or spaces in the regexp
+If `replace-regexp-lax-whitespace' is non-nil, a space or spaces in the regexp
 to be replaced will match a sequence of whitespace chars defined by the
 regexp in `search-whitespace-regexp'.
 
@@ -499,7 +507,7 @@ (defun replace-regexp (regexp to-string
 Preserve case in each match if `case-replace' and `case-fold-search'
 are non-nil and REGEXP has no uppercase letters.
 
-If `replace-lax-whitespace' is non-nil, a space or spaces in the regexp
+If `replace-regexp-lax-whitespace' is non-nil, a space or spaces in the regexp
 to be replaced will match a sequence of whitespace chars defined by the
 regexp in `search-whitespace-regexp'.
 
@@ -1790,9 +1798,9 @@ (defun perform-replace (from-string repl
              (let ((isearch-regexp regexp-flag)
                    (isearch-word delimited-flag)
                    (isearch-lax-whitespace
-                    (and replace-lax-whitespace (not regexp-flag)))
+                    replace-lax-whitespace)
                    (isearch-regexp-lax-whitespace
-                    (and replace-lax-whitespace regexp-flag))
+                    replace-regexp-lax-whitespace)
                    (isearch-case-fold-search case-fold-search)
                    (isearch-forward t))
                (isearch-search-fun))))
@@ -2151,9 +2159,9 @@ (defun replace-highlight (match-beg matc
            (isearch-regexp regexp-flag)
            (isearch-word delimited-flag)
            (isearch-lax-whitespace
-            (and replace-lax-whitespace (not regexp-flag)))
+            replace-lax-whitespace)
            (isearch-regexp-lax-whitespace
-            (and replace-lax-whitespace regexp-flag))
+            replace-regexp-lax-whitespace)
            (isearch-case-fold-search case-fold-search)
            (isearch-forward t)
            (isearch-error nil))

=== modified file 'lisp/isearch.el'
--- lisp/isearch.el     2012-09-06 09:12:16 +0000
+++ lisp/isearch.el     2012-09-07 09:27:42 +0000
@@ -1613,10 +1613,9 @@ (defun isearch-query-replace (&optional
        ;; `isearch-no-upper-case-p' in `perform-replace'
        (search-upper-case nil)
        (replace-lax-whitespace
-        (and search-whitespace-regexp
-             (if isearch-regexp
-                 isearch-regexp-lax-whitespace
-               isearch-lax-whitespace)))
+        isearch-lax-whitespace)
+       (replace-regexp-lax-whitespace
+        isearch-regexp-lax-whitespace)
        ;; Set `isearch-recursive-edit' to nil to prevent calling
        ;; `exit-recursive-edit' in `isearch-done' that terminates
        ;; the execution of this command when it is non-nil.






reply via email to

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