Function: kill-emacs
kill-emacs is an interactive function defined in emacs.c.
Signature
(kill-emacs &optional ARG)
Documentation
Exit the Emacs job and kill it.
If ARG is an integer, return ARG as the exit program code. If ARG is a string, stuff it as keyboard input. Any other value of ARG, or ARG omitted, means return an exit code that indicates successful program termination.
This function is called upon receipt of the signals SIGTERM or SIGHUP, and upon SIGINT in batch mode.
The value of kill-emacs-hook, if not void,
is a list of functions (of no args),
all of which are called before Emacs is actually killed.
Probably introduced at or before Emacs version 17.
Key Bindings
Source Code
// Defined in /usr/src/emacs/src/emacs.c
{
int exit_code;
#ifdef HAVE_LIBSYSTEMD
/* Notify systemd we are shutting down, but only if we have notified
it about startup. */
if (daemon_type == -1)
sd_notify(0, "STOPPING=1");
#endif /* HAVE_LIBSYSTEMD */
/* Fsignal calls emacs_abort () if it sees that waiting_for_input is
set. */
waiting_for_input = 0;
if (!NILP (find_symbol_value (Qkill_emacs_hook)))
{
if (noninteractive)
safe_run_hooks (Qkill_emacs_hook);
else
call1 (Qrun_hook_query_error_with_timeout, Qkill_emacs_hook);
}
#ifdef HAVE_X_WINDOWS
/* Transfer any clipboards we own to the clipboard manager. */
x_clipboard_manager_save_all ();
#endif
shut_down_emacs (0, (STRINGP (arg) && !feof (stdin)) ? arg : Qnil);
#ifdef HAVE_NS
ns_release_autorelease_pool (ns_pool);
#endif
/* If we have an auto-save list file,
kill it because we are exiting Emacs deliberately (not crashing).
Do it after shut_down_emacs, which does an auto-save. */
if (STRINGP (Vauto_save_list_file_name))
{
Lisp_Object listfile;
listfile = Fexpand_file_name (Vauto_save_list_file_name, Qnil);
unlink (SSDATA (listfile));
}
#ifdef HAVE_NATIVE_COMP
eln_load_path_final_clean_up ();
#endif
if (FIXNUMP (arg))
exit_code = (XFIXNUM (arg) < 0
? XFIXNUM (arg) | INT_MIN
: XFIXNUM (arg) & INT_MAX);
else
exit_code = EXIT_SUCCESS;
exit (exit_code);
}