From 198f98b43d5dde34775010ac987d31e90745381f Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Thu, 1 Dec 2022 16:46:57 -0800 Subject: [PATCH] Make killing a non-last client work the same no matter the auto-stop setting Do not merge to master. (This is a minimal change for the release branch, and will be fixed in a cleaner way on master.) Previously, if 'server-stop-automatically' was configured for 'kill-terminal' or 'delete-frame', killing a client via 'save-buffers-kill-terminal' wouldn't prompt about the saving files in the client's buffer list (as it does when not using those settings). This change ensures that those settings only apply when killing the last client, as described in the manual (bug#51993). * lisp/server.el (server-stop-automatically--handle-delete-frame): When called by 'save-buffers-kill-terminal', first check to see whether we'll want to kill Emacs, and if not, call 'save-some-buffers' and 'server-delete-client', as in 'server-save-buffers-kill-terminal'. --- lisp/server.el | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/lisp/server.el b/lisp/server.el index 1b027f88ce..0657af1f98 100644 --- a/lisp/server.el +++ b/lisp/server.el @@ -1809,19 +1809,32 @@ server-stop-automatically--handle-delete-frame (when server-stop-automatically (if (if (and (processp (frame-parameter frame 'client)) (eq this-command 'save-buffers-kill-terminal)) - (progn - (dolist (f (frame-list)) - (when (and (eq (frame-parameter frame 'client) - (frame-parameter f 'client)) - (not (eq frame f))) - (set-frame-parameter f 'client nil) - (let ((server-stop-automatically nil)) - (delete-frame f)))) - (if (cddr (frame-list)) - (let ((server-stop-automatically nil)) - (delete-frame frame) - nil) - t)) + (let* ((proc (frame-parameter frame 'client)) + ;; Keep the server alive if... + (keep-server-alive-p + (or + ;; a) there are any other clients, or... + (length> server-clients 1) + ;; b) there are any frames not owned by this + ;; client. + (seq-some + (lambda (frame) + (when-let ((p (frame-parameter frame 'client))) + (not (eq proc p)))) + (frame-list))))) + (when keep-server-alive-p + ;; If we want to keep the server alive, don't kill + ;; Emacs. Instead, just call `save-some-buffers' and + ;; delete the client, as in + ;; `server-save-buffers-kill-terminal' above. + (let ((buffers (process-get proc 'buffers))) + (save-some-buffers + nil (if buffers + (lambda () (memq (current-buffer) buffers)))) + (server-delete-client proc))) + ;; Tell the outer `if' block whether we want to kill + ;; Emacs. + (not keep-server-alive-p)) (null (cddr (frame-list)))) (let ((server-stop-automatically nil)) (save-buffers-kill-emacs) -- 2.25.1