From 2fb6c6da99b84c250e59409d4dc0adbdbe704fed 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 * 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