Function: kill-emacs
kill-emacs is an interactive function defined in emacs.c.
Signature
(kill-emacs &optional ARG RESTART)
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.
If RESTART is non-nil, instead of just exiting at the end, start a new Emacs process, using the same command line arguments as the currently running Emacs process.
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;
#ifndef WINDOWSNT
/* Do some checking before shutting down Emacs, because errors
can't be meaningfully reported afterwards. */
if (!NILP (restart))
{
/* This is very unlikely, but it's possible to execute a binary
(on some systems) with no argv. */
if (initial_argc < 1)
error ("No command line arguments known; unable to re-execute Emacs");
/* Check that the binary hasn't gone away. */
if (!initial_emacs_executable)
error ("Unknown Emacs executable");
if (!file_access_p (initial_emacs_executable, F_OK))
error ("Emacs executable \"%s\" can't be found", initial_argv[0]);
}
#endif
#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 (!NILP (restart))
{
turn_on_atimers (false);
#ifdef WINDOWSNT
if (w32_reexec_emacs (initial_cmdline, initial_wd) < 0)
#else
initial_argv[0] = initial_emacs_executable;
if (execvp (*initial_argv, initial_argv) < 1)
#endif
emacs_perror ("Unable to re-execute Emacs");
}
if (FIXNUMP (arg))
exit_code = (XFIXNUM (arg) < 0
? XFIXNUM (arg) | INT_MIN
: XFIXNUM (arg) & INT_MAX);
else
exit_code = EXIT_SUCCESS;
exit (exit_code);
}