On Oct 1, 6:08 am, "Bourgneuf Francois" wrote: > You don't need to use a regexp. > (query-replace "\n" "\n\n") will do the job > Bour9 > > > -----Message d'origine----- > > De : > > help-gnu-emacs-bounces+francois.bourgneuf=groupe-mma...@gnu.or > > g > > [mailto:help-gnu-emacs-bounces+francois.bourgneuf=groupe-mma.f > > r...@gnu.org] De la part de Seweryn Kokot > > Envoyé : lundi 1 octobre 2007 09:57 > > À : help-gnu-em...@gnu.org > > Objet : elisp, replace-regexp and re-search-forward > > > 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? > > > _______________________________________________ > > help-gnu-emacs mailing list > > help-gnu-em...@gnu.org > >http://lists.gnu.org/mailman/listinfo/help-gnu-emacs 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