Is it possible to stop Emacs on macOS from quitting? This may sound like a weird request, but numerous times I may accidentally quit Emacs and the whole GUI app exits -- which means I then have to restore the session as it was before (which is a pain).

Or maybe there's another way to solve this problem: is it possible to have Emacs' session restore to exactly where it was when the app quit?

  • Maybe edit your question to make clear from the outset that you want to avoid/prevent accidentally quitting, not prevent being able to quit.
    – Drew
    Jul 27 '17 at 3:15
  1. See kill-emacs-query-functions, which lets you query yourself to confirm quitting, to avoid accidental quitting.

  2. See desktop.el, which lets you save most of the state of your session when you quit, and restores it at the next session. See the Emacs manual, node Saving Emacs Sessions. See also savehist.el and bookmarks.

  • You may also try to modify the "app" launcher for emacs to use emacsclient and daemon.
    – Joafigue
    Jul 27 '17 at 23:58
  • You may also try to modify the "app" launcher for emacs to use emacsclient and daemon. It should say something along the lines emacsclient -c || ( emacs --daemon && emacsclient -c)
    – Joafigue
    Jul 28 '17 at 0:05

You may consider setting (setq confirm-kill-emacs 'yes-or-no-p) as described in


One convenient function to use as the value of confirm-kill-emacs is the function yes-or-no-p. The default value of confirm-kill-emacs is nil.

And if you only want this to apply in the GUI version of MacOS, and not in Terminal, then you can use: (when (display-graphic-p) (setq confirm-kill-emacs 'yes-or-no-p))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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