@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.