emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [RFC] Option to kill `emacs --daemon' when closing the last client f


From: Jim Porter
Subject: Re: [RFC] Option to kill `emacs --daemon' when closing the last client frame
Date: Wed, 20 Oct 2021 20:43:31 -0700

On 10/20/2021 5:13 AM, Eli Zaretskii wrote:
Unlike "other programs", Emacs doesn't aim to support such use
patterns with the ALTERNATE_EDITOR thing.  It is supposed to allow the
user to invoke emacsclient without knowing whether a server already
runs, by starting the server the first time.  That is why we don't
kill the server when the last client exits: it is against the use case
we want to support.

My expectation (which is really just personal preference informed by other programs I'm used to) is that since `emacs --daemon' is created on as-needed basis in this configuration, it would also be killed when it's no longer needed. If I wanted `emacs --daemon' to live forever, I'd probably just set it up to start when my system boots.

However, I don't know if I can make a particularly compelling argument as to why this *should* be how things work, aside from just saying that I find the symmetry of this behavior simpler/easier to remember. It's in the same vein as a refcounted object in a program (e.g. `std::shared_ptr' for C++ programmers): I can make new `emacsclient's, which increment the refcount, and once the refcount drops to 0, the underlying entity (i.e. the daemon) is automatically cleaned up.

In the end though, it's just what I like / what makes the most sense to me. If other people see things similarly, I'd be happy to write a patch, but if I'm the only one who wants this, then I can always customize my .emacs to my liking instead.

We could add an optional command-line argument to do what you want,
but I wonder why would that be useful, when we already have
kill-emacs.

That's one option, although it might take a bit of work to support that (assuming I understand what you mean). As far as I understand how ALTERNATE_EDITOR works, there's not an easy way to automatically start the Emacs daemon *and* provide it with some extra options. That is, ALTERNATE_EDITOR="emacs --daemon --foo" would start the daemon, but wouldn't create a client to connect to it.

Another method might be to add an option like `daemon-kill-when-no-clients' that defaults to nil. Then after an `emacsclient' is killed, we can consult that variable, and if it's true, kill the daemon if there are no remaining clients.

- Jim



reply via email to

[Prev in Thread] Current Thread [Next in Thread]