Can I configure Emacs to ask for confirmation before exiting on C-x C-c? (Sometimes, my fingers press this by mistake.)


Set the variable confirm-kill-emacs to something like yes-or-no-p.

  • 2
    Thanks! It's a pity it is not mentioned in save-buffers-kill-terminal documentation... – imz -- Ivan Zakharyaschev Jul 3 '15 at 10:02
  • 1
    It'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 3 '15 at 16:39
  • 1
    @imz--IvanZakharyaschev: Yes; likewise kill-emacs-query-functions. See Emacs bug #10794. (And bug #11181, though not directly related, is also relevant here.) – Drew Jul 4 '15 at 6:29

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


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? "))
  • 3
    It 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 3 '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 4 '15 at 6:22

This site is temporarily in read only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .