From b51c311210d96daf04af4cf388a4aa4f536733cc Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Wed, 2 Sep 2020 11:12:24 +0200 Subject: [PATCH] Make server start more robust The present configuration is supposed to start the server if it's not already running. Previously we checked this using `server-running-p', but this is not really realiable. Instead, we now checking the `server-process' variable directly. Furthermore, if it turns out during startup that the currently configured server file is already present, we warn the user about this and don't do anything else. We let the user to fix it manually because it's (i) easy for the user (easier than doing it automatically) and (ii) only done once, namly during startup (the burden on the user is thus tenable). The current implementation may not be accurate, though, as my understanding of the implementation around Emacs' server functionality is only at the beginning. --- init.el | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/init.el b/init.el index 490bc88..ff2749e 100644 --- a/init.el +++ b/init.el @@ -272,8 +272,20 @@ ;; Start Server when not running already - (unless (server-running-p) - (server-start)) + (unless (and (boundp 'server-process) server-process) + (require 'server) + + (let ((server-file (expand-file-name server-name + (if server-use-tcp server-auth-dir server-socket-dir)))) + (if (file-exists-p server-file) + (warn "Server file already exists, but no server process is running. Check %s and restart server manually." + server-file) + + (server-start) + (ecase (server-running-p) + ((t) t) ; server is running + (nil (warn "Server not running, check logs and restart manually.")) + (t (warn "`server-running-p' returned neither nil nor t. Check and restart server manually if required.")))))) ;; Load custom code