Skip to content

Instantly share code, notes, and snippets.

@willwillis
Created July 21, 2010 14:32
Show Gist options
  • Save willwillis/484560 to your computer and use it in GitHub Desktop.
Save willwillis/484560 to your computer and use it in GitHub Desktop.
(defun ask-before-closing ()
"Ask whether or not to close, and then close if y was pressed"
(interactive)
(if (y-or-n-p (format "Are you sure you want to exit Emacs? "))
(if (< emacs-major-version 22)
(save-buffers-kill-terminal)
(save-buffers-kill-emacs))
(message "Canceled exit")))
(when window-system
(global-set-key (kbd "C-x C-c") 'ask-before-closing))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment