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: Paul Pogonyshev
Subject: Re: regexp repacement, how to present replacement to user?
Date: Mon, 15 Oct 2007 23:28:54 +0300
User-agent: KMail/1.7.2

David Kastrup wrote:
> Stefan Monnier <address@hidden> writes:
> 
> >> (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))))
> >
> > This work 99% with the last 1% being due to failure in boundary conditions
> > (e.g. if the pattern starts with "\\>").
> 
>      (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.  Besides,
what if Emacs regexps are slightly improved with more features, like
named groups or whatnot?

Paul




reply via email to

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