unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: weber <hugows@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: elisp, replace-regexp and re-search-forward
Date: Mon, 01 Oct 2007 11:36:50 -0000	[thread overview]
Message-ID: <1191238610.992573.294470@n39g2000hsh.googlegroups.com> (raw)
In-Reply-To: <mailman.1531.1191229744.18990.help-gnu-emacs@gnu.org>

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="us-ascii", Size: 1850 bytes --]

On Oct 1, 6:08 am, "Bourgneuf Francois" <francois.bourgn...@groupe-
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 :
> > 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

       reply	other threads:[~2007-10-01 11:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.1531.1191229744.18990.help-gnu-emacs@gnu.org>
2007-10-01 11:36 ` weber [this message]
2007-10-01 16:11   ` elisp, replace-regexp and re-search-forward 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1191238610.992573.294470@n39g2000hsh.googlegroups.com \
    --to=hugows@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).