From: Jim Porter <jporterbugs@gmail.com>
To: Gregory Heytings <gregory@heytings.org>, 51377@debbugs.gnu.org
Subject: bug#51377: Automatically exit server when it has no remaining clients
Date: Sun, 24 Oct 2021 09:03:13 -0700 [thread overview]
Message-ID: <63203d9f-dae7-a39f-c70f-ebf37632e642@gmail.com> (raw)
In-Reply-To: <90ba36dccc00d6f0d62d@heytings.org>
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? "))))
--------------------------------------------------
next prev parent reply other threads:[~2021-10-24 16:03 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-24 15:15 bug#51377: Automatically exit server when it has no remaining clients Gregory Heytings
2021-10-24 16:03 ` Jim Porter [this message]
2021-10-24 16:14 ` Jim Porter
2021-10-24 16:32 ` Gregory Heytings
2021-10-24 18:08 ` Jim Porter
2021-10-24 18:43 ` Gregory Heytings
2021-10-24 19:39 ` Jim Porter
2021-10-24 20:42 ` Gregory Heytings
2021-10-24 21:19 ` Jim Porter
2021-10-24 21:37 ` Gregory Heytings
2021-10-25 18:21 ` Jim Porter
2021-10-26 10:37 ` Gregory Heytings
2021-10-26 11:59 ` Gregory Heytings
2021-10-26 15:07 ` Gregory Heytings
2021-11-11 5:43 ` Lars Ingebrigtsen
2021-10-24 21:40 ` Jim Porter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=63203d9f-dae7-a39f-c70f-ebf37632e642@gmail.com \
--to=jporterbugs@gmail.com \
--cc=51377@debbugs.gnu.org \
--cc=gregory@heytings.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.