[Top][All Lists]
[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 17:43:52 +0200 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50 |
Juri Linkov <address@hidden> writes:
> David Kastrup <address@hidden> writes:
> > address@hidden (Kim F. Storm) writes:
> >> Richard Stallman <address@hidden> writes:
> >> > That seems like an interesting idea.
> >>
> >> I would prefer a syntax which can be parsed with `read', which
> >> includes the second example above, but not the first one.
> >
> > Well, this was of course just a wild proposal without any serious
> > thought behind the involved details. One should probably take a look
> > at eshell syntax maybe for getting some suggestions for a somewhat
> > consistent syntax, and one would need to think about a way that makes
> > it possible to end the expression in question without adding
> > unnecessary spaces or so to the match.
>
> I like this idea. To avoid problems with `read' and to end the expression
> explicitly I suggest to always place the expression in parenthesis.
> To use a single variable inside a replacement string, one can use
> a no-op function like `+':
>
> \\footnote{\\label{fn:\!(+ replace-count)}
If there are always to be parens around, then there would be no need for
!. One could just write
\\footnote{\\label{fn:\(+ replace-count\)}
I don't see a good way around having to backslash the closing paren:
if one doesn't, paren matching goes awry.
> > And of course, this sort of stuff should not be done by
> > replace-match or similar functions but just by the interactive
> > function, to avoid opening security concerns when Emacs is used as
> > a match-and-replace engine (where people don't expect it to
> > execute arbitrary code).
>
> Doing it only in the interactive function instead of `replace-match'
> seems right. This is needed only to save keystrokes for users.
> Since `replace-match' is not a command, when the programmer writes a
> loop with `re-search-forward' and `replace-match', he can construct
> a replacement string explicitly with appropriate functions.
>
> Anyway, below is a quick implementation of such a feature. I tried it
> a bit and I like it. What I don't like yet is the choice of a special
> meta symbol `\!'. Usually this symbol is associated with the error code.
> Perhaps, a better symbol would be \( itself like in:
>
> \\footnote{\\label{fn:\(+ replace-count)}
>
> but this has another problem: the open parenthesis is escaped
> and Emacs commands don't match it with the close parenthesis.
Oh shucks. That's what I get from replying before reading to the end.
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.
How about using \'? After all, we have an unevaled expression
following.
That would allow either
\\footnote{\\label{fn:\'(+ replace-count)}
or
\\footnote{\\label{fn:\'replace-count }}
Well, the latter has a spurious space. Bother.
> 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 14:56:15 -0000
> ***************
> *** 174,180 ****
> (if (and transient-mark-mode mark-active)
> (region-end)))))
>
> ! (perform-replace regexp to-string t t delimited nil nil start end))
> (define-key esc-map [?\C-%] 'query-replace-regexp)
>
> (defun query-replace-regexp-eval (regexp to-expr &optional delimited start
> end)
> --- 183,200 ----
> (if (and transient-mark-mode mark-active)
> (region-end)))))
>
> ! (if (string-match "!\(" to-string)
> ! (let (res)
> ! (while (string-match "!\(" to-string)
> ! (setq res (cons (substring to-string 0 (1- (match-beginning 0)))
> res)
> ! to-string (substring to-string (1- (match-end 0))))
> ! (let ((r (read-from-string to-string)))
> ! (setq res (cons `(format "%s" ,(car r)) res)
> ! to-string (substring to-string (cdr r)))))
> ! (perform-replace regexp `(replace-eval-replacement
> ! concat ,@(nreverse (cons to-string res)))
> ! t 'literal delimited nil nil start end))
> ! (perform-replace regexp to-string t t delimited nil nil start end)))
> (define-key esc-map [?\C-%] 'query-replace-regexp)
>
> (defun query-replace-regexp-eval (regexp to-expr &optional delimited start
> end)
First you are matching against !( not against \!( or similar. 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.
Something like that.
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
- Re: query-replace-interactive not documented, (continued)
- Re: query-replace-interactive not documented, Richard Stallman, 2004/06/11
- Re: query-replace-interactive not documented, Juri Linkov, 2004/06/12
- Re: query-replace-interactive not documented, Richard Stallman, 2004/06/12
- Re: query-replace-interactive not documented, Miles Bader, 2004/06/12
- Re: query-replace-interactive not documented, David Kastrup, 2004/06/13
- Re: query-replace-interactive not documented, Richard Stallman, 2004/06/14
- Re: query-replace-interactive not documented, Kim F. Storm, 2004/06/14
- Re: query-replace-interactive not documented, David Kastrup, 2004/06/14
- Re: query-replace-interactive not documented, Juri Linkov, 2004/06/15
- Re: query-replace-interactive not documented,
David Kastrup <=
- Re: query-replace-interactive not documented, Juri Linkov, 2004/06/15
- Re: query-replace-interactive not documented, David Kastrup, 2004/06/15
- Re: query-replace-interactive not documented, Andreas Schwab, 2004/06/15
- Re: query-replace-interactive not documented, David Kastrup, 2004/06/15
- Re: query-replace-interactive not documented, Kim F. Storm, 2004/06/15
- Re: query-replace-interactive not documented, David Kastrup, 2004/06/15
- Re: query-replace-interactive not documented, David Kastrup, 2004/06/15
- Re: query-replace-interactive not documented, Juri Linkov, 2004/06/16
- Re: query-replace-interactive not documented, David Kastrup, 2004/06/16
- Re: query-replace-interactive not documented, Juri Linkov, 2004/06/16