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

[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:06:24 -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 was testing that here and it looks like the first "end-marker"
should be "endm".
Cheers!
weber



reply via email to

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