unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: David Kastrup <dak@gnu.org>
Cc: emacs-devel@gnu.org, rms@gnu.org, storm@cua.dk
Subject: Re: query-replace-interactive not documented
Date: 15 Jun 2004 17:43:52 +0200	[thread overview]
Message-ID: <x5y8mog72f.fsf@lola.goethe.zz> (raw)
In-Reply-To: <87659snbd8.fsf@mail.jurta.org>

Juri Linkov <juri@jurta.org> writes:

> David Kastrup <dak@gnu.org> writes:
> > storm@cua.dk (Kim F. Storm) writes:
> >> Richard Stallman <rms@gnu.org> 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

  reply	other threads:[~2004-06-15 15:43 UTC|newest]

Thread overview: 101+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-05-28 16:16 query-replace-interactive not documented Werner LEMBERG
2004-05-29 17:02 ` Richard Stallman
2004-05-29 17:37   ` Luc Teirlinck
2004-05-29 20:33     ` Juri Linkov
2004-06-11  8:19       ` Juri Linkov
2004-06-11  8:39         ` Kim F. Storm
2004-06-11  9:00         ` David Kastrup
2004-06-12  8:21           ` Juri Linkov
2004-06-12  1:50         ` Richard Stallman
2004-06-12  8:16           ` Juri Linkov
2004-06-13  0:01             ` Richard Stallman
2004-06-13  0:46               ` Miles Bader
2004-06-13  9:03               ` David Kastrup
2004-06-14 18:50                 ` Richard Stallman
2004-06-14 20:49                   ` Kim F. Storm
2004-06-14 21:20                     ` David Kastrup
2004-06-15 14:29                       ` Juri Linkov
2004-06-15 15:43                         ` David Kastrup [this message]
2004-06-15 18:17                           ` Juri Linkov
2004-06-15 20:23                             ` David Kastrup
2004-06-15 22:30                             ` Andreas Schwab
2004-06-15 22:36                               ` David Kastrup
2004-06-15 22:43                                 ` Kim F. Storm
2004-06-15 23:13                                   ` David Kastrup
2004-06-16  1:16                                     ` David Kastrup
2004-06-16  8:08                                       ` Juri Linkov
2004-06-16  9:23                                         ` David Kastrup
2004-06-16  8:02                                   ` Juri Linkov
2004-06-17  5:06                                   ` Richard Stallman
2004-06-16  8:17                               ` Juri Linkov
2004-06-16  9:01                                 ` David Kastrup
2004-06-16 17:06                                   ` Kevin Rodgers
2004-06-16  9:02                                 ` Andreas Schwab
2004-06-16  1:41                           ` Miles Bader
2004-06-16  2:01                             ` David Kastrup
2004-06-16  2:11                               ` Miles Bader
2004-06-16 16:57                           ` Richard Stallman
2004-06-15 22:25                         ` Andreas Schwab
2004-06-15 22:28                           ` Kim F. Storm
2004-06-16  9:00                             ` Juri Linkov
2004-06-16  9:25                               ` Andreas Schwab
2004-06-16  9:32                               ` David Kastrup
2004-06-16 11:30                                 ` Kim F. Storm
2004-06-16 12:15                                   ` David Kastrup
2004-06-16 14:35                                     ` David Kastrup
2004-06-16 15:23                                       ` Juri Linkov
2004-06-16 21:15                                         ` David Kastrup
2004-06-16 22:26                                           ` Kim F. Storm
2004-06-17  0:56                                             ` David Kastrup
2004-06-17 12:14                                               ` David Kastrup
2004-06-17 13:05                                                 ` Kim F. Storm
2004-06-17 13:29                                                   ` David Kastrup
2004-06-17 14:10                                                     ` Kim F. Storm
2004-06-17 14:56                                                 ` David Kastrup
2004-06-17 15:33                                                   ` Juri Linkov
2004-06-17 17:03                                                     ` David Kastrup
2004-06-18  6:43                                                       ` Juri Linkov
2004-06-18  7:13                                                         ` David Kastrup
2004-06-16 15:27                                       ` Kim F. Storm
2004-06-16 17:28                                       ` Juri Linkov
2004-06-16 21:07                                         ` David Kastrup
2004-06-17  0:47                                           ` David Kastrup
2004-06-17 23:05                                           ` Richard Stallman
2004-06-18  6:55                                             ` Juri Linkov
2004-06-19  3:19                                               ` Richard Stallman
2004-06-19  7:00                                                 ` David Kastrup
2004-06-20 19:18                                                   ` Richard Stallman
2004-06-20 21:05                                                     ` David Kastrup
2004-06-21  9:31                                                       ` Richard Stallman
2004-06-21  9:50                                                         ` David Kastrup
2004-06-22 23:16                                                           ` Richard Stallman
2004-06-25 23:12                                                         ` Juri Linkov
2004-06-26  7:34                                                           ` David Kastrup
2004-06-26 16:18                                                             ` Juri Linkov
2004-06-27 17:41                                                           ` Richard Stallman
2004-06-21  9:31                                                       ` Richard Stallman
2004-06-21  9:38                                                         ` David Kastrup
2004-06-22 23:17                                                           ` Richard Stallman
2004-06-22 23:20                                                             ` David Kastrup
2004-06-17  5:07                                 ` Richard Stallman
2004-06-14 16:59               ` Juri Linkov
2004-06-12  8:21           ` David Kastrup
2004-05-30 19:41     ` Richard Stallman
2004-05-30 22:00       ` Luc Teirlinck
2004-06-08  6:55       ` Juri Linkov
2004-06-11  8:22         ` Juri Linkov
2004-06-12  1:50           ` Richard Stallman
2004-06-18 20:00             ` isearch hooks (was: query-replace-interactive not documented) Juri Linkov
2004-06-19  1:10               ` Miles Bader
2004-06-19 18:09                 ` isearch hooks Juri Linkov
2004-06-19  3:19               ` isearch hooks (was: query-replace-interactive not documented) Richard Stallman
2004-06-19 18:36                 ` isearch hooks Juri Linkov
2004-06-20 19:18                   ` Richard Stallman
2004-06-21 21:56                     ` Juri Linkov
2004-06-22 23:17                       ` Richard Stallman
2004-06-25 18:07                         ` Juri Linkov
2004-06-27 17:41                           ` Richard Stallman
2004-06-27 22:34                             ` Juri Linkov
2004-06-28 14:57                               ` Richard Stallman
2004-06-29  0:25               ` isearch hooks (was: query-replace-interactive not documented) Stefan
2004-06-29  1:17                 ` isearch hooks Juri Linkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=x5y8mog72f.fsf@lola.goethe.zz \
    --to=dak@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=rms@gnu.org \
    --cc=storm@cua.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).