Function: eglot-ensure
eglot-ensure is an autoloaded and byte-compiled function defined in
eglot.el.gz.
Signature
(eglot-ensure)
Documentation
Start Eglot session for current buffer if there isn't one.
Only use this function (in major mode hooks, etc) if you are
confident that Eglot can be started safely and efficiently for
*every* buffer visited where these hooks may execute.
Since it is difficult to establish this confidence fully, it's
often wise to use the interactive command eglot instead. This
command only needs to be invoked once per project, as all other
files of a given major mode visited within the same project will
automatically become managed with no further user intervention
needed.
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/eglot.el.gz
(defvar eglot--managed-mode) ; forward decl
;;;###autoload
(defun eglot-ensure ()
"Start Eglot session for current buffer if there isn't one.
Only use this function (in major mode hooks, etc) if you are
confident that Eglot can be started safely and efficiently for
*every* buffer visited where these hooks may execute.
Since it is difficult to establish this confidence fully, it's
often wise to use the interactive command `eglot' instead. This
command only needs to be invoked once per project, as all other
files of a given major mode visited within the same project will
automatically become managed with no further user intervention
needed."
(let ((buffer (current-buffer)))
(cl-labels
((maybe-connect
()
(eglot--when-live-buffer buffer
(remove-hook 'post-command-hook #'maybe-connect t)
(unless eglot--managed-mode
(condition-case-unless-debug oops
(apply #'eglot--connect (eglot--guess-contact))
(error (eglot--warn (error-message-string oops))))))))
(when buffer-file-name
(add-hook 'post-command-hook #'maybe-connect 'append t)))))