unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Paul Pogonyshev <pogonyshev@gmx.net>
To: emacs-devel@gnu.org
Cc: Juri Linkov <juri@jurta.org>, monnier@iro.umontreal.ca
Subject: Re: regexp repacement, how to present replacement to user?
Date: Wed, 17 Oct 2007 22:25:33 +0300	[thread overview]
Message-ID: <200710172225.33511.pogonyshev@gmx.net> (raw)
In-Reply-To: <87lka2d3id.fsf@jurta.org>

Juri Linkov wrote:
> >>      (while (re-search-forward from nil t)
> >>         (if y-or-n-p (format "Replace %s with %s "
> >>                        (match-string 0)
> >>                           (save-match-data
> >>                             (replace-match to nil nil (match-string 0)
> >>                              (prog1 nil
> >>                                (set-match-data
> >>                                  (mapcar
> >>                                    (lambda(x)(if (numberp x)
> >>                                                    (- x (match-beginning 0))
> >>                                                    x)))
> >>                                  (match-data t)))
> >
> > Thanks, but shouldn't this be a function somewhere?  I mean, it's
> > not like random peope are going to easily write such code.
> 
> `query-replace-regexp' already highlights the text matched by
> `from-regexp' in the source buffer, so the user can see the text to
> replace.  And the result of the replacement is also displayed in the
> prompt in the expanded form, so the user sees the resulting string
> before replacing it in the buffer.
> 
> The only thing I don't understand why the result of evaluating \,
> expressions is displayed in the prompt, but the result of back references
> is not.  I mean why, for instance,
> 
> C-M-% \(a\|b\) RET \,\1  \1 RET
> 
> displays
> 
> Query replacing \(a\|b\) with a \1:
> 
> but not
> 
> Query replacing \(a\|b\) with a a:

That is exactly what I'm asking for.  How to present user with expanded
string, without those \N.

In my case I want to scan a buffer for like 20 predefined regexps with
as well predefined replacements, meant only to somehow "standardize"
text.  User is not expected to edit replacement at all, he is expected
only to decide whether to replace, or to skip this case completely (e.g.
because it is a false match, regexps cannot cover all cases in a real
human-language text).

So, I want something like this:

	Replace 12,345.67 with 12 345,67 (Russian number format)?

The user doesn't need to see regexp or its replacement with back-
references.  He should see the text and proposed replacement and just
decide if it is OK, or not.  He is not interested how this particular
occurence was found, with a regexp or not, much less with which
regexp in particular.

> > Besides, what if Emacs regexps are slightly improved with more features,
> > like named groups or whatnot?
> 
> Recently Stefan improved Emacs regexps with numbered groups where a number
> can be explicitly assigned to a regexp group.

That's why I think this (replacement expansion with back-references) must
be a function inside Emacs and not written in a package.  For instance,
code (outside Emacs) written before wouldn't know about this enhancement
by Stefan.  Code written now cannot know in advance about possible future
enhancement.  But if one uses a Emacs function, he can expect that if his
code runs in e.g. Emacs 30, standard function will handle whatever regexp
syntax might evolve to by Emacs 30.

Paul

  parent reply	other threads:[~2007-10-17 19:25 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-13 14:00 regexp repacement, how to present replacement to user? Paul Pogonyshev
2007-10-14 22:50 ` Juri Linkov
2007-10-15  3:20   ` Stefan Monnier
2007-10-15  5:57     ` David Kastrup
2007-10-15 20:28       ` Paul Pogonyshev
2007-10-16 23:54         ` Juri Linkov
2007-10-17  6:06           ` David Kastrup
2007-10-17 19:25           ` Paul Pogonyshev [this message]
2007-10-20 13:53             ` [patch] " Paul Pogonyshev
2007-10-21 16:26               ` Richard Stallman
2007-10-21 19:00                 ` Paul Pogonyshev
2007-10-21 20:43                   ` Juri Linkov
2007-10-21 21:15                     ` Paul Pogonyshev
2007-10-22  1:22                   ` Stefan Monnier
2007-10-26  3:48                     ` Richard Stallman
2007-10-28 14:41                       ` Paul Pogonyshev
2007-10-29  9:22                         ` Richard Stallman
2007-10-30 14:16                           ` Juri Linkov
2007-10-31  7:46                             ` Richard Stallman
2007-10-31 21:39                               ` Paul Pogonyshev
2007-11-01  7:32                                 ` Richard Stallman
2007-11-02 20:58                                   ` Paul Pogonyshev
2007-11-10 15:01                                     ` Paul Pogonyshev
2007-11-11  5:21                                       ` Richard Stallman
2007-11-10 21:54                                     ` Juri Linkov
2007-10-23  7:12                   ` Richard Stallman
2007-10-23  8:16                     ` David Kastrup
2007-10-23 17:53                       ` Richard Stallman
2007-10-23 19:03                         ` Lennart Borgman (gmail)
2007-10-24  8:32                           ` Richard Stallman

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=200710172225.33511.pogonyshev@gmx.net \
    --to=pogonyshev@gmx.net \
    --cc=emacs-devel@gnu.org \
    --cc=juri@jurta.org \
    --cc=monnier@iro.umontreal.ca \
    /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).