From 4bcdb1cc65bf779b6479f99a7aa767ab83b3bae1 Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Fri, 2 Dec 2022 12:14:50 -0800 Subject: [PATCH] Make killing a non-last client work the same no matter the auto-stop setting 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-save-buffers-kill-terminal): Handle 'server-stop-automatically' behavior in this function, rather than calling 'server-stop-automatically--handle-delete-frame'. --- lisp/server.el | 60 +++++++++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/lisp/server.el b/lisp/server.el index 1b027f88ce6..7e713eaecde 100644 --- a/lisp/server.el +++ b/lisp/server.el @@ -1780,29 +1780,43 @@ With ARG non-nil, 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." - (if server-stop-automatically - (server-stop-automatically--handle-delete-frame (selected-frame)) - (let ((proc (frame-parameter nil 'client))) - (cond ((eq proc 'nowait) - ;; Nowait frames have no client buffer list. - (if (cdr (frame-list)) - (progn (save-some-buffers arg) - (delete-frame)) - ;; If we're the last frame standing, kill Emacs. - (save-buffers-kill-emacs arg))) - ((processp proc) - (let ((buffers (process-get proc 'buffers))) - (save-some-buffers - arg (if buffers - ;; Only files from emacsclient file list. - (lambda () (memq (current-buffer) buffers)) - ;; No emacsclient file list: don't override - ;; `save-some-buffers-default-predicate' (unless - ;; ARG is non-nil), since we're not killing - ;; Emacs (unlike `save-buffers-kill-emacs'). - (and arg t))) - (server-delete-client proc))) - (t (error "Invalid client frame")))))) + (let ((proc (frame-parameter nil 'client))) + (cond ((eq proc 'nowait) + ;; Nowait frames have no client buffer list. + (if (length> (frame-list) (if server-stop-automatically 2 1)) + ;; If there are any other frames, only delete this one. + ;; When `server-stop-automatically' is set, don't count + ;; the daemon frame. + (progn (save-some-buffers arg) + (delete-frame)) + ;; If we're the last frame standing, kill Emacs. + (save-buffers-kill-emacs arg))) + ((processp proc) + (if (or (not server-stop-automatically) + (length> server-clients 1) + (seq-some + (lambda (frame) + (when-let ((p (frame-parameter frame 'client))) + (not (eq proc p)))) + (frame-list))) + ;; If `server-stop-automatically' is not enabled, there + ;; are any other clients, or there are frames not owned + ;; by the current client (e.g. `nowait' frames), then + ;; we just want to delete this client. + (let ((buffers (process-get proc 'buffers))) + (save-some-buffers + arg (if buffers + ;; Only files from emacsclient file list. + (lambda () (memq (current-buffer) buffers)) + ;; No emacsclient file list: don't override + ;; `save-some-buffers-default-predicate' (unless + ;; ARG is non-nil), since we're not killing + ;; Emacs (unlike `save-buffers-kill-emacs'). + (and arg t))) + (server-delete-client proc)) + ;; Otherwise, we want to kill Emacs. + (save-buffers-kill-emacs arg))) + (t (error "Invalid client frame"))))) (defun server-stop-automatically--handle-delete-frame (frame) "Handle deletion of FRAME when `server-stop-automatically' is used." -- 2.39.2