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: Re: query-replace-interactive not documented Date: 20 Jun 2004 23:05:25 +0200 Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: References: <20040528.181649.25475113.wl@gnu.org> <873c5jug73.fsf@mail.jurta.org> <87oenqa4lu.fsf@mail.jurta.org> <873c51w5rq.fsf@mail.jurta.org> <87659snbd8.fsf@mail.jurta.org> <87llin98sc.fsf@mail.jurta.org> <87hdtbtnsg.fsf@mail.jurta.org> <87brjhwe2c.fsf@mail.jurta.org> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1087765568 2023 80.91.224.253 (20 Jun 2004 21:06:08 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 20 Jun 2004 21:06:08 +0000 (UTC) Cc: juri@jurta.org, emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Sun Jun 20 23:06:01 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 1Bc9Vp-0002Jh-00 for ; Sun, 20 Jun 2004 23:06:01 +0200 Original-Received: from lists.gnu.org ([199.232.76.165]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1Bc9Vp-0004bG-00 for ; Sun, 20 Jun 2004 23:06:01 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1Bc9X2-0006mb-CJ for emacs-devel@quimby.gnus.org; Sun, 20 Jun 2004 17:07:16 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1Bc9Wu-0006kg-JZ for emacs-devel@gnu.org; Sun, 20 Jun 2004 17:07:08 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1Bc9Wt-0006jN-Qh for emacs-devel@gnu.org; Sun, 20 Jun 2004 17:07:08 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1Bc9Wt-0006ix-IK for emacs-devel@gnu.org; Sun, 20 Jun 2004 17:07:07 -0400 Original-Received: from [199.232.76.164] (helo=fencepost.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.34) id 1Bc9VN-0003g9-Vl for emacs-devel@gnu.org; Sun, 20 Jun 2004 17:05:34 -0400 Original-Received: from localhost ([127.0.0.1] helo=lola.goethe.zz) by fencepost.gnu.org with esmtp (Exim 4.34) id 1Bc9VG-00059n-Uq; Sun, 20 Jun 2004 17:05:27 -0400 Original-To: rms@gnu.org In-Reply-To: Original-Lines: 80 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50 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:25132 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:25132 Richard Stallman writes: > Wel, optional spaces in the middle of regexp are something that > needs extra explaining....Actually, I can't think about much > except symbols here, and maybe forms like 'symbol which end up as > a list. > > I think that is simple enough to explain. > > It does feel somewhat strange that the replacement expression > x + \,(1+ \#) + y; > would swallow a space, > > It would not swallow a space; the reader would stop after the > close paren. So what is the rule? The problem is that currently I just use read-from-string, and that can't distinguish between 'symbol and (quote symbol) even though it sounds as though both should be treated differently. > Have you taken a look at the DOC-string of the currently checked-in > version of query-replace-regexp? > > No. Did you check something in that doesn't agree with what > I've said? You are quoting it. > These two paragraphs of doc string > > When this function is called interactively, the replacement text > can also contain `\\,' followed by a Lisp expression. The escaped > shorthands for `query-replace-regexp-eval' are also valid > here: within the Lisp expression, you can use `\\&' for the whole > match string, `\\N' for partial matches, `\\#&' and `\\#N' for > the respective numeric values, and `\\#' for `replace-count'. > > If your Lisp expression is an identifier and the next > letter in the replacement string would be interpreted as part of it, > you can wrap it with an expression like `\\,(or \\#)'. Incidentally, > for this particular case you may also enter `\\#' in the replacement > text directly. > > would be clearer as follows: > > When this function is called interactively, the replacement text > can also contain `\\,' followed by a Lisp expression. Each > replacement evaluates that expression to compute the replacement > string. In the expression, you can use `\\&' for the whole > match string, `\\N' for partial matches, and `\\#' for the > sequence number (origin-zero) of this replacement. > > If the replacement expression is a symbol, write a space after it > to terminate it. That's cheating. It does not tell that this space will actually get gobbled and won't appear in the replacement. It does not tell just _when_ such spaces will get gobbled. It does not tell how many of them might get gobbled. So it is too easy. I don't think you can do this much shorter than: If the replacement expression is a symbol, then it may be followed by one optional space that won't appear in the actual replacement. > I left out the part about `\\#&' and `\\#N' because I don't > understand what they do. I am not sure what "respective numeric > values" means. When I tried \#&, it seemed to insert the > replacement count followed by an &. Not _within_ a Lisp expression, namely something like \,(format "%d %d" \#& \#2). And if you had a match like \([0-9]+\), then you can do arithmetic on it with something like \,(1+ \#1). -- David Kastrup, Kriemhildstr. 15, 44793 Bochum