From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: David Kastrup Newsgroups: gmane.emacs.devel Subject: Search/Replace manual changes. Date: 24 Jun 2004 15:44:30 +0200 Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: sea.gmane.org 1088084692 2727 80.91.224.253 (24 Jun 2004 13:44:52 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 24 Jun 2004 13:44:52 +0000 (UTC) Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Thu Jun 24 15:44:44 2004 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1BdUWx-00073d-00 for ; Thu, 24 Jun 2004 15:44:43 +0200 Original-Received: from lists.gnu.org ([199.232.76.165]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1BdUWx-00009W-00 for ; Thu, 24 Jun 2004 15:44:43 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1BdUYM-0000iJ-Ot for emacs-devel@quimby.gnus.org; Thu, 24 Jun 2004 09:46:10 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1BdUYJ-0000iD-89 for emacs-devel@gnu.org; Thu, 24 Jun 2004 09:46:09 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1BdUYI-0000i0-Jl for emacs-devel@gnu.org; Thu, 24 Jun 2004 09:46:06 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1BdUYI-0000hx-HN for emacs-devel@gnu.org; Thu, 24 Jun 2004 09:46:06 -0400 Original-Received: from [199.232.76.164] (helo=fencepost.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.34) id 1BdUWm-0008Jd-Ov for emacs-devel@gnu.org; Thu, 24 Jun 2004 09:44:32 -0400 Original-Received: from localhost ([127.0.0.1] helo=lola.goethe.zz) by fencepost.gnu.org with esmtp (Exim 4.34) id 1BdUWl-0006CC-Vs for emacs-devel@gnu.org; Thu, 24 Jun 2004 09:44:32 -0400 Original-To: emacs-devel@gnu.org Original-Lines: 10 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:25225 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:25225 --=-=-= Ok, here are revised manual entries. I am checking them in now, so you can take changes from there. I think that the added examples are instructive enough to keep them all. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment --- search.texi 21 May 2004 00:24:35 +0200 1.44 +++ search.texi 24 Jun 2004 15:19:43 +0200 @@ -977,9 +977,9 @@ 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: @example -M-x query-replace @key{RET} x @key{RET} @@TEMP@@ @key{RET} -M-x query-replace @key{RET} y @key{RET} x @key{RET} -M-x query-replace @key{RET} @@TEMP@@ @key{RET} y @key{RET} +M-x replace-string @key{RET} x @key{RET} @@TEMP@@ @key{RET} +M-< M-x replace-string @key{RET} y @key{RET} x @key{RET} +M-< M-x replace-string @key{RET} @@TEMP@@ @key{RET} y @key{RET} @end example @noindent @@ -1016,6 +1016,49 @@ @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 @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{\,}. + + Repeating our example to exchange @samp{x} and @samp{y}, we can thus +do it also this way: + +@example +M-x replace-regexp @key{RET} \(x\)\|y @key{RET} +\,(if \1 "y" "x") @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, + +@example +M-x replace-regexp @key{RET} \footnote@{ @key{RET} +\&\\label@{fn:\#\?@} @key{RET} +@end example + +@noindent +will add labels starting with @samp{\label@{fn:0@}} to occurences of +@samp{\footnote@{}, but letting you edit each replacement before +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 @@ -1126,9 +1169,8 @@ @item ^ to go back to the position of the previous occurrence (or what used to -be an occurrence), in case you changed it by mistake. This works by -popping the mark ring. Only one @kbd{^} in a row is meaningful, because -only one previous replacement position is kept during @code{query-replace}. +be an occurrence), in case you changed it by mistake or want to +reexamine it. @item C-r to enter a recursive editing level, in case the occurrence needs to be --=-=-= -- David Kastrup, Kriemhildstr. 15, 44793 Bochum --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-devel --=-=-=--