summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Kastrup <dak@gnu.org>2004-06-25 11:02:08 +0000
committerDavid Kastrup <dak@gnu.org>2004-06-25 11:02:08 +0000
commitb5f9b70b7e276048099b8af00ac93cebbd52bbe5 (patch)
tree149ae0060600738f0fa9909b2c33dd895f0c8555
parent3b3602821edc19270e11953ae5b6762b3d980dca (diff)
downloademacs-b5f9b70b7e276048099b8af00ac93cebbd52bbe5.tar.gz
(Regexp Replace): Some typo corrections and
rearrangement.
-rw-r--r--man/ChangeLog5
-rw-r--r--man/search.texi36
2 files changed, 24 insertions, 17 deletions
diff --git a/man/ChangeLog b/man/ChangeLog
index 74f161fc51e..a3fbdf4d2e2 100644
--- a/man/ChangeLog
+++ b/man/ChangeLog
@@ -1,3 +1,8 @@
+2004-06-25 David Kastrup <dak@gnu.org>
+
+ * search.texi (Regexp Replace): Some typo corrections and
+ rearrangement.
+
2004-06-24 David Kastrup <dak@gnu.org>
* search.texi (Unconditional Replace): Use replace-string instead
diff --git a/man/search.texi b/man/search.texi
index 9b065a8fac8..6eafedf7749 100644
--- a/man/search.texi
+++ b/man/search.texi
@@ -1018,12 +1018,13 @@ performs the inverse transformation.
You can also use arbitrary Lisp expressions evaluated at replacement
time by placing @samp{\,} before them in the replacement string. Inside
-of those expressions, the symbols @samp{\&} and @samp{\@var{d}} refer to
-match and submatch strings like described above (a submatch not matching
-anything will be @samp{nil}), and @samp{\&#} and @samp{\@var{d}#} to
-those strings converted to numbers. @samp{\#} is short for
-@samp{replace-count}, the number of already completed replacements.
-This particular shorthand can also be used outside of @samp{\,}.
+of those expressions, the symbols @samp{\&} and @samp{\@var{n}} refer to
+match and submatch strings like described above (though @var{n} may
+exceed 9 here, and you get @code{nil} if nothing matches). @samp{\#&}
+and @samp{\#@var{n}} refer to those strings converted to numbers.
+@samp{\#} is short for @samp{replace-count}, the number of already
+completed replacements. This particular shorthand can also be used
+outside of @samp{\,}.
Repeating our example to exchange @samp{x} and @samp{y}, we can thus
do it also this way:
@@ -1033,11 +1034,21 @@ M-x replace-regexp @key{RET} \(x\)\|y @key{RET}
\,(if \1 "y" "x") @key{RET}
@end example
+ One function that comes handy in Lisp replacements is @samp{format}
+(@pxref{Formatting Strings,,,elisp, GNU Emacs Lisp Reference Manual}).
+For example, to add consecutively numbered strings like @samp{ABC00042}
+to columns 73 @w{to 80} (unless they are already occupied), you can use
+
+@example
+M-x replace-regexp @key{RET} ^.\@{0,72\@}$ @key{RET}
+\,(format "%-72sABC%05d" \& \#) @key{RET}
+@end example
+
Another feature you can use in the replacement string of Regexp
commands is @samp{\?}. In that case you will be allowed to edit the
replacement string at the given position before the replacement gets
-performed. Lisp style replacements have already been done before
-@samp{\?} is executed. For example,
+performed. Lisp style replacements are performed before @samp{\?} gets
+executed. For example,
@example
M-x replace-regexp @key{RET} \footnote@{ @key{RET}
@@ -1050,15 +1061,6 @@ will add labels starting with @samp{\label@{fn:0@}} to occurences of
performing it. If you want labels starting at 1, use @samp{\,(1+ \#)}
instead of @samp{\#}.
-As another example, to add consecutively numbered strings like
-@samp{ABC00042} to column 73 to~80 (unless they are already occupied),
-you can use
-
-@example
-M-x replace-regexp @key{RET} ^.\@{0,72\@}$ @key{RET}
-\,(format "%-72sABC%05d" \& \#) @key{RET}
-@end example
-
@node Replacement and Case, Query Replace, Regexp Replace, Replace
@subsection Replace Commands and Case