Emacs: Real Automatic Save File
Real Auto Save File
This is the best solution i use since about 2017. Most simple code, reliable, and practical.
Save all files when you switch out of emacs.
Put this in your Emacs Init File:
(defun xah-save-all-unsaved () "Save all unsaved files. no ask. Version 2019-11-05" (interactive) (save-some-buffers t )) (if (version< emacs-version "27") (add-hook 'focus-out-hook 'xah-save-all-unsaved) (setq after-focus-change-function 'xah-save-all-unsaved))
alternative solution and problem
You can set emacs to auto save files directly, instead of creating those #filename#.
Put this in your Emacs Init File:
(setq auto-save-default t) (setq auto-save-visited-file-name t)
Problems
However, this does not work well. Emacs still generates those #files#, this time, named like this:
.#xxtemp.201601134145.44920.el -> xah@xah-p6813w.21261:1452244010
If you have scripts going thru your machine, you get this error:
error: cannot open /home/john/web/.#vocabulary.html No such file or directory
There are probably ways to fix this, with hooks or timer, but i haven't looked into.
thanks to Fuqiao Xue (xfq) [[2013-08-20 https://github.com/xfq/ ]] and finalpatch [[2013-08-20 http://www.weibo.com/u/1885517634 ]]
thanks to http://irreal.org/blog/?p=4867, Anna Pawlicka (@AnnaPawlicka)