2

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

1

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) "#")
    (expand-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.

  • Ah ok, this might be it. Anything for TRAMP mode? – Urda Mar 20 '10 at 17:56
  • 3
    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. – viam0Zah Mar 22 '10 at 7:30
5

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.