all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#58404: 29.0.50; [PATCH] When killing Emacs from the last client, don't warn about the session having clients
@ 2022-10-09 23:32 Jim Porter
  2022-10-10  6:11 ` Eli Zaretskii
  0 siblings, 1 reply; 9+ messages in thread
From: Jim Porter @ 2022-10-09 23:32 UTC (permalink / raw)
  To: 58404

[-- Attachment #1: Type: text/plain, Size: 988 bytes --]

To reproduce:

   $ emacs -Q --daemon
   $ emacsclient foo.txt

   M-x save-buffers-kill-emacs
   => This Emacs session has clients; exit anyway?

I think that's unnecessary. Since we're in the last (only) client, we 
can't accidentally kill other clients that we don't see right now (e.g. 
ones in an SSH connection); they don't exist! Couldn't we just proceed 
ahead without the prompt?

On the other hand, I think it *would* be useful to prompt if you're in 
the last client, but there are other non-client frames. This can happen 
if you start the main Emacs process without --daemon or if you use 
--no-wait. For example:

   $ emacs -Q --daemon
   $ emacsclient foo.txt
   $ emacsclient --no-wait -c bar.txt

   ;; From the first client:
   M-x save-buffers-kill-emacs
   => This Emacs session has clients; exit anyway?

This is ok, except the prompt could be clearer. The real issue is that 
the session has non-client frames that would get killed.

Attached is a patch to do this.

[-- Attachment #2: 0001-Don-t-prompt-when-killing-an-Emacs-client-if-it-s-th.patch --]
[-- Type: text/plain, Size: 2215 bytes --]

From 2fb6c6da99b84c250e59409d4dc0adbdbe704fed Mon Sep 17 00:00:00 2001
From: Jim Porter <jporterbugs@gmail.com>
Date: Sun, 9 Oct 2022 15:53:27 -0700
Subject: [PATCH] Don't prompt when killing an Emacs client if it's the last
 client

* lisp/server.el (server-kill-emacs-query-function): Ignore the
current client, if any.  Prompt if there are non-client frames.
---
 lisp/server.el | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/lisp/server.el b/lisp/server.el
index 3caa335c4e..9ebdabbf87 100644
--- a/lisp/server.el
+++ b/lisp/server.el
@@ -1589,14 +1589,28 @@ server-done
     (server-buffer-done (current-buffer))))
 
 (defun server-kill-emacs-query-function ()
-  "Ask before exiting Emacs if it has live clients.
+  "Ask before exiting Emacs if it has other live clients or non-client frames.
 A \"live client\" is a client with at least one live buffer
 associated with it."
-  (or (not (seq-some (lambda (proc)
-                       (seq-some #'buffer-live-p
-                                 (process-get proc 'buffers)))
-                     server-clients))
-      (yes-or-no-p "This Emacs session has clients; exit anyway? ")))
+  (let ((this-client (frame-parameter nil 'client)))
+    (if (seq-some (lambda (proc)
+                    ;; Ignore the current client when checking for
+                    ;; live clients.
+                    (unless (eq proc this-client)
+                      (seq-some #'buffer-live-p
+                                (process-get proc 'buffers))))
+                  server-clients)
+        (yes-or-no-p "This Emacs session has other clients; exit anyway? ")
+      (or (not (processp this-client))
+          ;; Check if there are any non-client frames, ignoring the
+          ;; initial frame when in daemon mode.
+          (>= (if (daemonp) 1 0)
+              (seq-count
+               (lambda (frame)
+                 (not (processp (frame-parameter frame 'client))))
+               (frame-list)))
+          (yes-or-no-p
+           "This Emacs session has non-client frames; exit anyway? ")))))
 
 (defun server-kill-buffer ()
   "Remove the current buffer from its clients' buffer list.
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-10-10 23:09 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-09 23:32 bug#58404: 29.0.50; [PATCH] When killing Emacs from the last client, don't warn about the session having clients Jim Porter
2022-10-10  6:11 ` Eli Zaretskii
2022-10-10  8:08   ` Jim Porter
2022-10-10  8:53     ` Eli Zaretskii
2022-10-10 16:43       ` Jim Porter
2022-10-10 16:59         ` Eli Zaretskii
2022-10-10 17:49           ` Jim Porter
2022-10-10 17:57             ` Eli Zaretskii
2022-10-10 23:09               ` Jim Porter

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.