[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
elisp, replace-regexp and re-search-forward
From: |
Seweryn Kokot |
Subject: |
elisp, replace-regexp and re-search-forward |
Date: |
Mon, 1 Oct 2007 07:56:54 +0000 (UTC) |
User-agent: |
Loom/3.14 (http://gmane.org/) |
Hello,
I try to write a function that operate on a region and which inserts a newline
between each line, for example.
from:
aaa
bbb
ccc
to:
aaa
bbb
ccc
-------
My first attempt is the following function which does the job
(defun my-test (beg end)
(interactive "r")
(replace-regexp "\n" "\n\n" nil beg end))
however in Emacs help for replace-regexp I see that it is not good to use
replace-regexp function. Instead it is recommended to use re-search-forward and
replace-match. So I try with such a function, but it does not work.
(defun my-test-two (beg end)
(interactive "r")
(while (re-search-forward "\n" end t)
(replace-match "\n\n" nil nil)))
Any idea what is wrong?
- elisp, replace-regexp and re-search-forward,
Seweryn Kokot <=