5

I would like to put all of my auto-save files into a directory, say something like

~/.emacs-saves

Based on what's written in the wiki, I came up with this:

(setq backup-by-copying t      ; don't clobber symlinks
      backup-directory-alist '(("." . "~/.emacs-saves"))    ; don't litter my fs tree
      delete-old-versions t
      kept-new-versions 6
      kept-old-versions 2
      version-control t)       ; use versioned backups
(setq auto-save-file-name-transforms
      `((".*" "~/.emacs-saves" t)))

Now my autosaves are going in my home directory, which is actually kind of an improvement, but not what I want.

Can someone explain to me what I'm doing wrong, and how to correct it? I'm also very interested in what this syntax means (It's an example from the wiki entry):

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

What's with the comma in ,temporary-file-directory?

6

Put a slash at the end of your string. It's a directory.

(setq auto-save-file-name-transforms
  `((".*" "~/.emacs-saves/" t)))

The comma is used in the backquote notation.

(setq x 123)
(setq y `(my-x ,x))
(setq z (list 'my-x x)) ;; same as y
  • 1
    auto-save-file-name-transforms doesn't even need to be set to put all the backups into one directory. Only backup-directory-alist is needed. – erikstokes Nov 7 '15 at 2:53
  • regarding the above comment - this question is asking about auto-save files and not backup files. – Kevin Buchs Oct 28 '16 at 15:06
  • ahh that slash at the end fixed it for me! That has been bugging me for too long – Jesse Nov 21 '17 at 16:09
1

I had the same problem and now I use:

(let ((my-auto-save-dir (locate-user-emacs-file "auto-save")))
  (setq auto-save-file-name-transforms
        `((".*" ,(expand-file-name "\\2" my-auto-save-dir) t)))
  (unless (file-exists-p my-auto-save-dir)
    (make-directory my-auto-save-dir)))
(setq auto-save-default t
      auto-save-timeout 10
      auto-save-interval 200)

I don't now what "\\2" exactly does (maybe someone will explain) but it works correct, found it at (https://stackoverflow.com/questions/15302973/emacs-auto-save-why-are-files-not-stored-in-the-correct-folder).

You can also replace setq part of the above example by:

  (setq auto-save-file-name-transforms
        `((".*" ,(file-name-as-directory my-auto-save-dir) t))))
  • According to documentation, locate-user-emacs-file creates the directory if it doesn't exist, so the unless-section shouldn't be needed. The documentation seems to be lying though, according to my tests. – Pianosaurus Jun 6 at 17:54
  • And "\\2" is a back reference to the second matching group of the regex in the first element of auto-save-file-name-transforms (".*" in your code). There is no second matching group, so I think this works as expected by random chance. I haven't tested it. – Pianosaurus Jun 6 at 17:57
0

You need only the backup dir set correctly:

(setq backup-directory-alist '(("." . "~/.emacs-saves")))

I don't have any trailing / either. Also as erikstokes mentioned above, you don't need auto-save-file-name-transforms for backups to work.

  • backup-directory-alist is needed to put backups into one directory, auto-save-file-name-transforms is needed to put autosaves into one directory. Not clear if the OP wants both. – npostavs Nov 7 '15 at 15:28
  • 3
    This question is asking about auto-save files and not backup files. – Kevin Buchs Oct 28 '16 at 15:07

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.