views:

396

answers:

3

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

+6  A: 

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.

Sean Bright
But of course, you lose the usual functionality of the auto-mode-alist when you set it up this way. I would just (add-hook 'some-mode-hook #'sensitive-mode) to the modes that you don't want backups for.
jrockway
Thanks Sean, that's working out well.jrockway: I'm not sure of the implications of what I'm losing. I guess you mean that sensitive-mode becomes the only mode for those files? I can't have .obj files opened in c or html mode for example?
justinhj
+2  A: 

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

Nifle
+3  A: 

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)
scottfrazer
+1 for built-in solution.
Ryan Thompson