Emanuel Berg <[email protected]> writes:

> Julien Cubizolles <[email protected]> writes:
>
>> I can use the following replace string (for lack of
>> a better term) with query-replace-regexp
>
> Yes, you can do that.
>
> Check out this:
>
> (while (re-search-forward REGEXP nil t)
>   (replace-match TO-STRING nil nil))
>
> from the help of `replace-regexp'.
>
> So instead of the `replace-match' stuff above, you
> write a function that examines `match-beginning',
> `match-end', and `match-string', and then use that as
> input to your Elisp, to produce the on-the-fly
> TO-STRING (in the phrasing of the above Elisp).

I came up with

--8<---------------cut here---------------start------------->8---

(defun test_gen (begin end from to)
  (save-excursion
    (save-restriction
      (let (deactivate-mark)
        (narrow-to-region begin end)
        (goto-char (point-min))
        (while  (re-search-forward from end t)
          (replace-match-maybe-edit to t nil nil (match-data) nil)))
      )))
--8<---------------cut here---------------end--------------->8---

I used replace-match-maybe-edit because I wanted to be prompted for each
replacement, and replace-match wouldn't allow it. However with
replace-match-maybe-edit, the excursion is messed up at the end. It
wasn't the case with replace-match.

Julien.


_______________________________________________
info-gnus-english mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/info-gnus-english

Reply via email to