diff options
| author | David Kastrup | 2004-06-24 14:05:59 +0000 |
|---|---|---|
| committer | David Kastrup | 2004-06-24 14:05:59 +0000 |
| commit | a8e3c8d6aeab8e38d57ac47ca80e4462a62b3897 (patch) | |
| tree | 42016e8005621614a0e6fe8f09a4eea4d20380b6 | |
| parent | 1791907b101be2227c6bb95cfce2de859be3fc41 (diff) | |
| download | emacs-a8e3c8d6aeab8e38d57ac47ca80e4462a62b3897.tar.gz emacs-a8e3c8d6aeab8e38d57ac47ca80e4462a62b3897.zip | |
(Unconditional Replace): Use replace-string instead
of query-replace in example.
(Regexp Replace): Add explanations for `\,', `\#' and `\?'
sequences.
(Query Replace): Correct explanation of `^' which does not use
the mark stack.
| -rw-r--r-- | man/ChangeLog | 9 | ||||
| -rw-r--r-- | man/search.texi | 54 |
2 files changed, 57 insertions, 6 deletions
diff --git a/man/ChangeLog b/man/ChangeLog index 3266dbbeab0..74f161fc51e 100644 --- a/man/ChangeLog +++ b/man/ChangeLog | |||
| @@ -1,3 +1,12 @@ | |||
| 1 | 2004-06-24 David Kastrup <dak@gnu.org> | ||
| 2 | |||
| 3 | * search.texi (Unconditional Replace): Use replace-string instead | ||
| 4 | of query-replace in example. | ||
| 5 | (Regexp Replace): Add explanations for `\,', `\#' and `\?' | ||
| 6 | sequences. | ||
| 7 | (Query Replace): Correct explanation of `^' which does not use | ||
| 8 | the mark stack. | ||
| 9 | |||
| 1 | 2004-06-21 Nick Roberts <nickrob@gnu.org> | 10 | 2004-06-21 Nick Roberts <nickrob@gnu.org> |
| 2 | 11 | ||
| 3 | * misc.texi (Shell History Copying): Document comint-insert-input. | 12 | * misc.texi (Shell History Copying): Document comint-insert-input. |
diff --git a/man/search.texi b/man/search.texi index fbc8d24bf23..9b065a8fac8 100644 --- a/man/search.texi +++ b/man/search.texi | |||
| @@ -977,9 +977,9 @@ by word boundaries. The argument's value doesn't matter. | |||
| 977 | What if you want to exchange @samp{x} and @samp{y}: replace every @samp{x} with a @samp{y} and vice versa? You can do it this way: | 977 | What if you want to exchange @samp{x} and @samp{y}: replace every @samp{x} with a @samp{y} and vice versa? You can do it this way: |
| 978 | 978 | ||
| 979 | @example | 979 | @example |
| 980 | M-x query-replace @key{RET} x @key{RET} @@TEMP@@ @key{RET} | 980 | M-x replace-string @key{RET} x @key{RET} @@TEMP@@ @key{RET} |
| 981 | M-x query-replace @key{RET} y @key{RET} x @key{RET} | 981 | M-< M-x replace-string @key{RET} y @key{RET} x @key{RET} |
| 982 | M-x query-replace @key{RET} @@TEMP@@ @key{RET} y @key{RET} | 982 | M-< M-x replace-string @key{RET} @@TEMP@@ @key{RET} y @key{RET} |
| 983 | @end example | 983 | @end example |
| 984 | 984 | ||
| 985 | @noindent | 985 | @noindent |
| @@ -1016,6 +1016,49 @@ M-x replace-regexp @key{RET} \(c[ad]+r\)-safe @key{RET} \1 @key{RET} | |||
| 1016 | @noindent | 1016 | @noindent |
| 1017 | performs the inverse transformation. | 1017 | performs the inverse transformation. |
| 1018 | 1018 | ||
| 1019 | You can also use arbitrary Lisp expressions evaluated at replacement | ||
| 1020 | time by placing @samp{\,} before them in the replacement string. Inside | ||
| 1021 | of those expressions, the symbols @samp{\&} and @samp{\@var{d}} refer to | ||
| 1022 | match and submatch strings like described above (a submatch not matching | ||
| 1023 | anything will be @samp{nil}), and @samp{\&#} and @samp{\@var{d}#} to | ||
| 1024 | those strings converted to numbers. @samp{\#} is short for | ||
| 1025 | @samp{replace-count}, the number of already completed replacements. | ||
| 1026 | This particular shorthand can also be used outside of @samp{\,}. | ||
| 1027 | |||
| 1028 | Repeating our example to exchange @samp{x} and @samp{y}, we can thus | ||
| 1029 | do it also this way: | ||
| 1030 | |||
| 1031 | @example | ||
| 1032 | M-x replace-regexp @key{RET} \(x\)\|y @key{RET} | ||
| 1033 | \,(if \1 "y" "x") @key{RET} | ||
| 1034 | @end example | ||
| 1035 | |||
| 1036 | Another feature you can use in the replacement string of Regexp | ||
| 1037 | commands is @samp{\?}. In that case you will be allowed to edit the | ||
| 1038 | replacement string at the given position before the replacement gets | ||
| 1039 | performed. Lisp style replacements have already been done before | ||
| 1040 | @samp{\?} is executed. For example, | ||
| 1041 | |||
| 1042 | @example | ||
| 1043 | M-x replace-regexp @key{RET} \footnote@{ @key{RET} | ||
| 1044 | \&\\label@{fn:\#\?@} @key{RET} | ||
| 1045 | @end example | ||
| 1046 | |||
| 1047 | @noindent | ||
| 1048 | will add labels starting with @samp{\label@{fn:0@}} to occurences of | ||
| 1049 | @samp{\footnote@{}, but letting you edit each replacement before | ||
| 1050 | performing it. If you want labels starting at 1, use @samp{\,(1+ \#)} | ||
| 1051 | instead of @samp{\#}. | ||
| 1052 | |||
| 1053 | As another example, to add consecutively numbered strings like | ||
| 1054 | @samp{ABC00042} to column 73 to~80 (unless they are already occupied), | ||
| 1055 | you can use | ||
| 1056 | |||
| 1057 | @example | ||
| 1058 | M-x replace-regexp @key{RET} ^.\@{0,72\@}$ @key{RET} | ||
| 1059 | \,(format "%-72sABC%05d" \& \#) @key{RET} | ||
| 1060 | @end example | ||
| 1061 | |||
| 1019 | @node Replacement and Case, Query Replace, Regexp Replace, Replace | 1062 | @node Replacement and Case, Query Replace, Regexp Replace, Replace |
| 1020 | @subsection Replace Commands and Case | 1063 | @subsection Replace Commands and Case |
| 1021 | 1064 | ||
| @@ -1126,9 +1169,8 @@ to replace all remaining occurrences without asking again. | |||
| 1126 | 1169 | ||
| 1127 | @item ^ | 1170 | @item ^ |
| 1128 | to go back to the position of the previous occurrence (or what used to | 1171 | to go back to the position of the previous occurrence (or what used to |
| 1129 | be an occurrence), in case you changed it by mistake. This works by | 1172 | be an occurrence), in case you changed it by mistake or want to |
| 1130 | popping the mark ring. Only one @kbd{^} in a row is meaningful, because | 1173 | reexamine it. |
| 1131 | only one previous replacement position is kept during @code{query-replace}. | ||
| 1132 | 1174 | ||
| 1133 | @item C-r | 1175 | @item C-r |
| 1134 | to enter a recursive editing level, in case the occurrence needs to be | 1176 | to enter a recursive editing level, in case the occurrence needs to be |