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-regexp-eval is quite nice, but... Date: 02 Feb 2004 12:19:28 +0100 Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: References: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1075724977 11741 80.91.224.253 (2 Feb 2004 12:29:37 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 2 Feb 2004 12:29:37 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Mon Feb 02 13:29:29 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 1AndCj-0000qB-00 for ; Mon, 02 Feb 2004 13:29:29 +0100 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1AndCg-0006Js-00 for ; Mon, 02 Feb 2004 13:29:26 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AndAp-0006vs-7n for emacs-devel@quimby.gnus.org; Mon, 02 Feb 2004 07:27:31 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.24) id 1And5i-0006KQ-Cf for emacs-devel@gnu.org; Mon, 02 Feb 2004 07:22:14 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.24) id 1Ancjy-0003OL-Ah for emacs-devel@gnu.org; Mon, 02 Feb 2004 07:00:17 -0500 Original-Received: from [199.232.76.164] (helo=fencepost.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1Anca3-0002AJ-3f for emacs-devel@gnu.org; Mon, 02 Feb 2004 06:49:31 -0500 Original-Received: from fencepost.gnu.org ([127.0.0.1] helo=lola.goethe.zz) by fencepost.gnu.org with esmtp (Exim 4.24) id 1AncYk-0005lt-Fv; Mon, 02 Feb 2004 06:48:11 -0500 Original-To: Andreas Schwab In-Reply-To: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50 Original-Lines: 56 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.2 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:19650 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:19650 Andreas Schwab writes: > David Kastrup writes: > > > The description tells us > > > > [...] > > > > TO-EXPR is a Lisp expression evaluated to compute each > > replacement. It may reference `replace-count' to get the number > > of replacements already made. If the result of TO-EXPR is not a > > string, it is converted to one using `prin1-to-string' with the > > NOESCAPE argument (which see). > > > > For convenience, when entering TO-EXPR interactively, you can use > > `\&' or `\0' to stand for whatever matched the whole of REGEXP, > > and `\N' (where N is a digit) to stand for whatever matched the > > Nth `\(...\)' in REGEXP. Use `\#&' or `\#N' if you want a number > > instead of a string. > > > > So the idea is to build your replacement string with Lisp, and this > > is quite an excellent thing. It is completely defeated because the > > replacement is then done non-literally. Which means that if > > \0 > > would have matched \footnote, replacing the string just with \0 (which > > one would expect to do nothing in effect) will barf because the > > regexp replacer will not know what \f is supposed to be. > > I agree this is a bug. > > > Is there anybody that would make a case for a non-literal > > replacement? If not, is there anybody with enough of a clue to find > > out how to fix this? I have taken a look at perform-replace, but it > > does not seem to offer an option for literal replacement for > > regexps. Should we add one? > > Currently, perform-replace uses literal replacement for all non-regexp > searches, and non-literal otherwise. What we could do is offer a special > version of match-string that quotes backslashes and use that in > replace-match-string-symbols. But that means only that you get \0 and its ilk quoted. The idea of query-replace-regexp-eval is to build your replacement string yourself. And I won't get anything else quoted then. I'll be perfectly able to enter (concat "buzz" &1 &2) instead of "buzz\\1\\2". Really, I don't see any purpose whatsoever to do a non-literal replacement here: all building blocks that a non-literal string would be able to access are equally available in a form convenient for replacements. -- David Kastrup, Kriemhildstr. 15, 44793 Bochum