Emacs: move autosave and backup files elsewhere

[Originally posted by]: http://amitp.blogspot.ca/2007/03/emacs-move-autosave-and-backup-files.html

One thing that really bugs me about Emacs is the way it clutters up my directories with backup files (filenames ending in ~) and autosave files (filenames starting with #). Fortunately there’s an easy way to move them elsewhere. Unfortunately the technique isn’t consistent across Emacs versions. In GNU Emacs 21, you can set backup-directory-alist and auto-save-file-name-transforms. In XEmacs 21, you can setbkup-backup-directory-info and auto-save-directory. Here’s what I do in GNU Emacs:

(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)))

Here’s what I do in XEmacs:

(require 'auto-save) 
(require 'backup-dir) 

(defvar user-temporary-file-directory
  (concat (temp-directory) "/" (user-login-name)))
(make-directory user-temporary-file-directory t)
(setq backup-by-copying t)
(setq auto-save-directory user-temporary-file-directory)
(setq auto-save-list-file-prefix 
         (concat user-temporary-file-directory ".auto-saves-"))
(setq bkup-backup-directory-info
      `((t ,user-temporary-file-directory full-path)))

I’m much happier with Emacs temporary files being kept out of my way.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s