Skip to content

Commit

Permalink
Option to autoshutdown after killing last buffer (joaotavora#308)
Browse files Browse the repository at this point in the history
This should close issue joaotavora#217, also cf. joaotavora#270.

* eglot.el: New defcustom `eglot-autoshutdown' (default t).
(eglot--managed-mode): Signal didClose before possibly triggering
autoshutdown.
(eglot--managed-mode-onoff): Shutdown if so configured and no managed
buffers left.
  • Loading branch information
ingolohmar authored and Ingo Lohmar committed Oct 2, 2019
1 parent d774754 commit 8c9c3ce
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions eglot.el
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ as 0, i.e. don't block at all."
:type '(choice (boolean :tag "Whether to inhibit autoreconnection")
(integer :tag "Number of seconds")))

(defcustom eglot-autoshutdown t
"If t, shut down a language server automatically after killing
the last buffer it has managed."
:type 'boolean)

(defcustom eglot-events-buffer-size 2000000
"Control the size of the Eglot events buffer.
If a number, don't let the buffer grow larger than that many
Expand Down Expand Up @@ -1172,7 +1177,7 @@ and just return it. PROMPT shouldn't end with a question mark."
(eglot--managed-mode
(add-hook 'after-change-functions 'eglot--after-change nil t)
(add-hook 'before-change-functions 'eglot--before-change nil t)
(add-hook 'kill-buffer-hook 'eglot--signal-textDocument/didClose nil t)
(add-hook 'kill-buffer-hook 'eglot--signal-textDocument/didClose -1 t) ;before possible server autoshutdown
(add-hook 'kill-buffer-hook 'eglot--managed-mode-onoff nil t)
(add-hook 'before-revert-hook 'eglot--signal-textDocument/didClose nil t)
(add-hook 'before-save-hook 'eglot--signal-textDocument/willSave nil t)
Expand Down Expand Up @@ -1223,7 +1228,11 @@ Reset in `eglot--managed-mode-onoff'.")
(setq eglot--cached-current-server nil)
(when server
(setf (eglot--managed-buffers server)
(delq buf (eglot--managed-buffers server)))))))))
(delq buf (eglot--managed-buffers server)))
(when (and eglot-autoshutdown
(not (eglot--shutdown-requested server))
(not (eglot--managed-buffers server)))
(eglot-shutdown server))))))))

(defun eglot--current-server ()
"Find the current logical EGLOT server."
Expand Down

0 comments on commit 8c9c3ce

Please sign in to comment.