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:03:31 -0000
User-agent: G2/1.0

On Oct 1, 1:21 pm, Bastien <address@hidden> wrote:
> Seweryn Kokot <address@hidden> 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



reply via email to

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