auto-save-mode works with non-file buffers. It just doesn't turn on by default - this usually happens in (after-find-file) .
So: Mx auto-save-mode RET
By default, the autosave file will be written to the default-directory buffer (or /var/tmp or ~/ , depending on write permissions, see Ch v buffer-auto-save-file-name RET ) which may be a little inconvenient to find out after a crash, so installing on something standard is probably a good idea.
The following ensures that these autosave files are written to your home directory (or Mx customize-variable RET my-non-file-buffer-auto-save-dir RET ) if auto-save-mode is invoked interactively. This, I hope, will avoid the conflict associated with any other use of auto-save-mode with non-file buffers (for example, Mail mode is mentioned in the code).
(defcustom my-non-file-buffer-auto-save-dir (expand-file-name "~/") "Directory in which to store auto-save files for non-file buffers, when `auto-save-mode' is invoked manually.") (defadvice auto-save-mode (around use-my-non-file-buffer-auto-save-dir) "Use a standard location for auto-save files for non-file buffers" (if (and (not buffer-file-name) (called-interactively-p 'any)) (let ((default-directory my-non-file-buffer-auto-save-dir)) ad-do-it) ad-do-it)) (ad-activate 'auto-save-mode)
phils source share