bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#51377: Automatically exit server when it has no remaining clients


From: Jim Porter
Subject: bug#51377: Automatically exit server when it has no remaining clients
Date: Sun, 24 Oct 2021 14:19:42 -0700

On 10/24/2021 1:42 PM, Gregory Heytings wrote:


Yeah, that looks like it should avoid any data loss. However, it's not the behavior I'd personally expect. As I understand it, this will just keep the Emacs daemon alive if there are any unsaved files.


Indeed.  And if there are any running processes.  This is I think the least surprising behavior for users who use the Emacs daemon.

I'd find it quite surprising, since an errant edit to any open file would prevent the server from exiting after the last client stops. While leaving the server running isn't the worst thing ever (indeed, that's how it works now), I'd want the logic for when the server exits to be as simple as possible, i.e. "when there are no more clients, exit" (provided the user has confirmed as necessary). Having the server stick around because I forgot to save one file would surprise me, mainly because it would typically happen after, well, I forgot something.

I'd find it easier to use if Emacs warned the user about unsaved files before killing the last client. Then, Emacs can safely kill the daemon once I've confirmed that that's what I want.


I'm not sure I understand why this would be better.

Coming from a non-daemon configuration, my expectation is that `save-buffers-kill-terminal' typically kills Emacs entirely. The behavior I'm looking for is: I can have multiple clients (or "terminals", as the function calls them) connected to the Emacs daemon, but once I'm down to just one client, `save-buffers-kill-terminal' works like it does in a non-daemon/server configuration. Then, in terms of my use pattern, the extra clients work like an addition on top of the behavior I'm used to (i.e. running `emacs' directly).

If want you want is to save unsaved buffers and stop the daemon when you close the last frame, you can simply use:

(defun save-buffers-kill-terminal (&optional arg)
   (interactive "P")
   (if (and (frame-parameter nil 'client)
        (cddr (frame-list)))
       (server-save-buffers-kill-terminal arg)
     (save-buffers-kill-emacs arg)))

That's pretty much what I started with, actually. I've added more to that as I find corner cases, and as I try to make my code work well under different configurations so that it could merge into Emacs if there's interest.





reply via email to

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