]> code.delx.au - gnu-emacs/commitdiff
* lisp/replace.el (replace-lax-whitespace): New defcustom.
authorJuri Linkov <juri@jurta.org>
Thu, 6 Sep 2012 08:49:40 +0000 (11:49 +0300)
committerJuri Linkov <juri@jurta.org>
Thu, 6 Sep 2012 08:49:40 +0000 (11:49 +0300)
(query-replace, query-replace-regexp, query-replace-regexp-eval)
(replace-string, replace-regexp): Mention it in docstrings.
(perform-replace, replace-highlight): Let-bind
isearch-lax-whitespace and isearch-regexp-lax-whitespace according
to the values of replace-lax-whitespace and regexp-flag.
Don't let-bind search-whitespace-regexp.

* lisp/isearch.el (isearch-query-replace): Let-bind
replace-lax-whitespace instead of let-binding
replace-search-function and replace-re-search-function.
(isearch-lazy-highlight-search): Let-bind isearch-lax-whitespace
and isearch-regexp-lax-whitespace to lazy-highlight variables.
(isearch-toggle-symbol): Set isearch-regexp to nil
in isearch-word mode (like in isearch-toggle-word).

Fixes: debbugs:10885
etc/NEWS
lisp/ChangeLog
lisp/isearch.el
lisp/replace.el

index 5ddb4ed4a1e44d611a7e2f3997915c0b168fdc01..ed59f3264abfa4f9035fabef3b78e94d8be14197 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -197,6 +197,13 @@ of one or more whitespace characters defined by the variable
 `isearch-lax-whitespace'.  In regexp incremental search, it toggles
 the value of the variable `isearch-regexp-lax-whitespace'.
 
 `isearch-lax-whitespace'.  In regexp incremental search, it toggles
 the value of the variable `isearch-regexp-lax-whitespace'.
 
