emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: query-replace-interactive not documented


From: David Kastrup
Subject: Re: query-replace-interactive not documented
Date: 15 Jun 2004 22:23:36 +0200
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50

Juri Linkov <address@hidden> writes:

> David Kastrup <address@hidden> 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.

Ok.

> > 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).

It is not even unneeded, it is even completely wrong.  That is why
there had been the 'literal stuff in the first place.  You can use
things like \1 and \2 also in the Lisp expression, and if they match,
say, \footnote, things will go horribly wrong because of that
additional backslash interpretation.

> Anyway, with the current implementation all three expressions below
> produce the same replacement for the entire string:
> 
> \& = \'\& = \'"\\&"

The latter is wrong IMO.  A string is a string is a string.

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum




reply via email to

[Prev in Thread] Current Thread [Next in Thread]