This chapter provides concise instructions for setting up and using Eglot with your programming project in common usage scenarios. For more detailed instructions regarding Eglot setup, see Eglot and LSP Servers. See Using Eglot, for detailed description of using Eglot, and see Customizing Eglot, for adapting Eglot to less common use patterns.
Here’s how to start using Eglot with your programming project:
Eglot comes pre-configured with many popular language servers, see the
value of eglot-server-programs
. If the server(s) mentioned
there satisfy your needs for the programming language(s) with which
you want to use Eglot, you just need to make sure those servers are
installed on your system. Alternatively, install one or more servers
of your choice and add them to the value of
eglot-server-programs
, as described in Setting Up LSP Servers.
To start using Eglot for a project, type M-x eglot RET in a buffer visiting any file that belongs to the project. This starts the language server configured for the programming language of that buffer, and causes Eglot to start managing all the files of the project which use the same programming language. The notion of a “project” used by Eglot is the same Emacs uses (see Projects in GNU Emacs Manual): in the simplest case, the “project” is the single file you are editing, but it can also be all the files in a single directory or a directory tree under some version control system, such as Git.
Alternatively, you can start Eglot automatically from the major-mode hook of the mode used for the programming language; see Starting Eglot.
Most Eglot facilities are integrated into Emacs features, such as ElDoc, Flymake, Xref, and Imenu. However, Eglot also provides commands of its own, mainly to perform tasks by the language server, such as M-x eglot-rename (to rename an identifier across the entire project), M-x eglot-format (to reformat and reindent code), and some others. See Eglot Commands, for the detailed list of Eglot commands.