Function: server-stop-automatically
server-stop-automatically is an autoloaded and byte-compiled function
defined in server.el.gz.
Signature
(server-stop-automatically ARG)
Documentation
Automatically stop server as specified by ARG.
If ARG is the symbol empty, stop the server when it has no
remaining clients, no remaining unsaved file-visiting buffers,
and no running processes with a query-on-exit flag.
If ARG is the symbol delete-frame, ask the user when the last
frame is deleted whether each unsaved file-visiting buffer must
be saved and each running process with a query-on-exit flag
can be stopped, and if so, stop the server itself.
If ARG is the symbol kill-terminal, ask the user when the
terminal is killed with C-x C-c (save-buffers-kill-terminal) whether each unsaved file-visiting
buffer must be saved and each running process with a query-on-exit
flag can be stopped, and if so, stop the server itself.
Any other value of ARG will cause this function to signal an error.
This function is meant to be called from the user init file.
Probably introduced at or before Emacs version 29.1.
Source Code
;; Defined in /usr/src/emacs/lisp/server.el.gz
;;;###autoload
(defun server-stop-automatically (arg)
"Automatically stop server as specified by ARG.
If ARG is the symbol `empty', stop the server when it has no
remaining clients, no remaining unsaved file-visiting buffers,
and no running processes with a `query-on-exit' flag.
If ARG is the symbol `delete-frame', ask the user when the last
frame is deleted whether each unsaved file-visiting buffer must
be saved and each running process with a `query-on-exit' flag
can be stopped, and if so, stop the server itself.
If ARG is the symbol `kill-terminal', ask the user when the
terminal is killed with \\[save-buffers-kill-terminal] \
whether each unsaved file-visiting
buffer must be saved and each running process with a `query-on-exit'
flag can be stopped, and if so, stop the server itself.
Any other value of ARG will cause this function to signal an error.
This function is meant to be called from the user init file."
(when (daemonp)
(setq server-stop-automatically arg)
(cond
((eq arg 'empty)
(setq server-stop-automatically nil)
(run-with-timer 10 2
#'server-stop-automatically--maybe-kill-emacs))
((eq arg 'delete-frame)
(add-hook 'delete-frame-functions
#'server-stop-automatically--handle-delete-frame))
((eq arg 'kill-terminal))
(t
(error "Unexpected argument")))))