From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: query-replace-interactive not documented Date: Tue, 15 Jun 2004 21:17:02 +0300 Organization: JURTA Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <878yeoadpd.fsf@mail.jurta.org> References: <20040528.181649.25475113.wl@gnu.org> <200405291737.i4THbPJ06689@raven.dms.auburn.edu> <873c5jug73.fsf@mail.jurta.org> <87oenqa4lu.fsf@mail.jurta.org> <873c51w5rq.fsf@mail.jurta.org> <87659snbd8.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 1087324304 32458 80.91.224.253 (15 Jun 2004 18:31:44 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 15 Jun 2004 18:31:44 +0000 (UTC) Cc: emacs-devel@gnu.org, rms@gnu.org, storm@cua.dk Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Tue Jun 15 20:31:26 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 1BaIiU-0001Wd-00 for ; Tue, 15 Jun 2004 20:31:26 +0200 Original-Received: from lists.gnu.org ([199.232.76.165]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1BaIiU-00056g-00 for ; Tue, 15 Jun 2004 20:31:26 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1BaIjR-0001G6-Ky for emacs-devel@quimby.gnus.org; Tue, 15 Jun 2004 14:32:25 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1BaIiU-0000tb-3d for emacs-devel@gnu.org; Tue, 15 Jun 2004 14:31:26 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1BaIiQ-0000sN-1D for emacs-devel@gnu.org; Tue, 15 Jun 2004 14:31:25 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1BaIiP-0000s0-MU for emacs-devel@gnu.org; Tue, 15 Jun 2004 14:31:21 -0400 Original-Received: from [66.33.205.9] (helo=spatula.dreamhost.com) by monty-python.gnu.org with esmtp (Exim 4.34) id 1BaIgu-0001Bc-SH; Tue, 15 Jun 2004 14:29:49 -0400 Original-Received: from mail.jurta.org (80-235-43-19-dsl.mus.estpak.ee [80.235.43.19]) by spatula.dreamhost.com (Postfix) with ESMTP id A1F9C17D021; Tue, 15 Jun 2004 11:29:39 -0700 (PDT) Original-To: David Kastrup In-Reply-To: (David Kastrup's message of "15 Jun 2004 17:43:52 +0200") User-Agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3.50 (gnu/linux) 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:25006 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:25006 David Kastrup writes: > Anyway, since it appears that we can hardly avoid using non-escaped > parens if we want to make use of the Lisp reader as well as paren > matching, one might as well use the original proposal allowing a > variable name directly. Yes, I think paren matching is needed for editing Lisp expressions in the minibuffer. > How about using \'? After all, we have an unevaled expression > following. In regexps \' is used to match the empty string at the end of the buffer. But perhaps in the replacement string this symbol is free to use. Also in some pattern-matching languages like Perl $' is an alias for $POSTMATCH. But I don't see what it could mean in the context of `query-replace-regexp'. So unless a potential meaning for \' in `query-replace-regexp' will be proposed, I think \' is a good symbol which would have mnemonics of quoting Lisp expression. > First you are matching against !( not against \!( or similar. OK, this is the easiest part. I tried different prefixes and messed up the latest one. > Then you are not replacing any \1 \2 or similar sequences as far as > I can see. It will probably not be easy to do this right: have the > \( replacement not being interpreted afterwards, but the non-evalled > ones still being interpreted. Probably one needs to explicitly > double any \ returned from the evaluation, and then call > perform-replace with "t" instead of 'literal. Replacing backreferences in expressions is easy: it is just one call to `replace-match-string-symbols'. Replacing them in strings is easy as well: just using t instead of `literal'. However, this has one side-effect: when evaluation returns a string in the form \D, then it is substituted later for the Dth occurrence. But I think this is right: it allows to construct replacement strings by Lisp expressions (though, it is not very needed). Anyway, with the current implementation all three expressions below produce the same replacement for the entire string: \& = \'\& = \'"\\&" Here is the newest version. I tested it a little, and it seems it works in all mentioned cases. Index: replace.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/replace.el,v retrieving revision 1.172 diff -c -r1.172 replace.el *** replace.el 10 Jun 2004 04:21:14 -0000 1.172 --- replace.el 15 Jun 2004 17:57:28 -0000 *************** *** 174,179 **** --- 183,199 ---- (if (and transient-mark-mode mark-active) (region-end))))) + (if (string-match "\\\\'" to-string) + (let (to expr) + (while (string-match "\\\\'" to-string) + (setq to (cons (substring to-string 0 (match-beginning 0)) to) + to-string (substring to-string (match-end 0)) + expr (read-from-string to-string) + to (cons `(format "%s" ,(car expr)) to) + to-string (substring to-string (cdr expr)))) + (setq to (nreverse (cons to-string to))) + (replace-match-string-symbols to) + (setq to-string `(replace-eval-replacement concat ,@to)))) (perform-replace regexp to-string t t delimited nil nil start end)) (define-key esc-map [?\C-%] 'query-replace-regexp) -- Juri Linkov http://www.jurta.org/emacs/