[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: elisp, replace-regexp and re-search-forward
From: |
weber |
Subject: |
Re: elisp, replace-regexp and re-search-forward |
Date: |
Mon, 01 Oct 2007 20:03:31 -0000 |
User-agent: |
G2/1.0 |
On Oct 1, 1:21 pm, Bastien <b...@altern.org> wrote:
> Seweryn Kokot <s.ko...@po.opole.pl> writes:
> > and one which doesn't work
>
> > (defun insert-empty-lines (beg end)
> > (interactive "r")
> > (goto-char beg)
> > (while (re-search-forward "\n" end t)
> > (replace-match "\n\n" nil nil)))
>
> Since your modifying the text within the region, the region end moves.
> You should perhaps use markers to track these moves:
>
> (defun insert-empty-lines (beg end)
> (interactive "r")
> (let* ((end-marker (make-marker))
> (end-marker (set-marker endm end)))
> (save-excursion
> (goto-char beg)
> (while (re-search-forward "\n" end-marker t)
> (replace-match "\n\n" nil nil)))))
>
> See (info "(elisp)Markers")
>
> --
> Bastien
I had totally missed that. Please forgive me for posting the snippet
of malfunctioning code.
-weber