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
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With