|
From: | Bastien |
Subject: | Re: elisp, replace-regexp and re-search-forward |
Date: | Mon, 01 Oct 2007 18:21:56 +0200 |
User-agent: | Gnus/5.110007 (No Gnus v0.7) Emacs/23.0.0 (gnu/linux) |
Seweryn Kokot <s.kokot@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
[Prev in Thread] | Current Thread | [Next in Thread] |