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.
This commit is contained in:
Daniel - 2020-09-02 11:12:24 +02:00
parent 03f23b11fb
commit b51c311210
No known key found for this signature in database
GPG Key ID: 1C7071A75BB72D64
1 changed files with 14 additions and 2 deletions

16
init.el
View File

@ -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