@Harald answered your question.
But I would not say "unfortunately". This is by design. Buffer *scratch*
is designed for what its name suggests and its initial contents describe: It is a scratchpad, for throwaway content.
If you use it for some other purpose then you are misusing it.
- But of course you might want a scratchpad that is automatically backed up (autosaved) periodically. If so, then use a buffer that is backed by a file.
For example, edit your Lisp scratch in a new file buffer iii.el
or whatever. Then (a) you can more easily save the content, if you want, and (b) Emacs will prompt you about any unsaved changes when you use C-x C-c
.
In other words, Emacs does not prompt you about unsaved changes for *scratch*
because it is not a buffer that is designed (intended, by default) to be saved. For that, use a file buffer, even for a not-yet-existing file.
With respect to autosaving, be aware that it happens only for an existing file, that is, a file on disk. So if you want autosaving to kick in then you must save the file buffer at least once.
- If you want
C-x C-c
to ask for confirmation, that is easy to get. You could even have it let you know about modification of buffers, such as *scratch*
.
This is what I use:
(add-hook 'kill-emacs-query-functions
(lambda () (y-or-n-p "Do you really want to exit Emacs? "))
'append)
That always prompts me, when I use C-x C-c
, regardless of the state of any buffers. You might prefer something more specific, which checks certain buffers etc.
You can also use command customize-customized
to check whether you have unsaved customizations.
M-x remember-notes
. I learned about it from a similar question here a while back. Maybe a search will bring it up. Oh, wait … here it is. That question is not an exact duplicate of this one, but it is relevant.*scratch*
for stuff that you don't want to throw away. (That's what "scratch" means.)*scratch*
buffer comes with the following notice:This buffer is for notes you don't want to save
. But if you do want to save what is in your scratch buffer, justC-x C-s
to save it somewhere.*scratch*
buffer, but one that was created by a call toswitch-to-buffer "name"
somewhere, which does create a new one if "name" was not found. After modifying that, emacs would still fail to consider it "valuable" enough for its usual "modified buffers exist" warning (perhaps because it has no file associated with it), which is rather unfortunate.