GNU bug report logs -
#51377
Automatically exit server when it has no remaining clients
Previous Next
Reported by: Gregory Heytings <gregory <at> heytings.org>
Date: Sun, 24 Oct 2021 15:16:01 UTC
Severity: wishlist
Tags: patch
Fixed in version 29.1
Done: Lars Ingebrigtsen <larsi <at> gnus.org>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
On 10/24/2021 8:15 AM, Gregory Heytings wrote:
>
> As discussed in
> https://lists.gnu.org/archive/html/emacs-devel/2021-10/msg01465.html ,
> an option to stop the Emacs server when it has no clients anymore (which
> is similar to what some other apps do, for example browsers) would be
> useful.
>
> Patch attached.
I'm not sure I understand the patch; `save-buffers-kill-emacs' prompts
the user to save buffers before killing Emacs, but how would that work
in a daemon when there are no frames remaining?
I use a slightly-modified form of the following in my configuration,
which I'm working on hooking up to a flag to remember if the daemon was
started lazily:
--------------------------------------------------
(defun save-buffers-kill-terminal (&optional arg)
"Offer to save each buffer, then kill the current connection.
If the current frame has no client or is the last client of a daemon,
kill Emacs itself using `save-buffers-kill-emacs'.
With prefix ARG, 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."
(interactive "P")
;; Only kill the terminal if the current frame is a client. However, if
;; Emacs was started as a daemon and this is the last client, kill Emacs
;; entirely.
(if-let ((this-client (frame-parameter nil 'client))
((not (and (daemonp)
(equal server-clients (list this-client))))))
(server-save-buffers-kill-terminal arg)
(save-buffers-kill-emacs arg)))
(defun server-kill-emacs-query-function ()
"Ask before exiting Emacs if it has live clients.
If Emacs was started as a daemon and the only live client is the
current frame's client, don't bother asking."
(let ((ignored-client (and (daemonp) (frame-parameter nil 'client))))
(or (not (seq-some (lambda (client)
(unless (eq ignored-client client)
(seq-some #'buffer-live-p
(process-get client 'buffers))))
server-clients))
(yes-or-no-p "This Emacs session has clients; exit anyway? "))))
--------------------------------------------------
This bug report was last modified 3 years and 271 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.