Can I configure Emacs to ask for confirmation before exiting on C-x C-c
? (Sometimes, my fingers press this by mistake.)
Asked
Active
Viewed 6,121 times
15

imz -- Ivan Zakharyaschev
- 591
- 6
- 20
-
See also [Prevent Emacs from exiting once the exit procedure has initiated?](https://stackoverflow.com/q/21192111/94687) for some other related suggestions. – imz -- Ivan Zakharyaschev Dec 07 '17 at 12:45
3 Answers
23
Set the variable confirm-kill-emacs
to something like yes-or-no-p
.

legoscia
- 6,012
- 29
- 54
-
2Thanks! It's a pity it is not mentioned in `save-buffers-kill-terminal` documentation... – imz -- Ivan Zakharyaschev Jul 03 '15 at 10:02
-
1It's only mentioned for `save-buffers-kill-emacs`, which used to be the binding for `C-x C-c` until 23.1. That should be updated, it seems. – legoscia Jul 03 '15 at 16:39
-
1@imz--IvanZakharyaschev: Yes; likewise `kill-emacs-query-functions`. See Emacs [bug #10794](http://debbugs.gnu.org/cgi/bugreport.cgi?bug=10794). (And [bug #11181](http://debbugs.gnu.org/cgi/bugreport.cgi?bug=11181#22), though not directly related, is also relevant here.) – Drew Jul 04 '15 at 06:29
9
I use this, which workds in all Emacs versions:
(add-hook 'kill-emacs-query-functions
(lambda () (y-or-n-p "Do you really want to exit Emacs? "))
'append)

Drew
- 75,699
- 9
- 109
- 225
-
3It would be nice to explain how that is different from setting `confirm-kill-emacs`. IIUC, the difference is that `c-k-e` is ignored if there are modified buffers (which already asks confirmation) or active processes (also asks for confirmation). – YoungFrog Jul 03 '15 at 16:24
-
@YoungFrog: What you say is true, but only for Emacs 25, not earlier. And `confirm-kill-emacs` does not exist prior to Emacs 21. – Drew Jul 04 '15 at 06:22
8
A common alternative is to unbind the key using
(global-unset-key (kbd "C-x C-c"))
You can always quit via M-x save-buffers-kill-terminal

mike3996
- 463
- 4
- 15