From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Juanma Barranquero" Newsgroups: gmane.emacs.help Subject: Re: write-file like function help needed Date: Wed, 13 Dec 2006 23:24:57 +0100 Message-ID: References: <1166042237.856019.98270@n67g2000cwd.googlegroups.com> NNTP-Posting-Host: dough.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1166048726 27154 80.91.229.10 (13 Dec 2006 22:25:26 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 13 Dec 2006 22:25:26 +0000 (UTC) Cc: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Dec 13 23:25:23 2006 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by dough.gmane.org with esmtp (Exim 4.50) id 1GucXP-0000Sj-9d for geh-help-gnu-emacs@m.gmane.org; Wed, 13 Dec 2006 23:25:19 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GucXO-00076L-Kc for geh-help-gnu-emacs@m.gmane.org; Wed, 13 Dec 2006 17:25:18 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1GucX6-00072X-T5 for help-gnu-emacs@gnu.org; Wed, 13 Dec 2006 17:25:00 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1GucX5-0006y0-7C for help-gnu-emacs@gnu.org; Wed, 13 Dec 2006 17:25:00 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GucX5-0006xl-2Y for help-gnu-emacs@gnu.org; Wed, 13 Dec 2006 17:24:59 -0500 Original-Received: from [64.233.182.188] (helo=nf-out-0910.google.com) by monty-python.gnu.org with esmtp (Exim 4.52) id 1GucX4-0004JW-HL for help-gnu-emacs@gnu.org; Wed, 13 Dec 2006 17:24:58 -0500 Original-Received: by nf-out-0910.google.com with SMTP id d4so661777nfe for ; Wed, 13 Dec 2006 14:24:57 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=R9yk796wXC0hpRTkk17jkoB/z2aCk3SBtgcpMFOirL4E9VsUPxAxPfNJ/CqTb/E0UK5BSW3gkJN6nJACjRVrAHe1QzqQRpTzTdh49yYr5bna78cTtNTefCke7ZEmmk6QtSOAdfm6Fjl0M9X5dgoZE3VMbIMAbGq3N8wXZUOElDc= Original-Received: by 10.82.138.6 with SMTP id l6mr128504bud.1166048697190; Wed, 13 Dec 2006 14:24:57 -0800 (PST) Original-Received: by 10.82.147.2 with HTTP; Wed, 13 Dec 2006 14:24:57 -0800 (PST) Original-To: keithv In-Reply-To: <1166042237.856019.98270@n67g2000cwd.googlegroups.com> Content-Disposition: inline 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:39526 Archived-At: On 13 Dec 2006 12:37:17 -0800, keithv wrote: > I need help writing a function that works like write-file but > first modifies the file name by locating and incrementing > any numbers in the file name. For example, if the buffer > name is "test1.txt", repeatedly invoking this function > would save files with the names "test2.txt", "test3.txt", > "test4.txt", etc. (defun increment-file-name (filename) (replace-regexp-in-string "\\([0-9]+\\)[^0-9]*\\'" #'(lambda (num) (number-to-string (1+ (string-to-number num)))) filename t t 1)) (defadvice write-file (before write-file-increment activate compile) (ad-set-arg 0 (increment-file-name (ad-get-arg 0)))) /L/e/k/t/u