Subject: bug#58877: 29.0.50; [PATCH] When killing Emacs from a client frame with no other frames, Emacs shows a useless error prompt

From: Jim Porter <[email-masked]>
Date: Sun, 27 Nov 2022 17:28:41 -0800

On 11/26/2022 1:44 PM, Jim Porter wrote:
> On 11/26/2022 12:35 PM, Eli Zaretskii wrote:
>>> Date: Sat, 26 Nov 2022 12:17:59 -0800
>>> Cc: [email-masked]
>>> From: Jim Porter <[email-masked]>
>>>
>>> Unless you have an idea for how to fix that (I've got no clue,
>>> unfortunately), how about just skipping these tests on MS Windows, with
>>> a comment explaining what the limitation is?
>>
>> Fine with me, thanks.
> 
> Thanks. I've merged the fixes for the tests as 
> 14d54212ea46dbd8c950c9852318597e0e47908d. If you see any other issues, 
> just let me know.

Here's one tiny followup fix. Currently on master, if you restart the 
Emacs server, it emits a "Server stopped" message. That's not right, and 
it should do what it used to: emit a "Restarting server" message. Here's 
a fix.

From 1724f23f3d8b3bef18bcd97e2f892e943f03c0da Mon Sep 17 00:00:00 2001
From: Jim Porter <[email-masked]>
Date: Sun, 27 Nov 2022 17:22:49 -0800
Subject: [PATCH] ; Don't emit a "Server stopped" message when restarting the
 Emacs server

* lisp/server.el (server-stop): Return non-nil when we actually stop
the server.  Don't message about stopping the server here (but do log
it).
(server-start): Emit the appropriate message about stopping or
restarting the server.
---
 lisp/server.el | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/lisp/server.el b/lisp/server.el
index 2102f8569b..1b027f88ce 100644
--- a/lisp/server.el
+++ b/lisp/server.el
@@ -619,20 +619,22 @@ server--file-name
 
 (defun server-stop (&optional noframe)
   "If this Emacs process has a server communication subprocess, stop it.
-If the server is running in some other Emacs process (see
+If this actually stopped the server, return non-nil.  If the
+server is running in some other Emacs process (see
 `server-running-p'), signal a `server-running-external' error.
 
 If NOFRAME is non-nil, don't delete any existing frames
 associated with a client process.  This is useful, for example,
 when killing Emacs, in which case the frames will get deleted
 anyway."
-  (let ((server-file (server--file-name)))
+  (let ((server-file (server--file-name))
+        stopped-p)
     (when server-process
       ;; Kill it dead!
       (ignore-errors (delete-process server-process))
-      (unless noframe
-        (server-log (message "Server stopped")))
-      (setq server-process nil
+      (server-log "Stopped server")
+      (setq stopped-p t
+            server-process nil
             server-mode nil
             global-minor-modes (delq 'server-mode global-minor-modes)))
     (unwind-protect
@@ -658,7 +660,8 @@ server-stop
                                   server-name))))
       ;; If this Emacs already had a server, clear out associated status.
       (while server-clients
-        (server-delete-client (car server-clients) noframe)))))
+        (server-delete-client (car server-clients) noframe)))
+    stopped-p))
 
 ;;;###autoload
 (defun server-start (&optional leave-dead inhibit-prompt)
@@ -702,7 +705,8 @@ server-start
         (if (and internal--daemon-sockname
                  (not server--external-socket-initialized))
             (setq server--external-socket-initialized t)
-          (server-stop))
+          (when (server-stop)
+            (message (if leave-dead "Stopped server" "Restarting server"))))
       (server-running-external
        (display-warning
         'server
@@ -717,8 +721,6 @@ server-start
       (let ((server-file (server--file-name)))
 	;; Make sure there is a safe directory in which to place the socket.
 	(server-ensure-safe-dir (file-name-directory server-file))
-	(when server-process
-	  (server-log (message "Restarting server")))
         (with-file-modes ?\700
 	  (add-hook 'suspend-tty-functions #'server-handle-suspend-tty)
 	  (add-hook 'delete-frame-functions #'server-handle-delete-frame)
@@ -756,7 +758,7 @@ server-start
 			       :service server-file
 			       :plist '(:authenticated t)))))
 	  (unless server-process (error "Could not start server process"))
-          (server-log "Starting server")
+          (server-log "Started server")
 	  (process-put server-process :server-file server-file)
           (setq server-mode t)
           (push 'server-mode global-minor-modes)
-- 
2.25.1