help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Using lisp code in query-replace-regexp


From: Julien Cubizolles
Subject: Re: Using lisp code in query-replace-regexp
Date: Tue, 04 Nov 2014 21:58:06 +0100
User-agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/25.0.50 (gnu/linux)

Andreas Röhler <andreas.roehler@easy-emacs.de> writes:

> When writing a program, for example start with
>
> (narrow-to-region beg end)
> (goto-char (point-min))
> (while (re-search-forward RE end)
> (replace-match ...

Thanks for this example, it allows me to add the test I needed in the
mix. However, I'd rather be prompted for each replace. I tried with
replace-match-maybe-edit:

--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---

but it messes up the excursion. If I use replace-match, the excursion is
preserved however.

Julien.




reply via email to

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