From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jim Porter Newsgroups: gmane.emacs.bugs Subject: bug#51377: Automatically exit server when it has no remaining clients Date: Sun, 24 Oct 2021 14:19:42 -0700 Message-ID: <2fb21ea4-0b95-a76b-8c5f-f8a6c7c1fc9b@gmail.com> References: <90ba36dccc00d6f0d62d@heytings.org> <63203d9f-dae7-a39f-c70f-ebf37632e642@gmail.com> <90ba36dcccc2abc8dec1@heytings.org> <7f3dde25-f81b-d7db-efc5-f8d471fd06bc@gmail.com> <90ba36dcccdc40168c93@heytings.org> <90ba36dcccde742a3c60@heytings.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32759"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 51377@debbugs.gnu.org To: Gregory Heytings Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Oct 24 23:20:18 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mekuf-0008M3-HV for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 24 Oct 2021 23:20:17 +0200 Original-Received: from localhost ([::1]:37164 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mekue-0006Nb-D8 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 24 Oct 2021 17:20:16 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:57926) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mekuQ-0006LQ-Ld for bug-gnu-emacs@gnu.org; Sun, 24 Oct 2021 17:20:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:57796) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mekuQ-0007OX-AC for bug-gnu-emacs@gnu.org; Sun, 24 Oct 2021 17:20:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mekuP-0005Dn-Va for bug-gnu-emacs@gnu.org; Sun, 24 Oct 2021 17:20:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Jim Porter Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 24 Oct 2021 21:20:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51377 X-GNU-PR-Package: emacs Original-Received: via spool by 51377-submit@debbugs.gnu.org id=B51377.163511039120051 (code B ref 51377); Sun, 24 Oct 2021 21:20:01 +0000 Original-Received: (at 51377) by debbugs.gnu.org; 24 Oct 2021 21:19:51 +0000 Original-Received: from localhost ([127.0.0.1]:41109 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mekuF-0005DK-0S for submit@debbugs.gnu.org; Sun, 24 Oct 2021 17:19:51 -0400 Original-Received: from mail-pj1-f48.google.com ([209.85.216.48]:55938) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mekuD-0005D8-Hj for 51377@debbugs.gnu.org; Sun, 24 Oct 2021 17:19:49 -0400 Original-Received: by mail-pj1-f48.google.com with SMTP id om14so6748253pjb.5 for <51377@debbugs.gnu.org>; Sun, 24 Oct 2021 14:19:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=crt8InJVflFFLMd+XoNVkvMeQYYtI5W1pjAExA4dcuc=; b=jtYcvMxMhE2fx260XD/ly3tTm4XnrsqoDdVEtIvqIuYWnEJ1Wt0YovVV7d7wWLA96c i2FZcmVqq6I4QmzfgJE56gIeNkuHdfgFM7BA/dkDCT+UAgf4uRY/8ocOlN1CZQi/LcEk y64r44MSlBM9bG0rjOFIq3XUO5WnEPtyUulTPIPaA2IwGIifM895e2yVcjcGSulNWXP9 tk2CbPRaFVCLLXTWck3r/yRJ9kMEbTk0BliJkI3ZHboSVM60FzLAQxZfxs0QZJpyBhel pGfYm1WpwmCzb4DsgrJLK4X0hs6Hpuy9ELHkZbZGku3xPpIQkifaTJow14OJDFUu+FUm ikIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=crt8InJVflFFLMd+XoNVkvMeQYYtI5W1pjAExA4dcuc=; b=Up5HUxssp4gUcL7V9/oYIQgRHC/gnJfj8HRQowjs7Lj8o5k2UREg8nkP53IIifh1un iuDqqC76mqd2I/DZB+GSEnylZyxil62GLSMbzIeTB0Ee9mVsPtDMYLMyqGzrOhHnWMnn 5x1qNSLWw6MJi55BPa/+v3Iu8SlTVHvz4nLRp/HyQOpqdq3D89XehY8vJCluzsphMir6 dXBNElEf0phoWbT0cvCZZZ2/+I14KfA8GmRjG1+rLdQ2c13bIZuigECDRVPRABi28jJT LIVmsFDhehXvUkvkwmCPOwnRtokMwNbGbqv0ZNc1fmpkadSmxCtrNpllN/CJ7A6GtShm H8oQ== X-Gm-Message-State: AOAM530pCwLvBBDlKcRPPyaZ+MDfiaiOx7fvI00hIZqLNvudDXChCU3E MMWvUwo6/EMpwUc23DWR8tbruNHAfvw= X-Google-Smtp-Source: ABdhPJweHpS1FkVDl9EGVlWLANidHL3XnYlk4f73OQvP1j0gc3Nt/y4auYkV5fNoktYXeBXIhXb4Gg== X-Received: by 2002:a17:90b:1e01:: with SMTP id pg1mr15745906pjb.81.1635110383269; Sun, 24 Oct 2021 14:19:43 -0700 (PDT) Original-Received: from [192.168.1.2] (cpe-76-168-148-233.socal.res.rr.com. [76.168.148.233]) by smtp.googlemail.com with ESMTPSA id h14sm12650714pfv.182.2021.10.24.14.19.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 24 Oct 2021 14:19:42 -0700 (PDT) In-Reply-To: <90ba36dcccde742a3c60@heytings.org> Content-Language: en-US X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:218208 Archived-At: 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.