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: Seweryn Kokot
Subject: Re: elisp, replace-regexp and re-search-forward
Date: Mon, 01 Oct 2007 18:11:06 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/23.0.50 (gnu/linux)

weber <address@hidden> writes:

> Another version imitates what you would do if you were going to do it
> manually (jump one line, press ret, jump one line..) :
>
> (defun insert-lines (beg end)
>   (interactive "r")
>   (goto-char beg)
>   (while (< (point) end)
>       (insert "\n")
>       (next-line 1)))
>
> Regards,
> weber

thanks for another approach. However I needed to modify the function a
little. So now I have two working functions

; works
(defun insert-lines (beg end)
  (interactive "r")
  (save-excursion
        (let ((line 1)
                  (region-lines (count-lines beg end)))
          (goto-char beg)
          (while (< line region-lines)
                (end-of-line)
                (insert "\n")
                (forward-line)
                (setq line (+ line 1))))))

; works
(defun my-test (beg end)
  (interactive "r")
  (replace-regexp "\n" "\n\n" nil beg end))

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

namely if I select the following region from 1 (mark at 1) to 7 (mark
after 7)

1
2
3
4
5
6
7

I get something like this

1

2

3

4

5
6
7

(note that there is no \n after 5 and 6). It seems that the replacement
doesn't reach the end bound which was after number 7.  Any ideas what is
wrong?

regards,
-- 
Seweryn Kokot





reply via email to

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