Reputation: 11306
For example when editing various data files, the backup data is no use and actually trips up our tools. So I'd like to be able to disable backup for files containing a regexp in the name.
justinhj
Upvotes: 5
Views: 1721
Reputation: 11923
You could always ask emacs to put the backup/autosave files in your home dir.
http://amitp.blogspot.com/2007/03/emacs-move-autosave-and-backup-files.html
(defvar user-temporary-file-directory
(concat temporary-file-directory user-login-name "/"))
(make-directory user-temporary-file-directory t)
(setq backup-by-copying t)
(setq backup-directory-alist
`(("." . ,user-temporary-file-directory)
(,tramp-file-name-regexp nil)))
(setq auto-save-list-file-prefix
(concat user-temporary-file-directory ".auto-saves-"))
(setq auto-save-file-name-transforms
`((".*" ,user-temporary-file-directory t)))
Upvotes: 3
Reputation: 17327
If you want to use the built-in Emacs functionality do something like this:
(defvar my-backup-ignore-regexps (list "foo.*" "\\.bar$")
"*List of filename regexps to not backup")
(defun my-backup-enable-p (name)
"Filter certain file backups"
(when (normal-backup-enable-predicate name)
(let ((backup t))
(mapc (lambda (re)
(setq backup (and backup (not (string-match re name)))))
my-backup-ignore-regexps)
backup)))
(setq backup-enable-predicate 'my-backup-enable-p)
Upvotes: 5
Reputation: 120644
I hate to simply reference other online resources for questions like these, but this appears to be a perfect fit for your needs.
http://anirudhs.chaosnet.org/blog/2005.01.21.html
Once you've setup what's described on that page, you could just add this to your .emacs
or .emacs.d/init.el
file depending on your version of emacs:
(setq auto-mode-alist (append '(("\\.ext1$" . sensitive-mode)) auto-mode-alist))
(setq auto-mode-alist (append '(("\\.ext2$" . sensitive-mode)) auto-mode-alist))
(setq auto-mode-alist (append '(("\\.ext3$" . sensitive-mode)) auto-mode-alist))
(setq auto-mode-alist (append '(("\\.ext4$" . sensitive-mode)) auto-mode-alist))
Where \\.ext1$
, \\.ext2$
, etc. are the regular expressions that match the filenames you don't want backups for.
Upvotes: 9