Subject: Re: bug#76870: 31.0.50; server-start with non-nil arg LEAVE-DEAD can write confusing warnings

From: Jens Schmidt <[email-masked]>
Date: Sat, 8 Mar 2025 18:27:50 +0100

On 2025-03-08  17:04, Eli Zaretskii wrote:
>> Date: Sat, 08 Mar 2025 16:45:27 +0100
>> From:  Jens Schmidt via "Bug reports for GNU Emacs,
>>  the Swiss army knife of text editors" <[email-masked]>
>>
>> 1. So I think in case of non-nil LEAVE-DEAD and a running external
>>    server, a more appropriate warning would be:
>>
>>      ⛔ Warning (server): Unable to stop an external Emacs server.
>>      There is an existing Emacs server, named "server"
>>      Stop it either in its Emacs session or call M-x server-force-delete to forcibly disconnect it.
> 
> This doesn't seem to be very different from the current message.

Except that I use the word "stop" instead of "start" in its first
line...

Do we agree that the following are all equivalent in effect

  M-: (server-start t) RET

  C-u M-x server-start RET

  C-- M-x server-mode RET

and all should *stop* the server without restarting it?

If yes, then I find it confusing to read that Emacs could not
*start* the server in the resulting warning.

>> 4. Or at the very least it should be silent if called from
>>    `server-unload-function'.
> 
> The only bug here is 4.  Unloading the server feature should not cause
> this warning.  All the rest is the intended behavior.

How about the attached patch?  (Which I would extend if we find
an agreement for case 1. as well.)
From 5b5264bf39183a6b7ccc7319930764ac260cfe5f Mon Sep 17 00:00:00 2001
From: Jens Schmidt <[email-masked]>
Date: Sat, 8 Mar 2025 18:13:54 +0100
Subject: [PATCH] Silently stop the server if unloading its library

* lisp/server.el (server-unload-function): Silently stop the
server.  (Bug#76870)
---
 lisp/server.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/server.el b/lisp/server.el
index a49787e3498..644f46676b4 100644
--- a/lisp/server.el
+++ b/lisp/server.el
@@ -2016,7 +2016,7 @@ ctl-x-map
 
 (defun server-unload-function ()
   "Unload the Server library."
-  (server-mode -1)
+  (ignore-errors (server-stop 'noframe))
   (substitute-key-definition 'server-edit nil ctl-x-map)
   (save-current-buffer
     (dolist (buffer (buffer-list))
-- 
2.39.5