unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Bastien <bzg@altern.org>
To: Seweryn Kokot <s.kokot@po.opole.pl>
Cc: help-gnu-emacs@gnu.org
Subject: Re: elisp, replace-regexp and re-search-forward
Date: Mon, 01 Oct 2007 18:21:56 +0200	[thread overview]
Message-ID: <87odfikdp7.fsf@bzg.ath.cx> (raw)
In-Reply-To: <87wsu6lsrp.fsf@poczta.po.opole.pl> (Seweryn Kokot's message of "Mon, 01 Oct 2007 18:11:06 +0200")

Seweryn Kokot <s.kokot@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

  reply	other threads:[~2007-10-01 16:21 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 [this message]
     [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=87odfikdp7.fsf@bzg.ath.cx \
    --to=bzg@altern.org \
    --cc=help-gnu-emacs@gnu.org \
    --cc=s.kokot@po.opole.pl \
    /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).