Function: eglot

eglot is an autoloaded, interactive and byte-compiled function defined in eglot.el.gz.

Signature

(eglot MANAGED-MAJOR-MODES PROJECT CLASS CONTACT LANGUAGE-IDS &optional INTERACTIVE)

Documentation

Start LSP server for PROJECT's buffers under MANAGED-MAJOR-MODES.

This starts a Language Server Protocol (LSP) server suitable for the buffers of PROJECT whose major-mode is among MANAGED-MAJOR-MODES. CLASS is the class of the LSP server to start and CONTACT specifies how to connect to the server.

Interactively, the command attempts to guess MANAGED-MAJOR-MODES, CLASS, CONTACT, and LANGUAGE-IDS from eglot-server-programs, according to the current buffer's major-mode. PROJECT is guessed from project-find-functions. The search for active projects in this context binds eglot-lsp-context (which see).

If it can't guess, it prompts the user for the mode and the server. With a single C-u (universal-argument) prefix arg, it always prompts for COMMAND. With two C-u (universal-argument), it also always prompts for MANAGED-MAJOR-MODE.

The LSP server of CLASS is started (or contacted) via CONTACT. If this operation is successful, current *and future* file buffers of MANAGED-MAJOR-MODE inside PROJECT become "managed" by the LSP server, meaning the information about their contents is exchanged periodically with the server to provide enhanced code-analysis via xref-find-definitions, flymake-mode(var)/flymake-mode(fun), eldoc-mode(var)/eldoc-mode(fun), and completion-at-point, among others.

PROJECT is a project object as returned by project-current.

CLASS is a subclass of eglot-lsp-server(var)/eglot-lsp-server(fun).

CONTACT specifies how to contact the server. It is a keyword-value plist used to initialize CLASS or a plain list as described in eglot-server-programs, which see.

LANGUAGE-IDS is a list of language ID string to send to the server for each element in MANAGED-MAJOR-MODES.

INTERACTIVE is ignored and provided for backward compatibility.

Probably introduced at or before Emacs version 29.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/eglot.el.gz
;;;###autoload
(defun eglot (managed-major-modes project class contact language-ids
                                 &optional _interactive)
  "Start LSP server for PROJECT's buffers under MANAGED-MAJOR-MODES.

This starts a Language Server Protocol (LSP) server suitable for
the buffers of PROJECT whose `major-mode' is among
MANAGED-MAJOR-MODES.  CLASS is the class of the LSP server to
start and CONTACT specifies how to connect to the server.

Interactively, the command attempts to guess MANAGED-MAJOR-MODES,
CLASS, CONTACT, and LANGUAGE-IDS from `eglot-server-programs',
according to the current buffer's `major-mode'.  PROJECT is
guessed from `project-find-functions'.  The search for active
projects in this context binds `eglot-lsp-context' (which see).

If it can't guess, it prompts the user for the mode and the
server.  With a single \\[universal-argument] prefix arg, it
always prompts for COMMAND.  With two \\[universal-argument], it
also always prompts for MANAGED-MAJOR-MODE.

The LSP server of CLASS is started (or contacted) via CONTACT.
If this operation is successful, current *and future* file
buffers of MANAGED-MAJOR-MODE inside PROJECT become \"managed\"
by the LSP server, meaning the information about their contents is
exchanged periodically with the server to provide enhanced
code-analysis via `xref-find-definitions', `flymake-mode',
`eldoc-mode', and `completion-at-point', among others.

PROJECT is a project object as returned by `project-current'.

CLASS is a subclass of `eglot-lsp-server'.

CONTACT specifies how to contact the server.  It is a
keyword-value plist used to initialize CLASS or a plain list as
described in `eglot-server-programs', which see.

LANGUAGE-IDS is a list of language ID string to send to the
server for each element in MANAGED-MAJOR-MODES.

INTERACTIVE is ignored and provided for backward compatibility."
  (interactive
   (let ((current-server (eglot-current-server)))
     (unless (or (null current-server)
                 (y-or-n-p "\
[eglot] Shut down current connection before attempting new one?"))
       (user-error "[eglot] Connection attempt aborted by user"))
     (prog1 (append (eglot--guess-contact t) '(t))
       (when current-server (ignore-errors (eglot-shutdown current-server))))))
  (eglot--connect (eglot--ensure-list managed-major-modes)
                  project class contact
                  (eglot--ensure-list language-ids)))