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 11:36:50 -0000
User-agent: G2/1.0

On Oct 1, 6:08 am, "Bourgneuf Francois" <address@hidden
mma.fr> wrote:
>  You don't need to use a regexp.
> (query-replace "\n" "\n\n") will do the job
> Bour9
>
> > -----Message d'origine-----
> > De :
> > address@hidden
> > g
> > [mailto:help-gnu-emacs-bounces+francois.bourgneuf=groupe-mma.f
> > address@hidden De la part de Seweryn Kokot
> > Envoyé : lundi 1 octobre 2007 09:57
> > À : address@hidden
> > 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
> > address@hidden
> >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



reply via email to

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