summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2021-08-16 13:20:35 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2021-08-16 13:20:35 +0200
commit751f1707f009c714dbfe047ef43443a5c0c3df89 (patch)
treeaf4841befe93c09b6e28851fa5c20e57be9abbc5 /doc
parent42be41657813ae606427aa53d2f0f0b7039d3ef1 (diff)
downloademacs-751f1707f009c714dbfe047ef43443a5c0c3df89.tar.gz
Add new functions to replace strings/regexp in a region
* doc/lispref/searching.texi (Search and Replace): Document them. * lisp/subr.el (replace-string-in-region) (replace-regexp-in-region): New functions. * lisp/emacs-lisp/shortdoc.el (regexp, buffer): Mention them.
Diffstat (limited to 'doc')
-rw-r--r--doc/lispref/searching.texi26
1 files changed, 20 insertions, 6 deletions
diff --git a/doc/lispref/searching.texi b/doc/lispref/searching.texi
index 1d3e2d986c5..fe47e7ccf57 100644
--- a/doc/lispref/searching.texi
+++ b/doc/lispref/searching.texi
@@ -2540,9 +2540,9 @@ associated with it still exists.
@cindex replacement after search
@cindex searching and replacing
- If you want to find all matches for a regexp in part of the buffer,
-and replace them, the best way is to write an explicit loop using
-@code{re-search-forward} and @code{replace-match}, like this:
+ If you want to find all matches for a regexp in part of the buffer
+and replace them, the most flexible way is to write an explicit loop
+using @code{re-search-forward} and @code{replace-match}, like this:
@example
(while (re-search-forward "foo[ \t]+bar" nil t)
@@ -2553,9 +2553,23 @@ and replace them, the best way is to write an explicit loop using
@xref{Replacing Match,, Replacing the Text that Matched}, for a
description of @code{replace-match}.
- However, replacing matches in a string is more complex, especially
-if you want to do it efficiently. So Emacs provides two functions to do
-this.
+@findex replace-regexp-in-region
+ If it's more convenient, you can also use the
+@code{replace-regexp-in-region}, which does something similar to the
+loop above, but is optionally delimited to a specific region (and
+doesn't change point). Furthermore, it does the searches
+case-sensitively, and performs the replacements without changing case
+in the replacement.
+
+@example
+(replace-regexp-in-region "foo[ \t]+bar" "foobar")
+@end example
+
+@findex replace-string-in-region
+ There's also @code{replace-string-in-region}, which works along the
+same lines, but searches for literal strings instead.
+
+ Emacs also has special functions for replacing matches in a string.
@defun replace-regexp-in-string regexp rep string &optional fixedcase literal subexp start
This function copies @var{string} and searches it for matches for