16

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

1

3 Answers 3

23

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

3
  • 2
    Thanks! It's a pity it is not mentioned in save-buffers-kill-terminal documentation... Commented Jul 3, 2015 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
    Commented Jul 3, 2015 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
    Commented Jul 4, 2015 at 6: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)
2
  • 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
    Commented Jul 3, 2015 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
    Commented Jul 4, 2015 at 6: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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.