[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Mon, 04 Oct 2004 21:52:34 -0400
Gnus/5.110002 (No Gnus v0.2) Emacs/21.3.50 (gnu/linux)
I know emacs makes backup files (~-files) but that appears to take
place among file visits (series of opens and closes), not among file
saves. Since I keep files open for weeks (months? :)), sometimes, I
needed a solution that backs up at every save. Now, time to buy a
new hard disk. :)
;;; backup-each-save.el --- backup each savepoint of a file
;; Copyright (C) 2004 Free Software Foundation, Inc.
;; Author: Benjamin Rutt <address@hidden>
;; Version: 1.0
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;; Ever wish to go back to an older saved version of a file? Then
;; this package is for you. This package copies every file you save
;; in emacs to a backup directory tree (which mirrors the tree
;; structure of the filesystem), with a timestamp suffix to make
;; multiple saves of the same file unique. Never lose old saved
;; versions again.
;; To activate, place this file in your `load-path', and add the
;; following line to your ~/.emacs file:
;; (add-hook 'after-save-hook 'backup-each-save)
;; Features/bug reports/enhancements welcome. -- Benjamin Rutt
(defvar backup-each-save-mirror-location "~/.backups")
(defvar backup-each-save-remote-files nil
"Whether to backup remote files at each save.
Defaults to nil.")
(defvar backup-each-save-time-format "%Y_%m_%d_%H_%M_%S"
"Format given to `format-time-string' which is appended to the filename.")
(defun backup-each-save ()
(let ((bfn (buffer-file-name)))
(when (or backup-each-save-remote-files
(not (file-remote-p bfn)))
(copy-file bfn (backup-each-save-compute-location bfn) t))))
(defun backup-each-save-compute-location (filename)
(let* ((containing-dir (file-name-directory filename))
(basename (file-name-nondirectory filename))
(when (not (file-exists-p backup-container))
(make-directory backup-container t))
(format "%s/%s-%s" backup-container basename
Benjamin Rutt <=