[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: write-file like function help needed

From: Juanma Barranquero
Subject: Re: write-file like function help needed
Date: Wed, 13 Dec 2006 23:24:57 +0100

On 13 Dec 2006 12:37:17 -0800, keithv <address@hidden> 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))))


reply via email to

[Prev in Thread] Current Thread [Next in Thread]