5

When typing ls in my home directory, I amm greeted by a lot of this:

#%2Ascratch%2A#1399_po# #%2Ascratch%2A#14484YsZ# [...]

I also have the following in my init.el

(defvar autosave-location (concat user-emacs-directory "data/autosave"))

(setq auto-save-file-name-transforms
  `((".*" ,autosave-location t)))

Why, then are the scratch autosaves not being sent to ~/.emacs.d/data/autosave and instead are being blasted around my file system? Ideally, I just want it to save to that folder, however if that can't be done, disabling autosave for *scratch* buffers entirely would suffice.

I believe this started with Emacs 24.4.

7
  • In your setup, is the *scratch* a file-visiting-buffer or a NON-file-visiting buffer? The default is the latter and thus is not subject to autosave. I like to kill the *scratch* when Emacs opens and prevent it from reappearing, and instead I use a custom file-visiting-buffer called .scratch. Whenever *scratch* would normally appear, I preempt it with a custom find-file /path/to/.scratch
    – lawlist
    Commented Jan 26, 2015 at 19:21
  • It is not a file-visiting buffer (and I would rather it stay that way), which is why I'm confused.
    – PythonNut
    Commented Jan 26, 2015 at 19:24
  • Emacs does not, by default, autosave NON-file-visiting buffers. For example, a *Help* buffer does not get autosaved, nor does a *Backtrace* buffer.
    – lawlist
    Commented Jan 26, 2015 at 19:25
  • Apparently, it will if you enable auto-save-mode in the buffer.
    – PythonNut
    Commented Jan 26, 2015 at 19:27
  • See also stackoverflow.com/questions/8849661/…
    – phils
    Commented Jan 26, 2015 at 21:17

1 Answer 1

5

You'll notice that you're using a variable called auto-save-file-name-transforms. Since *scratch* has no filename, it falls back to autosaving in default-directory.

For the *scratch* buffer, or any other buffers like this with no filename, you can use:

(setq-local default-directory "~/.emacs.d/data/autosave")

Edit: I see that you don't really care about autosaving scratch buffers. Can I ask how you enable auto-save-mode in your init? You should use:

 (setq-default auto-save-default t)

And not something like a hook with (auto-save-mode 1), because the variable only enables it for file-visiting buffers, while a hook could potentially enable it for buffers where you don't want it.

1
  • Yes and yes. I suppose I'll just disable it entirely for *scratch* then.
    – PythonNut
    Commented Jan 26, 2015 at 19:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.