I developed a bad habit of quitting Emacs from my earlier days of using Emacs mostly in a terminal session (where even there quitting it is not the best idea). Using GUI versions of Emacs, I sometimes find myself hitting C-x C-c
and wishing I didn’t because I really intended to kill the current buffer, not completely close Emacs. So what I have done to deal with this is, when running a GUI version (which can be detected by checking the window-system
variable), I always prompt to ask if I really want to quit. Here is the code I use:
I do this only for the GUI version, but you could remove the check for window-system
if you want it to work in the terminal version as well. I use when
instead of if
in this case, because I do other things if I am running the GUI version, like (server-start)
, which I have excluded from this code sample.
© 2017 Nilesh D Kapadia