Function: server-save-buffers-kill-terminal
server-save-buffers-kill-terminal is an autoloaded and byte-compiled
function defined in server.el.gz.
Signature
(server-save-buffers-kill-terminal ARG)
Documentation
Offer to save each buffer, then kill the current client.
With ARG non-nil, silently save all file-visiting buffers, then kill.
If emacsclient was started with a list of filenames to edit, then only these files will be asked to be saved.
When running Emacs as a daemon and with
server-stop-automatically(var)/server-stop-automatically(fun) (which see) set to kill-terminal or
delete-frame, this function may call save-buffers-kill-emacs
if there are no other active clients.
Source Code
;; Defined in /usr/src/emacs/lisp/server.el.gz
;;;###autoload
(defun server-save-buffers-kill-terminal (arg)
;; Called from save-buffers-kill-terminal in files.el.
"Offer to save each buffer, then kill the current client.
With ARG non-nil, silently save all file-visiting buffers, then kill.
If emacsclient was started with a list of filenames to edit, then
only these files will be asked to be saved.
When running Emacs as a daemon and with
`server-stop-automatically' (which see) set to `kill-terminal' or
`delete-frame', this function may call `save-buffers-kill-emacs'
if there are no other active clients."
(let ((stop-automatically
(and (daemonp)
(memq server-stop-automatically '(kill-terminal delete-frame))))
(proc (frame-parameter nil 'client)))
(cond ((eq proc 'nowait)
;; Nowait frames have no client buffer list.
(if (length> (frame-list) (if stop-automatically 2 1))
;; If there are any other frames, only delete this one.
;; When `server-stop-automatically' is set, don't count
;; the daemon frame.
(progn (save-some-buffers arg)
(delete-frame))
;; If we're the last frame standing, kill Emacs.
(save-buffers-kill-emacs arg)))
((processp proc)
(if (or (not stop-automatically)
(length> server-clients 1)
(seq-some
(lambda (frame)
(when-let ((p (frame-parameter frame 'client)))
(not (eq proc p))))
(frame-list)))
;; If `server-stop-automatically' is not enabled, there
;; are any other clients, or there are frames not owned
;; by the current client (e.g. `nowait' frames), then
;; we just want to delete this client.
(let ((buffers (process-get proc 'buffers)))
(save-some-buffers
arg (if buffers
;; Only files from emacsclient file list.
(lambda () (memq (current-buffer) buffers))
;; No emacsclient file list: don't override
;; `save-some-buffers-default-predicate' (unless
;; ARG is non-nil), since we're not killing
;; Emacs (unlike `save-buffers-kill-emacs').
(and arg t)))
(server-delete-client proc))
;; Otherwise, we want to kill Emacs.
(save-buffers-kill-emacs arg)))
(t (error "Invalid client frame")))))