Search code examples
emacselispkill

When is kill-emacs-hook called?


If I have some unsaved buffers, when does kill-emacs-hook call?

Scenario A

  1. User invoke kill-emacs.
  2. Prompt for saving modified buffers.
  3. Cancel kill-emacs operation (C-g).
  4. User continues to use emacs.

Scenario B

  1. User invoke kill-emacs.
  2. Prompt for saving modified buffers.
  3. All modified buffers saved
  4. Emacs killed.

Solution

  • Running kill-emacs-hook is the first thing which kill-emacs does.

    Both of your scenarios are invalid. If the user directly invokes kill-emacs the user is not prompted to save buffers (that's only done if save-buffers-kill-emacs is called).

    For the latter, if the user aborts the query to save buffers, or if any of the members of kill-emacs-query-functions return nil, then kill-emacs is never called.