Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an Emacs variable to turn off backup of files with a specific extension?

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

like image 911
justinhj Avatar asked Jan 27 '09 03:01

justinhj


2 Answers

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.

like image 157
Sean Bright Avatar answered Sep 27 '22 22:09

Sean Bright


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)
like image 26
scottfrazer Avatar answered Sep 27 '22 22:09

scottfrazer