Search code examples
emacsautosave

Emacs auto-save: Why are files not stored in the correct folder?


I looked in various places and finally came up with the following setup for 'auto-save' mode in Emacs:

(defvar my-auto-save-folder (concat "~/.emacs.d/auto-save")); folder for auto-saves
(setq auto-save-list-file-prefix "~/.emacs.d/auto-save/.saves-"); set prefix for auto-saves 
(setq auto-save-file-name-transforms `((".*", my-auto-save-folder t))); location for all auto-save files
(setq tramp-auto-save-directory my-auto-save-folder); auto-save tramp files in local directory

After having this setup for some weeks, I visited ~/.emacs.d and found that the folder ~/.emacs.d/auto-save is empty, while ~/.emacs.d contained two auto-save files of the form #!home!<myusername>!<myfolder>!<myfile>. Why are the auto-save files not stored in ~/.emacs.d/auto-save? [the folder auto-save has rights 775, .emacs.d 700]


Solution

  • Your error is in:

    (defvar my-auto-save-folder (concat "~/.emacs.d/auto-save")); folder for auto-saves
    

    (the call to concat with a single argument is pointless, incidentally).

    If the optional element UNIQUIFY is non-nil, the auto-save file name is constructed by taking the directory part of the replaced file-name, concatenated with the buffer file name with all directory separators changed to `!' to prevent clashes.

    Emacs identifies directory names by a trailing /, which means that "the directory part" of the path you've used is "~/.emacs.d/".

    You want:

    (defvar my-auto-save-folder "~/.emacs.d/auto-save/"); folder for auto-saves
    

    The positioning of the comma in the following is also strange (although apparently it still works):

    `((".*", my-auto-save-folder t)))
    

    That should really be:

    `((".*" ,my-auto-save-folder t)))