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.
The goal being to keep all versions of a given file.
My elisp is rusty--I know how I would do the
number locate and increment on the buffer text
but not for an arbitrary string.
Or better yet, is there a package out there
to do something similar?
Thanks in advance,
Keith
Version control.
,----[ (info "(emacs)Version Control") ]
| The Emacs version control interface is called VC. Its commands work
| with different version control systems--currently, it supports CVS, GNU
| Arch, RCS, Meta-CVS, Subversion, and SCCS. Of these, the GNU project
| distributes CVS, GNU Arch, and RCS; we recommend that you use either
| CVS or GNU Arch for your projects, and RCS for individual files. We
| also have free software to replace SCCS, known as CSSC; if you are
| using SCCS and don't want to make the incompatible change to RCS or
| CVS, you can switch to CSSC.
`----
--
Leo <sdl.web AT gmail.com> (GPG Key: 9283AA3F)
> 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
> * Keithv (2006-12-13 12:37 -0800) said:
> ^^^^^^
>> Or better yet, is there a package out there
>> to do something similar?
> Version control.
> ,----[ (info "(emacs)Version Control") ]
[snip]
There's also the version-control variable in files.el.
Regards,
Dan
--
Dan Sommers
<http://www.tombstonezero.net/dan/>
"I wish people would die in alphabetical order." -- My wife, the genealogist
,----[ C-h v version-control RET ]
| version-control is a variable defined in `files.el'.
| Its value is nil
|
| Documentation:
| *Control use of version numbers for backup files.
| t means make numeric backup versions unconditionally.
| nil means make them for files that have some already.
| `never' means do not make them.
|
| You can customize this variable.
|
| [back]
`----
--
Kevin