help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Backup Blacklist


From: Juanma Barranquero
Subject: Re: Backup Blacklist
Date: Tue, 2 Jan 2007 02:51:00 +0100

On 1/1/07, Matthew Flaschen <matthew.flaschen@gatech.edu> wrote:

Does anyone know a good way to maintain a blacklist of files that will
never be backed up by emacs?

If I understand correctly what you're asking for, I use something
similar to the following on my .emacs:

(require 'cl)
(require 'regexp-opt)

;; Set this to t or nil if you don't want the default.
;; It is used in my-backup-enable-predicate
(defvar my-backup-case-fold case-fold-search)

(defun my-exclude-from-backup (&rest files)
 "Exclude from backup all filenames in FILES.
They must be absolute paths.
Other files are passed to `normal-backup-enable-predicate',
so is still possible for them to be excluded anyway."
 (let ((excluded (get 'my-exclude-from-backup :files)))
   (mapc #'(lambda (file)
             (unless (file-name-absolute-p file)
               (error "%s is not an absolute filename" file))
             (pushnew file excluded :test #'equal))
         files)
   (put 'my-exclude-from-backup :files excluded)
   (put 'my-exclude-from-backup
        :regexp (concat "^" (regexp-opt excluded) "$"))))

(defun my-backup-enable-predicate (file)
 "Alternate `backup-enable-predicate' function that excludes from
backups those files registered with `my-exclude-from-backup'."
 (let ((regexp (get 'my-exclude-from-backup :regexp)))
   (if (and regexp
            (let ((case-fold-search my-backup-case-fold))
              (string-match regexp file)))
       nil
     (normal-backup-enable-predicate file))))

(setq backup-enable-predicate 'my-backup-enable-predicate)

;; and now, you can exclude files from backup with:
(my-exclude-from-backup "/this/file" "/that/other/file")


                   /L/e/k/t/u




reply via email to

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