From: Juri Linkov <juri@jurta.org>
To: 10885@debbugs.gnu.org
Subject: bug#10885: Replace expressions: enhance functionality when searching in filled paragraphs
Date: Sun, 02 Sep 2012 14:32:33 +0300 [thread overview]
Message-ID: <87boho1wyz.fsf@mail.jurta.org> (raw)
In-Reply-To: <87oblo21xe.fsf@mail.jurta.org> (Juri Linkov's message of "Sun, 02 Sep 2012 12:45:33 +0300")
> 1. Add a new defcustom like `case-replace' with a name e.g.
> `replace-lax-whitespace' and use it in `perform-replace'.
> When non-nil, spaces will match any whitespace in replacement.
This is implemented in the following patch:
=== modified file 'lisp/replace.el'
--- lisp/replace.el 2012-08-06 05:33:39 +0000
+++ lisp/replace.el 2012-09-02 11:27:15 +0000
@@ -33,6 +33,13 @@ (defcustom case-replace t
: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)
+
(defvar query-replace-history nil
"Default history list for query-replace commands.
See `query-replace-from-history-variable' and
@@ -226,6 +233,10 @@ (defun query-replace (from-string to-str
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.
@@ -270,6 +281,10 @@ (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
+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.
@@ -346,6 +361,10 @@ (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
+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."
@@ -437,6 +456,10 @@ (defun replace-string (from-string to-st
\(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.
@@ -475,6 +498,10 @@ (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
+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.
@@ -1717,12 +1745,12 @@ (defun replace-match-maybe-edit (newtext
(replace-match newtext fixedcase literal)
noedit)
-(defvar replace-search-function 'search-forward
+(defvar replace-search-function nil
"Function to use when searching for strings to replace.
It is used by `query-replace' and `replace-string', and is called
with three arguments, as if it were `search-forward'.")
-(defvar replace-re-search-function 're-search-forward
+(defvar replace-re-search-function nil
"Function to use when searching for regexps to replace.
It is used by `query-replace-regexp', `replace-regexp',
`query-replace-regexp-eval', and `map-query-replace-regexp'.
@@ -1755,9 +1783,16 @@ (defun perform-replace (from-string repl
(nocasify (not (and case-replace case-fold-search)))
(literal (or (not regexp-flag) (eq regexp-flag 'literal)))
(search-function
- (if regexp-flag
- replace-re-search-function
- replace-search-function))
+ (or (if regexp-flag
+ replace-re-search-function
+ replace-search-function)
+ (if replace-lax-whitespace
+ (if regexp-flag
+ #'re-search-forward-lax-whitespace
+ #'search-forward-lax-whitespace)
+ (if regexp-flag
+ #'re-search-forward
+ #'search-forward))))
(search-string from-string)
(real-match-data nil) ; The match data for the current match.
(next-replacement nil)
@@ -2120,7 +2156,10 @@ (defun replace-highlight (match-beg matc
;; Set isearch-word to nil because word-replace is regexp-based,
;; so `isearch-search-fun' should not use `word-search-forward'.
(isearch-word nil)
- (search-whitespace-regexp nil)
+ (isearch-lax-whitespace
+ (and replace-lax-whitespace (not regexp)))
+ (isearch-regexp-lax-whitespace
+ (and replace-lax-whitespace regexp))
(isearch-case-fold-search case-fold)
(isearch-forward t)
(isearch-error nil))
=== modified file 'lisp/isearch.el'
--- lisp/isearch.el 2012-09-02 09:31:45 +0000
+++ lisp/isearch.el 2012-09-02 11:27:15 +0000
@@ -1579,14 +1612,11 @@ (defun isearch-query-replace (&optional
;; 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.
@@ -2956,6 +3045,10 @@ (defun isearch-lazy-highlight-search ()
(isearch-regexp isearch-lazy-highlight-regexp)
(isearch-word isearch-lazy-highlight-word)
(search-invisible nil) ; don't match invisible text
+ (isearch-lax-whitespace
+ isearch-lazy-highlight-lax-whitespace)
+ (isearch-regexp-lax-whitespace
+ isearch-lazy-highlight-regexp-lax-whitespace)
(retry t)
(success nil)
(isearch-forward isearch-lazy-highlight-forward)
next prev parent reply other threads:[~2012-09-02 11:32 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-26 1:02 bug#10885: Replace expressions: enhance functionality when searching in filled paragraphs linuxfever
2012-02-26 1:57 ` Glenn Morris
2012-02-26 7:16 ` Kevin Rodgers
2012-02-28 10:04 ` Dani Moncayo
2012-02-28 10:09 ` Dani Moncayo
2012-02-28 10:42 ` Juri Linkov
2012-02-29 0:12 ` Glenn Morris
2012-02-29 0:41 ` Juri Linkov
2012-03-11 8:59 ` Dani Moncayo
2012-03-11 10:48 ` Juri Linkov
2012-09-02 9:45 ` Juri Linkov
2012-09-02 11:32 ` Juri Linkov [this message]
2012-09-05 8:38 ` Juri Linkov
2012-09-05 14:38 ` Stefan Monnier
2012-09-06 8:54 ` Juri Linkov
2012-09-06 15:54 ` Dani Moncayo
2012-09-06 16:50 ` Juri Linkov
2012-09-06 17:39 ` Dani Moncayo
2012-09-06 19:11 ` Juri Linkov
2012-09-06 19:15 ` Juri Linkov
2012-09-06 19:45 ` Dani Moncayo
2012-09-06 20:21 ` Dani Moncayo
2012-09-06 21:25 ` Stefan Monnier
2012-09-07 8:33 ` Dani Moncayo
2012-09-07 9:28 ` Juri Linkov
2012-09-09 22:15 ` Juri Linkov
2012-09-05 14:39 ` Stefan Monnier
2012-02-26 10:10 ` linuxfever
2012-02-26 21:22 ` Stefan Monnier
2012-02-26 10:17 ` Dani Moncayo
2012-02-27 10:58 ` Juri Linkov
2012-02-27 13:27 ` Dani Moncayo
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87boho1wyz.fsf@mail.jurta.org \
--to=juri@jurta.org \
--cc=10885@debbugs.gnu.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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.