+** query-replace changes
+
+*** When new option `replace-lax-whitespace' is non-nil,
+and you enter a space or spaces in the strings or regexps
+to be replaced, `query-replace' will match any sequence matched
+by the regexp `search-whitespace-regexp'.
+
 ** M-x move-to-column, if called interactively with no prefix arg, now
 prompts for a column number.
 
 ** M-x move-to-column, if called interactively with no prefix arg, now
 prompts for a column number.
 
index b1dff7e5dc4c285b549888c8e47393c4ba4a425d..ccc517973b3505667101021556ac7689a650cdf3 100644 (file)
@@ -1,3 +1,21 @@
+2012-09-06  Juri Linkov  <juri@jurta.org>
+
+       * replace.el (replace-lax-whitespace): New defcustom.
+       (query-replace, query-replace-regexp, query-replace-regexp-eval)
+       (replace-string, replace-regexp): Mention it in docstrings.
+       (perform-replace, replace-highlight): Let-bind
+       isearch-lax-whitespace and isearch-regexp-lax-whitespace according
+       to the values of replace-lax-whitespace and regexp-flag.
+       Don't let-bind search-whitespace-regexp.  (Bug#10885)
+
+       * isearch.el (isearch-query-replace): Let-bind
+       replace-lax-whitespace instead of let-binding
+       replace-search-function and replace-re-search-function.
+       (isearch-lazy-highlight-search): Let-bind isearch-lax-whitespace
+       and isearch-regexp-lax-whitespace to lazy-highlight variables.
+       (isearch-toggle-symbol): Set isearch-regexp to nil
+       in isearch-word mode (like in isearch-toggle-word).
+
 2012-09-06  Juri Linkov  <juri@jurta.org>
 
        * replace.el (replace-search-function)
 2012-09-06  Juri Linkov  <juri@jurta.org>
 
        * replace.el (replace-search-function)
index e6e0a01566a8d28d79d9eed94a4ceed97ae17db2..328e4eb447fcbf322f9bd84f31a8505f90576ea0 100644 (file)
@@ -1405,6 +1405,7 @@ Use `isearch-exit' to quit without signaling."
   (interactive)
   (setq isearch-word (unless (eq isearch-word 'isearch-symbol-regexp)
                       'isearch-symbol-regexp))
   (interactive)
   (setq isearch-word (unless (eq isearch-word 'isearch-symbol-regexp)
                       'isearch-symbol-regexp))
+  (if isearch-word (setq isearch-regexp nil))
   (setq isearch-success t isearch-adjusted t)
   (isearch-update))
 
   (setq isearch-success t isearch-adjusted t)
   (isearch-update))
 
@@ -1579,14 +1580,11 @@ way to run word replacements from Isearch is `M-s w ... M-%'."
        ;; set `search-upper-case' to nil to not call
        ;; `isearch-no-upper-case-p' in `perform-replace'
        (search-upper-case nil)
        ;; set `search-upper-case' to nil to not call
        ;; `isearch-no-upper-case-p' in `perform-replace'
        (search-upper-case nil)
-       (replace-search-function
-        (if (and isearch-lax-whitespace (not regexp-flag))
-            #'search-forward-lax-whitespace
-          replace-search-function))
-       (replace-re-search-function
-        (if (and isearch-regexp-lax-whitespace regexp-flag)
-            #'re-search-forward-lax-whitespace
-          replace-re-search-function))
+       (replace-lax-whitespace
+        (and search-whitespace-regexp
+             (if isearch-regexp
+                 isearch-regexp-lax-whitespace
+               isearch-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.
        ;; 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.
@@ -2956,10 +2954,14 @@ 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)
            (isearch-word isearch-lazy-highlight-word)
       (let ((case-fold-search isearch-lazy-highlight-case-fold-search)
            (isearch-regexp isearch-lazy-highlight-regexp)
            (isearch-word isearch-lazy-highlight-word)
+           (isearch-lax-whitespace
+            isearch-lazy-highlight-lax-whitespace)
+           (isearch-regexp-lax-whitespace
+            isearch-lazy-highlight-regexp-lax-whitespace)
+           (isearch-forward isearch-lazy-highlight-forward)
            (search-invisible nil)      ; don't match invisible text
            (retry t)
            (success nil)
            (search-invisible nil)      ; don't match invisible text
            (retry t)
            (success nil)
-           (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
            (bound (if isearch-lazy-highlight-forward
                       (min (or isearch-lazy-highlight-end-limit (point-max))
                            (if isearch-lazy-highlight-wrapped
index f9f97dfe48537c65b66b2d883ec6fa04199fd260..194805a8f3e803127ff2b16246490bb479e7efed 100644 (file)
   :type 'boolean
   :group 'matching)
 
   :type 'boolean
   :group 'matching)
 
+(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,
+it will match any sequence matched by the regexp `search-whitespace-regexp'."
+  :type 'boolean
+  :group 'matching
+  :version "24.3")
+
 (defvar query-replace-history nil
   "Default history list for query-replace commands.
 See `query-replace-from-history-variable' and
 (defvar query-replace-history nil
   "Default history list for query-replace commands.
 See `query-replace-from-history-variable' and
@@ -226,6 +234,10 @@ letters.  \(Transferring the case pattern means that if the old text
 matched is all caps, or capitalized, then its replacement is upcased
 or capitalized.)
 
 matched is all caps, or capitalized, then its replacement is upcased
 or capitalized.)
 
+If `replace-lax-whitespace' is non-nil, a space or spaces in the string
+to be replaced will match a sequence of whitespace chars defined by the
+regexp in `search-whitespace-regexp'.
+
 Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace
 only matches surrounded by word boundaries.
 Fourth and fifth arg START and END specify the region to operate on.
 Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace
 only matches surrounded by word boundaries.
 Fourth and fifth arg START and END specify the region to operate on.
@@ -270,6 +282,10 @@ pattern of the old text to the new text, if `case-replace' and
 all caps, or capitalized, then its replacement is upcased or
 capitalized.)
 
 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
+to be replaced will match a sequence of whitespace chars defined by the
+regexp in `search-whitespace-regexp'.
+
 Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace
 only matches surrounded by word boundaries.
 Fourth and fifth arg START and END specify the region to operate on.
 Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace
 only matches surrounded by word boundaries.
 Fourth and fifth arg START and END specify the region to operate on.
@@ -346,6 +362,10 @@ minibuffer.
 Preserves case in each replacement if `case-replace' and `case-fold-search'
 are non-nil and REGEXP has no uppercase letters.
 
 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
+to be replaced will match a sequence of whitespace chars defined by the
+regexp in `search-whitespace-regexp'.
+
 Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace
 only matches that are surrounded by word boundaries.
 Fourth and fifth arg START and END specify the region to operate on."
 Third arg DELIMITED (prefix arg if interactive), if non-nil, means replace
 only matches that are surrounded by word boundaries.
 Fourth and fifth arg START and END specify the region to operate on."
@@ -437,6 +457,10 @@ are non-nil and FROM-STRING has no uppercase letters.
 \(Preserving case means that if the string matched is all caps, or capitalized,
 then its replacement is upcased or capitalized.)
 
 \(Preserving case means that if the string matched is all caps, or capitalized,
 then its replacement is upcased or capitalized.)
 
+If `replace-lax-whitespace' is non-nil, a space or spaces in the string
+to be replaced will match a sequence of whitespace chars defined by the
+regexp in `search-whitespace-regexp'.
+
 In Transient Mark mode, if the mark is active, operate on the contents
 of the region.  Otherwise, operate from point to the end of the buffer.
 
 In Transient Mark mode, if the mark is active, operate on the contents
 of the region.  Otherwise, operate from point to the end of the buffer.
 
@@ -475,6 +499,10 @@ and TO-STRING is also null.)"
 Preserve case in each match if `case-replace' and `case-fold-search'
 are non-nil and REGEXP has no uppercase letters.
 
 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
+to be replaced will match a sequence of whitespace chars defined by the
+regexp in `search-whitespace-regexp'.
+
 In Transient Mark mode, if the mark is active, operate on the contents
 of the region.  Otherwise, operate from point to the end of the buffer.
 
 In Transient Mark mode, if the mark is active, operate on the contents
 of the region.  Otherwise, operate from point to the end of the buffer.
 
@@ -1760,6 +1788,10 @@ make, or the user didn't cancel the call."
                replace-search-function)
              (let ((isearch-regexp regexp-flag)
                    (isearch-word delimited-flag)
                replace-search-function)
              (let ((isearch-regexp regexp-flag)
                    (isearch-word delimited-flag)
+                   (isearch-lax-whitespace
+                    (and replace-lax-whitespace (not regexp-flag)))
+                   (isearch-regexp-lax-whitespace
+                    (and replace-lax-whitespace regexp-flag))
                    (isearch-case-fold-search case-fold-search)
                    (isearch-forward t))
                (isearch-search-fun))))
                    (isearch-case-fold-search case-fold-search)
                    (isearch-forward t))
                (isearch-search-fun))))
@@ -2113,7 +2145,10 @@ make, or the user didn't cancel the call."
       (let ((isearch-string search-string)
            (isearch-regexp regexp-flag)
            (isearch-word delimited-flag)
       (let ((isearch-string search-string)
            (isearch-regexp regexp-flag)
            (isearch-word delimited-flag)
-           (search-whitespace-regexp nil)
+           (isearch-lax-whitespace
+            (and replace-lax-whitespace (not regexp-flag)))
+           (isearch-regexp-lax-whitespace
+            (and replace-lax-whitespace regexp-flag))
            (isearch-case-fold-search case-fold-search)
            (isearch-forward t)
            (isearch-error nil))
            (isearch-case-fold-search case-fold-search)
            (isearch-forward t)
            (isearch-error nil))