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 20:03:31 -0000 [thread overview]
Message-ID: <1191269011.977459.214730@57g2000hsv.googlegroups.com> (raw)
In-Reply-To: <mailman.1550.1191255727.18990.help-gnu-emacs@gnu.org>
On Oct 1, 1:21 pm, Bastien <b...@altern.org> wrote:
> Seweryn Kokot <s.ko...@po.opole.pl> writes:
> > and one which doesn't work
>
> > (defun insert-empty-lines (beg end)
> > (interactive "r")
> > (goto-char beg)
> > (while (re-search-forward "\n" end t)
> > (replace-match "\n\n" nil nil)))
>
> Since your modifying the text within the region, the region end moves.
> You should perhaps use markers to track these moves:
>
> (defun insert-empty-lines (beg end)
> (interactive "r")
> (let* ((end-marker (make-marker))
> (end-marker (set-marker endm end)))
> (save-excursion
> (goto-char beg)
> (while (re-search-forward "\n" end-marker t)
> (replace-match "\n\n" nil nil)))))
>
> See (info "(elisp)Markers")
>
> --
> Bastien
I had totally missed that. Please forgive me for posting the snippet
of malfunctioning code.
-weber
next prev parent reply other threads:[~2007-10-01 20:03 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 ` 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 [this message]
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=1191269011.977459.214730@57g2000hsv.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).