emacs-devel
[Top][All Lists]
Advanced

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

Re: regexp repacement, how to present replacement to user?


From: Juri Linkov
Subject: Re: regexp repacement, how to present replacement to user?
Date: Mon, 15 Oct 2007 01:50:01 +0300
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/23.0.50 (gnu/linux)

> I basically have a loop of `re-search-forward' with optional `replace-match'
> after that.  I'd like to ask user if the particular match should be replaced
> or not.  However, I'd like to present user with end-result strings, i.e. not
> regexp and replacement with \N strings, but the match string and what
> replacement would be in this case.  The former is as easy as (match-string 0),
> but the second is not obvious how to do.
>
> I.e., to clarify, I'd like this:
>
>       Replace "foo-bar" with "foo bar"?
>
> instead of this:
>
>       Replace "\([[:alpha:]]+\)-\([[:alpha:]]+\)" with "\1 \2"?

Something like this?

(let ((from "\\([[:alpha:]]+\\)-\\([[:alpha:]]+\\)")
      (to "\\1 \\2"))
  (while (re-search-forward from nil t)
    (if (y-or-n-p (format "Replace %s with %s "
                          (match-string 0)
                          (replace-regexp-in-string from to (match-string 0))))
        (replace-match to nil nil))))

-- 
Juri Linkov
http://www.jurta.org/emacs/




reply via email to

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