2019-01-07
I have an old post documenting my first
attempt at turning Emacs into a C++ IDE with clangd
. That post
describes using two packages: lsp-mode
and lsp-clangd
. Those
packages have evolved and now clangd
usage is built into lsp-mode
,
so the post is a bit outdated. I've also started to use
Eglot (see previous post for my
Eglot Python IDE). So, let's put together an updated setup:
First, one needs to have clangd
installed. These days, the 8.0
release of LLVM is a few months away, but clangd
(part of the
clang-tools-extra
LLVM project) is in rapid development and the
master
of the repository should be used. The installation
instructions
from the LLVM documentation are easy to follow.
My C++ development happens on multiple machines. In my Emacs
configuration I keep a simple variable around to point to wherever
clangd
is installed on various machines.
By default I'm letting Emacs find it, but I have things like this
sprinkled around my configuration (pointing to a specific LLVM
installation not in my PATH
):
Eglot uses project.el
, but I use
Projectile, so I start by
defining a function that will tell project.el
to find a project via
Projectile, thanks @wyuenho on
GitHub:
Now I have a function I call when I'm ready to start digging into a
C++ project which has an associated
compile_commands.json
:
use-package
.completion-at-point
backend is used by company
(bring it to the front of the company-backends
list).project.el
uses Projectile to find my project
definition (this is because I usually have C++ projects using git
submodules).clangd
executable to the eglot-server-programs
list.If I don't want the hook anymore, I use this very simple function: