From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Bastien Newsgroups: gmane.emacs.help Subject: Re: elisp, replace-regexp and re-search-forward Date: Mon, 01 Oct 2007 18:21:56 +0200 Message-ID: <87odfikdp7.fsf@bzg.ath.cx> References: <1191238610.992573.294470@n39g2000hsh.googlegroups.com> <87wsu6lsrp.fsf@poczta.po.opole.pl> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1191255752 11083 80.91.229.12 (1 Oct 2007 16:22:32 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 1 Oct 2007 16:22:32 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Seweryn Kokot Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Oct 01 18:22:29 2007 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1IcO2M-0000gH-KD for geh-help-gnu-emacs@m.gmane.org; Mon, 01 Oct 2007 18:22:26 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IcO2I-0001Ij-JN for geh-help-gnu-emacs@m.gmane.org; Mon, 01 Oct 2007 12:22:22 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IcO21-0001Hv-PP for help-gnu-emacs@gnu.org; Mon, 01 Oct 2007 12:22:05 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IcO1z-0001Hj-KJ for help-gnu-emacs@gnu.org; Mon, 01 Oct 2007 12:22:05 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IcO1z-0001Hg-FI for help-gnu-emacs@gnu.org; Mon, 01 Oct 2007 12:22:03 -0400 Original-Received: from fk-out-0910.google.com ([209.85.128.191]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1IcO1y-00085e-Vz for help-gnu-emacs@gnu.org; Mon, 01 Oct 2007 12:22:03 -0400 Original-Received: by fk-out-0910.google.com with SMTP id 19so5089339fkr for ; Mon, 01 Oct 2007 09:22:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=beta; h=domainkey-signature:received:received:received:from:to:cc:subject:in-reply-to:references:user-agent:date:message-id:mime-version:content-type:sender; bh=NR92ZcsxwGvYJo2zL4B72OoDzvXDXHHeUYyF1kVzJd4=; b=GhF4JIk9N4AM0K2v7t+3bSbn/wqBST56oqoLIQiOMaS5sjQGl8GRZjlKfpIiFSnohiSIlOXtm33CbG3Kqr37W+fEmyTG5UJgM6rBj7gH8ULFme5lSIg3g4/Q8iMT6tr7TyLgm9B0/21vr0WxpanGIJ2xmH8XzLLfOBoVzIfv7+4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=beta; h=received:from:to:cc:subject:in-reply-to:references:user-agent:date:message-id:mime-version:content-type:sender; b=VSajI74zvxfWKLU/A09XgaAK6VHQl1VKHbuzIdgCiYRs0C4IuCiTddTHGnoCdQg7LZJz4GsrADQ4v+CxnPlkdxPI/LtaE8qwl+0XlWHG5Op4171rqr5rLxi6ntjDBVMOA3R+3B5dSY0Ea869wb5nJvEEgn29SUYsoYWUgL2IwZc= Original-Received: by 10.82.119.17 with SMTP id r17mr15859425buc.1191255720340; Mon, 01 Oct 2007 09:22:00 -0700 (PDT) Original-Received: from bzg.ath.cx ( [131.227.113.23]) by mx.google.com with ESMTPS id f8sm192541nfh.2007.10.01.09.21.58 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 01 Oct 2007 09:21:59 -0700 (PDT) Original-Received: by bzg.ath.cx (Postfix, from userid 1000) id AEE5E15798B; Mon, 1 Oct 2007 18:21:56 +0200 (CEST) In-Reply-To: <87wsu6lsrp.fsf@poczta.po.opole.pl> (Seweryn Kokot's message of "Mon, 01 Oct 2007 18:11:06 +0200") User-Agent: Gnus/5.110007 (No Gnus v0.7) Emacs/23.0.0 (gnu/linux) X-Detected-Kernel: Linux 2.6 (newer, 2) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:48023 Archived-At: Seweryn Kokot 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