More Customization
As explained earlier (see Buffers, Projects, and Eglot), Eglot hooks onto existing Emacs packages and features by setting special variables in its special minor mode. To gain finer control of Eglot’s operation, the eglot-managed-mode-hook should be used to tweak, subdue or completely override Eglot’s setting of these variables.
Eglot hooks onto ElDoc’s
eldoc-documentation-functionsvariable, adding a number of functions to it:eglot-hover-eldoc-function, to display general information about an identifier.eglot-signature-eldoc-function, to display function signature information.eglot-highlight-eldoc-function, to highlight nearby manifestations of an identifier.eglot-code-action-suggestion, to retrieve relevant code actions at point.
A simple tweak to remove at-point identifier information for hypothetical language
Foomay look like:emacs-lisp(add-hook 'foo-mode-hook (lambda () (add-hook 'eglot-managed-mode-hook (lambda () (remove-hook 'eldoc-documentation-functions 'eglot-hover-eldoc-function nil t)) nil t)))For more sophisticated changes, we can take advantage of ElDoc’s well-defined protocols. See Programming Language Doc in GNU Emacs Manual. For instance, the functions in
eldoc-display-functionscontrol displays of the at-point documentation produced byeldoc-documentation-functions. As an example, to ensure that hover documentation specifically is never output into the Echo area (in all programming modes):emacs-lisp(require 'cl-lib) (defun my/special-eglot-hover-function (cb &rest _ignored) "Same as `eglot-hover-eldoc-function`, but skip the echo area." (eglot-hover-eldoc-function (lambda (info &rest _ignore) (funcall cb info :echo 'skip)))) ;; substitute 'eldoc-hover-eldoc-function with our "fixed" variant. (add-hook 'eglot-managed-mode-hook (lambda () (setq-local eldoc-documentation-functions (cl-substitute #'my/special-eglot-hover-function 'eglot-hover-eldoc-function eldoc-documentation-functions))))Eglot hooks onto Flymake’s
flymake-diagnostic-functionsvariable, completely replacing its value with Eglot’s owneglot-flymake-backendfunction. Additional backends may be added to work alongside Eglot’s.Eglot hooks onto Xref’s
xref-backend-functionsvariable, adding its owneglot-xref-backendfunction to it.Eglot hooks onto Imenu’s
imenu-create-index-function.Eglot hooks onto Emacs’s
completion-at-point-functions.Eglot hooks onto Company’s
company-backendsvariable, ensuring only thecompany-capfbackend lives there. This ensures the same set of completions as regularcompletion-at-point.Eglot hooks onto YASnippet by automatically activating
yas-minor-modewhen needed to expand server-provided snippets.