|
From: | David Kastrup |
Subject: | Re: regexp repacement, how to present replacement to user? |
Date: | Mon, 15 Oct 2007 07:57:31 +0200 |
User-agent: | Gnus/5.11 (Gnus v5.11) Emacs/22.1.50 (gnu/linux) |
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))) [...] -- David Kastrup, Kriemhildstr. 15, 44793 Bochum
[Prev in Thread] | Current Thread | [Next in Thread] |