4
votes

When Emacs is closed with modified buffers present, it creates a file with the format '#file_name#' for recovery purpose in its parent directory for each modified buffer (except for scratch).

When recover-file command is used when Emacs opens the next time, the previously modified buffer of the file is recovered. Even so the file #file_name# is not deleted automatically.

This would not occur if you manually kill all buffers before closing. This is a bit tedious as you would have to use the command kill-some-buffer or kill-matching buffer and say 'yes' to each of the prompts one by one.

Is there a simpler method to overcome this? It would be nice to have solutions for one or more of the following.

  • Prevent Emacs from creating a recovery file for modified buffer while closing

  • A simple command to force kill all buffers without prompt to save

  • Setting to re-route the recovery files to a different location (like ~/.emacs.d/)

(Versions: Emacs-24 on Ubuntu-12.04 / OS-X-10.9)

1
These files are called "auto save" files. Look for the corresponding documentation in Emacs's manual: C-h i followed by m emacs RET followed by i auto save mode RET.Stefan

1 Answers

6
votes

By adding the following line on your init.el file you'll disable the auto-save feature and no more of these files will be generated

(setq auto-save-default nil)

But you may want those files so you can use the code above which I borrowed from emacswiki

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

This will cause that all backup files will go to the temporary folder on your operating system. Check the emacswiki link to know more about what you can do with this feature

More on this