--- search.texi 21 May 2004 00:24:35 +0200 1.44 +++ search.texi 24 Jun 2004 13:36:08 +0200 @@ -1016,6 +1016,39 @@ @noindent 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 @address@hidden refer to +matches and submatches like above (a submatch not matching anything will +be @samp{nil}), and @samp{\&#} and @address@hidden to those strings +converted to numbers. @samp{\#} is short for @samp{replace-count}, the +number of already completed replacements. + + Repeating our example to exchange @samp{x} and @samp{y}, we can thus +do it also this way: + address@hidden +M-x query-replace-regexp @key{RET} \(x\)\|y @key{RET} +\,(if \1 "y" "x") @key{RET} address@hidden example + + Another feature you can use in the replacement text 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 address@hidden is executed. For example, + address@hidden +M-x query-replace-regexp @key{RET} address@hidden @{RET} +\&address@hidden:address@hidden @{RET} address@hidden example + address@hidden +will offer to add labels starting with @address@hidden:address@hidden to +occurences of @address@hidden, but will offer you to edit each +replacement before performing it. If you want labels starting at 1, use address@hidden,(1+ \#)} instead of @samp{\#}. + @node Replacement and Case, Query Replace, Regexp Replace, Replace @subsection Replace Commands and Case