From 3f08b120a83b3c06a777823acee604f94fd41210 Mon Sep 17 00:00:00 2001 From: Jim Porter 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 Previously, this function prompted whenever there was a live client, including the current one. Now, only prompt in one of: 1. There are live Emacs clients other than the current one, or 2. The current frame is a client frame and there are also non-client frames open. * lisp/server.el (server-kill-emacs-query-function): Rewrite to avoid prompting as above (bug#58404). --- lisp/server.el | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/lisp/server.el b/lisp/server.el index 3caa335c4e..f74f26210a 100644 --- a/lisp/server.el +++ b/lisp/server.el @@ -1589,14 +1589,34 @@ 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))) + (cond + ;; Check for Emacs clients, excluding the current one (if any). + ;; If there are any other clients, prompt the user before killing + ;; Emacs. Other clients might be on different (possibly remote) + ;; displays, so it can be hard for users to tell on their own. + ((seq-some (lambda (proc) + (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? ")) + ;; If the user is in a client frame, prompt if there are any + ;; frames created by the main Emacs process. Like in the case + ;; above, those frames might be on different displays. + ((and (processp this-client) + ;; Don't count 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? ")) + ;; Otherwise, we can kill Emacs without prompting. + (t t)))) (defun server-kill-buffer () "Remove the current buffer from its clients' buffer list. -- 2.25.1