From edbc24d9cd6e05291531a65a78bb960439ceaae2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jo=C3=A3o=20T=C3=A1vora?= Date: Wed, 1 Jan 2020 22:05:29 +0000 Subject: [PATCH] Avoid double shutdowns and simplify shutdown logic * eglot.el (eglot-shutdown): Don't turn off eglot--managed-mode here. (eglot--on-shutdown): Rather here, but without autoshutdown. (eglot--managed-mode): Don't check eglot--shutdown-requested. GitHub-reference: fix https://github.com/joaotavora/eglot/issues/389 --- lisp/progmodes/eglot.el | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index d1ff7da5d9c..e952b912d16 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -599,9 +599,6 @@ SERVER. ." ;; this one is supposed to always fail, because it asks the ;; server to exit itself. Hence ignore-errors. (ignore-errors (jsonrpc-request server :exit nil :timeout 1))) - ;; Turn off `eglot--managed-mode' where appropriate. - (dolist (buffer (eglot--managed-buffers server)) - (eglot--with-live-buffer buffer (eglot--managed-mode-off))) ;; Now ask jsonrpc.el to shut down the server (which under normal ;; conditions should return immediately). (jsonrpc-shutdown server (not preserve-buffers)) @@ -611,7 +608,9 @@ SERVER. ." "Called by jsonrpc.el when SERVER is already dead." ;; Turn off `eglot--managed-mode' where appropriate. (dolist (buffer (eglot--managed-buffers server)) - (eglot--with-live-buffer buffer (eglot--managed-mode-off))) + (let (;; Avoid duplicate shutdowns (github#389) + (eglot-autoshutdown nil)) + (eglot--with-live-buffer buffer (eglot--managed-mode-off)))) ;; Kill any expensive watches (maphash (lambda (_id watches) (mapcar #'file-notify-rm-watch watches)) @@ -1289,8 +1288,7 @@ For example, to keep your Company customization use (setf (eglot--managed-buffers server) (delq (current-buffer) (eglot--managed-buffers server))) (when (and eglot-autoshutdown - (not (eglot--shutdown-requested server)) - (not (eglot--managed-buffers server))) + (null (eglot--managed-buffers server))) (eglot-shutdown server))))))) (defun eglot--managed-mode-off () -- 2.39.2