Whenever I accidentally fat-finger C-x C-c
(or Cmd-Q
on a Mac), GNU Emacs exits right away unless shells are open or buffers, backed by files, are modified -- in which case it prompts as to how to proceed.
Unfortunately, if I've got no shell sessions open and have saved my files, but am in the midst of composing a brilliant, yet perhaps not entirely pithy, git log message (in the *vc-log*
buffer), that won't prevent me exiting in one fell, promptless, swoop -- thus losing that draft, which apparently doesn't get autosaved anywhere that I've been able to find.
What's the best way to address this issue? I would think it's best for *vc-log*
, and any other such buffer that provides for "on-the-fly" composition not backed by a traditional file (such as a commit/checkin message or email), to nevertheless be backed by a "pending draft" file. That would not only help avoid accidentally exiting Emacs, but allow restoring of such a draft if Emacs (or the computer itself) crashed.
If that's a reasonable approach, how should it be implemented?
Other approaches I've considered (which seem less than ideal):
- Somehow convince the pertinent Emacs exit hook to always prompt before exiting, even if there are no shell sessions nor modified, file-backed, buffers
- Use a fresh Emacs session, auto-invoked by (e.g.)
git commit
(with no-m
option and assumingGIT_EDITOR=emacs
in the environment), so the file-backedCOMMIT_EDITMSG
buffer is used to compose the commit message -- which prevents that new Emacs session from quitting without prompting and avoids accidentally quitting the original Emacs session (typically "fatter" with many buffers and other context) - Use
git commit -m ...
for single-line commit messages - Always keep a shell session open (within Emacs), so quitting always prompts first
Any recommendations?
(add-hook 'kill-emacs-query-functions (lambda () (y-or-n-p "Do you really want to exit Emacs? ")) 'append)
– Drew