unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* RE: elisp, replace-regexp and re-search-forward
@ 2007-10-01  9:08 Bourgneuf Francois
  0 siblings, 0 replies; 7+ messages in thread
From: Bourgneuf Francois @ 2007-10-01  9:08 UTC (permalink / raw)
  To: help-gnu-emacs

 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.fr@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-emacs@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-emacs@gnu.org
> http://lists.gnu.org/mailman/listinfo/help-gnu-emacs
> 
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread
* elisp, replace-regexp and re-search-forward
@ 2007-10-01  7:56 Seweryn Kokot
  0 siblings, 0 replies; 7+ messages in thread
From: Seweryn Kokot @ 2007-10-01  7:56 UTC (permalink / raw)
  To: help-gnu-emacs

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?

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2007-10-01 20:06 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.1531.1191229744.18990.help-gnu-emacs@gnu.org>
2007-10-01 11:36 ` elisp, replace-regexp and re-search-forward weber
2007-10-01 16:11   ` Seweryn Kokot
2007-10-01 16:21     ` Bastien
     [not found]     ` <mailman.1550.1191255727.18990.help-gnu-emacs@gnu.org>
2007-10-01 20:03       ` weber
2007-10-01 20:06       ` weber
2007-10-01  9:08 Bourgneuf Francois
  -- strict thread matches above, loose matches on Subject: below --
2007-10-01  7:56 Seweryn Kokot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).