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 09:03:13 -0700 Message-ID: <63203d9f-dae7-a39f-c70f-ebf37632e642@gmail.com> References: <90ba36dccc00d6f0d62d@heytings.org> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="11655"; mail-complaints-to="usenet@ciao.gmane.io" To: Gregory Heytings , 51377@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Oct 24 18:04:59 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 1mefzX-0002ls-4d for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 24 Oct 2021 18:04:59 +0200 Original-Received: from localhost ([::1]:44102 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mefzV-0002ji-8g for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 24 Oct 2021 12:04:57 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39490) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mefyc-0001z9-K8 for bug-gnu-emacs@gnu.org; Sun, 24 Oct 2021 12:04:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:57290) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mefyc-0002pU-7I for bug-gnu-emacs@gnu.org; Sun, 24 Oct 2021 12:04:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mefyc-00079K-0q for bug-gnu-emacs@gnu.org; Sun, 24 Oct 2021 12:04:02 -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 16:04: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.163509140227431 (code B ref 51377); Sun, 24 Oct 2021 16:04:01 +0000 Original-Received: (at 51377) by debbugs.gnu.org; 24 Oct 2021 16:03:22 +0000 Original-Received: from localhost ([127.0.0.1]:40603 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mefxy-00078N-9J for submit@debbugs.gnu.org; Sun, 24 Oct 2021 12:03:22 -0400 Original-Received: from mail-pf1-f177.google.com ([209.85.210.177]:46897) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mefxw-000789-Ao for 51377@debbugs.gnu.org; Sun, 24 Oct 2021 12:03:20 -0400 Original-Received: by mail-pf1-f177.google.com with SMTP id x66so8354776pfx.13 for <51377@debbugs.gnu.org>; Sun, 24 Oct 2021 09:03:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:references:from:message-id:date:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=uCuoIftyzzvL3bV/AwWt2TZaI5K+zTeLPFaxoJAdJsg=; b=qEeipSMQWOyuMCOIXEL9bIrgWQmqflzuATq/AmIMunUqezeon4Pjz7FasbcBZmiSpL aJm7r0iDP+4i1qXPZWGTDUy9drjgdAz9d4JegRCxmAwHhaF2sOq0Ro3Qv/vGoSKwTFoX OgiE5wOLiuqe0sCcEx6yHFwKjK+jYuXMQWmgkYYmhdeopG2utOHYkhX4fNjTxI2zvneW 6d053ErwM8gxqhCJSzxq2YeNmkx/NUnkd84Dcf3YRwKny5PNliMDIQ9N6+ZSBsuUE4wB lqOUSgMgUY6vVvqImt4TbJQupOB7DBcjmlaLorI/dKDLooHta794x2LP/8TyhoPt59V2 zYEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:references:from:message-id:date :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=uCuoIftyzzvL3bV/AwWt2TZaI5K+zTeLPFaxoJAdJsg=; b=FtvmxvD6V2ebBf3yez9dnY7BaBcUbt6REwBMYtPh0wEc/PbvdDMqHNq+Wi6lSERR0C fwhKRA98+6QMH490CsCqaQVKuPsMKEThjP97OpoMyfhajdbiErAOzcfV3FJu2t/KSHrE 1RwNhKcMUOWReirydfpn9m8trDUpJPUTtzED8ga8bOY1xgH7deaA8rPQFf6TSESrbUnN Cf+nv6jujk8tYQDHAsRymX/+7bA52dP1R7Nx/Q3afzKpfhyHbwqnS/7GklCiCmj3YbQz 42D3lMSjRv1OS/n+s/NWnAF9vcsNWv8U6oAegx7/jibLRCBOJek4IRR3kkO0qoeAXkFz q6BQ== X-Gm-Message-State: AOAM533MIxHAk/bNgCCbtilbfjFEjINFMjweg8m4Y9dmxIGxScLY4qi/ M9HSbUYRkrfZBfytvUS7rA46XJ/TIHI= X-Google-Smtp-Source: ABdhPJyGjg7fb+PxbOnnxSFFFfyqQl2BQvxLuNnvXVvXAkZ3lS6iEEMTaFcRwvH7mMC8fKe0wlnxgQ== X-Received: by 2002:a05:6a00:acc:b0:44b:ff29:621b with SMTP id c12-20020a056a000acc00b0044bff29621bmr12656506pfl.32.1635091393277; Sun, 24 Oct 2021 09:03:13 -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 s30sm19400446pfg.17.2021.10.24.09.03.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 24 Oct 2021 09:03:12 -0700 (PDT) In-Reply-To: <90ba36dccc00d6f0d62d@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:218146 Archived-At: 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? ")))) --------------------------------------------------