Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What do I need to add to my .emacs to get it to save all of my autosaves and backups into one directory? I don't do a lot of .emacs configuration, and I just can't get the variables out of emacsWiki to play right. Anybody mind sharing how they do it? I would prefer to have the saves placed in /tmp/emacs/{username}/{autosaves | backups}

BONUS, configuration to do the same for TRAMP

share|improve this question
up vote 1 down vote accepted

Try this gnu emacs backup files
GNU Emacs

;; Put autosave files (ie #foo#) in one place, *not*
;; scattered all over the file system!
(defvar autosave-dir
 (concat "/tmp/emacs_autosaves/" (user-login-name) "/"))

(make-directory autosave-dir t)

(defun auto-save-file-name-p (filename)
  (string-match "^#.*#$" (file-name-nondirectory filename)))

(defun make-auto-save-file-name ()
  (concat autosave-dir
   (if buffer-file-name
      (concat "#" (file-name-nondirectory buffer-file-name) "#")
     (concat "#%" (buffer-name) "#")))))

;; Put backup files (ie foo~) in one place too. (The backup-directory-alist
;; list contains regexp=>directory mappings; filenames matching a regexp are
;; backed up in the corresponding directory. Emacs will mkdir it if necessary.)
(defvar backup-dir (concat "/tmp/emacs_backups/" (user-login-name) "/"))
(setq backup-directory-alist (list (cons "." backup-dir)))

A version for XEmacs can be found if you follow the link at the top of this answer.

share|improve this answer
Ah ok, this might be it. Anything for TRAMP mode? – Urda Mar 20 '10 at 17:56
Too much magic. Only customizing backup-directory-alist's value is needed. Type M-x customize-variable backup-directory-alist and set to the preferred "catchall" directory. No need for dotemacs editing. – Török Gábor Mar 22 '10 at 7:30

From AutoSave on emacswiki:

(setq backup-directory-alist
      `((".*" . ,temporary-file-directory)))
(setq auto-save-file-name-transforms
      `((".*" ,temporary-file-directory t)))

There is also some info on tweaking the settings with TRAMP in mind as well.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .