200ok-ch/counsel-jq@f5bfed8 -> 200ok-ch/counsel-jq@153d70b Andersbakken/rtags@63a7d9b -> Andersbakken/rtags@aa4c827 MatthewFluet/company-mlton@b87e363 -> MatthewFluet/company-mlton@9b09d20 NixOS/nix-mode@e32c6bf -> NixOS/nix-mode@0023fc5 OmniSharp/omnisharp-emacs@e26ff8b -> OmniSharp/omnisharp-emacs@8ec5929 ProofGeneral/PG@702f5b9 -> ProofGeneral/PG@bdb6782 Wilfred/elisp-def@da1f763 -> Wilfred/elisp-def@dfca043 agda/agda@5070bd8 -> agda/agda@9d08edb ananthakumaran/exunit.el@c77b039 -> ananthakumaran/exunit.el@5bb115f ananthakumaran/tide@a43a37b -> ananthakumaran/tide@7f7334b asok/projectile-rails@7a256b1 -> asok/projectile-rails@8d6b373 brotzeit/rustic@f7d5ac0 -> brotzeit/rustic@61d600e clojure-emacs/cider@1a34f89 -> clojure-emacs/cider@815204f clojure-emacs/clj-refactor.el@9dcc50d -> clojure-emacs/clj-refactor.el@b24ce76 clojure-emacs/clojure-mode@53ef8ac -> clojure-emacs/clojure-mode@f26379b crystal-lang-tools/emacs-crystal-mode@f9e4db1 -> crystal-lang-tools/emacs-crystal-mode@1599814 cython/cython@17e03b8 -> cython/cython@9a761a6 dgutov/robe@f04dcc7 -> dgutov/robe@3ef165c diml/utop@7bc5117) -> diml/utop@a5ff52b) dominikh/go-mode.el@fdf46fe -> dominikh/go-mode.el@49a5380 elixir-editors/emacs-elixir@b78e7f7 -> elixir-editors/emacs-elixir@9de08c1 emacs-csharp/csharp-mode@4916829 -> emacs-csharp/csharp-mode@09b4d57 emacs-ess/ESS@d013616 -> emacs-ess/ESS@5169b0d emacs-lsp/lsp-dart@b81b1ec -> emacs-lsp/lsp-dart@71902ca emacs-lsp/lsp-haskell@4d85cb3 -> emacs-lsp/lsp-haskell@7efbef3 emacs-lsp/lsp-java@f43b00a -> emacs-lsp/lsp-java@5f6d357 emacs-lsp/lsp-metals@31dafff -> emacs-lsp/lsp-metals@c76eeb6 emacs-lsp/lsp-pyright@71ff088 -> emacs-lsp/lsp-pyright@65fb141 emacs-lsp/lsp-python-ms@5470ada -> emacs-lsp/lsp-python-ms@689f6cf emacs-lsp/lsp-sourcekit@948c3a3 -> emacs-lsp/lsp-sourcekit@ff204ed emacs-php/php-mode@7e5722c -> emacs-php/php-mode@8cdc727 emacs-straight/auctex@fb062a3 -> emacs-straight/auctex@384c4b9 emacs-straight/csv-mode@eb3ec00 -> emacs-straight/csv-mode@8da54e8 emacs-straight/org-mode@9e98e9a -> emacs-straight/org-mode@0b117f7 emacs-typescript/typescript.el@54f14c4 -> emacs-typescript/typescript.el@1043025 emacsmirror/cmake-mode@e58c411 -> emacsmirror/cmake-mode@d5d77de ericdallo/hover.el@3f07a18 -> ericdallo/hover.el@c9c0593 erlang/otp@8fc0641 -> erlang/otp@af06b43 eschulte/jump.el@e4f1372 -> eschulte/jump.el@55caa66 ethereum/emacs-solidity@d166a86 -> ethereum/emacs-solidity@b4fd719 factor/factor@94a922a -> factor/factor@1928e60 fsharp/emacs-fsharp-mode@13fbf4c -> fsharp/emacs-fsharp-mode@78898a1 fxbois/web-mode@890e837 -> fxbois/web-mode@8ef4793 godotengine/emacs-gdscript-mode@75fe658 -> godotengine/emacs-gdscript-mode@16c631c greghendershott/racket-mode@3563081 -> greghendershott/racket-mode@75ea8f6 haskell/haskell-mode@0d39c84 -> haskell/haskell-mode@3a019e6 hhvm/hack-mode@9079bc3) -> hhvm/hack-mode@847fd91) hvesalai/emacs-scala-mode@9d3b56e -> hvesalai/emacs-scala-mode@402d6df idris-hackers/idris-mode@b77eadd -> idris-hackers/idris-mode@80aabd2 immerrr/lua-mode@d2ff304 -> immerrr/lua-mode@2d9a468 iyefrat/evil-tex@ac313ef -> iyefrat/evil-tex@5f0d6fb jaor/geiser@cd00be6 -> jaor/geiser@26dd2f4 jcollard/elm-mode@363da4b -> jcollard/elm-mode@188b9c7 joaotavora/sly@3278819 -> joaotavora/sly@fb84318 jorgenschaefer/emacs-buttercup@2f24a44 -> jorgenschaefer/emacs-buttercup@1de6be4 jrblevin/markdown-mode@dcad557 -> jrblevin/markdown-mode@0517340 jwiegley/emacs-async@14f48de -> jwiegley/emacs-async@d7e7f79 jyp/attrap@9c88154 -> jyp/attrap@778382e jyp/dante@e2acbf6 -> jyp/dante@7b1ab64 kaushalmodi/ox-hugo@04f41ca -> kaushalmodi/ox-hugo@a05667e leanprover/lean-mode@cc1f5fa -> leanprover/lean-mode@15bee87 ledger/ledger-mode@805507f -> ledger/ledger-mode@3495d12 mooz/js2-mode@f7816bd -> mooz/js2-mode@29979e5 nonsequitur/inf-ruby@b012457 -> nonsequitur/inf-ruby@1fc972e ocaml-ppx/ocamlformat@860266b -> ocaml-ppx/ocamlformat@7db8d13 ocaml/dune@4d097cd -> ocaml/dune@f839fc1 ocaml/merlin@28193d5 -> ocaml/merlin@36d0aef pezra/rspec-mode@f1029ca -> pezra/rspec-mode@92ef785 polymode/poly-R@51ffeb6 -> polymode/poly-R@c42ff3a polymode/polymode@3284ff1 -> polymode/polymode@b3871e9 purescript-emacs/psc-ide-emacs@663f4e2 -> purescript-emacs/psc-ide-emacs@ce97d71 purescript-emacs/purescript-mode@154ad16 -> purescript-emacs/purescript-mode@8410baf pwalsh/pipenv.el@f516a1a -> pwalsh/pipenv.el@8f50c68 pythonic-emacs/anaconda-mode@b1875a5 -> pythonic-emacs/anaconda-mode@081f9d8 racer-rust/emacs-racer@a0bdf77 -> racer-rust/emacs-racer@f17f9d7 rubocop-hq/rubocop-emacs@03bf155 -> rubocop-hq/rubocop-emacs@1372ee3 seagle0128/grip-mode@91da46f -> seagle0128/grip-mode@1aebf9c senny/rvm.el@b2498a4 -> senny/rvm.el@c1f2642 swift-emacs/swift-mode@0bc8d8d -> swift-emacs/swift-mode@95ff004 takaxp/org-tree-slide@04b5a9d -> takaxp/org-tree-slide@c9487e5 technomancy/fennel-mode@fa56106 -> technomancy/fennel-mode@bebc9dd tpapp/julia-repl@d073acb -> tpapp/julia-repl@7ce38a9 wbolster/emacs-python-pytest@3fadf1f -> wbolster/emacs-python-pytest@31ae5e0 wwwjfy/emacs-fish@db257db -> wwwjfy/emacs-fish@a7c953b Fix #4695 Close #4529 Close #4576
lang/cc
Description
This module adds support for the C-family of languages: C, C++, and Objective-C.
- Code completion (
company-irony
) - eldoc support (
irony-eldoc
) - Syntax-checking (
flycheck-irony
) - Code navigation (
rtags
) - File Templates (c-mode, c++-mode)
- Snippets (cc-mode, c-mode, c++-mode)
- Several improvements to C++11 indentation and syntax highlighting.
Module Flags
+lsp
Disables irony+rtags and replaces them with LSP (ccls by default). This requires the:tools lsp
module.
Plugins
- cmake-mode
- cuda-mode
- demangle-mode
- disaster
- modern-cpp-font-lock
- opencl-mode
- glsl-mode*
- company-glsl*
-
+lsp
- ccls if
:tools lsp
has no+eglot
flag
- ccls if
-
-lsp
Prerequisites
This module's requirements change depending on how you use it.
- If
+lsp
is enabled, you need one of clangd v9+ or ccls. - If
+lsp
is not enabled, you need irony-server and rtags. -
Other features in this module depend on:
- (optional) glslangValidator, for GLSL completion in
glsl-mode
- (optional) cmake, for code completion in
cmake-mode
- (optional) glslangValidator, for GLSL completion in
- You will need a C/C++ compiler, like
gcc
orclang
.
LSP servers
lsp-mode
and eglot
support a few LSP servers, but clangd
and ccls
are
recommended.
- clangd (must be v9 or newer)
-
clangd is included with
llvm
which should be available through your OS' package manager.-
Linux:
-
Debian 11 & Ubuntu 20.10:
# apt-get install clangd-11
- 20.04 LTS: clangd-10
- Fedora & CentOS/RHEL 8+:
# dnf install clang-tools-extra
- openSUSE:
# zypper install clang
- Arch:
# pacman -S clang
-
-
BSDs:
- NetBSD & OpenBSD:
# pkg_add clang-tools-extra
- NetBSD & OpenBSD:
- macOS:
$ brew install llvm
// 1GB+ installation! May take a while! - Windows: use the win64 installer from LLVM's GitHub release page.
-
- ccls
- Available in many OS' package managers as
ccls
. Otherwise, there are alternative install methods listed in the project's wiki. - cmake-language-server
- available through
pip
on most distributions
irony-server
Irony powers the code completion, eldoc and syntax checking systems.
After installing its dependencies (Clang and CMake), run M-x
irony-install-server
in Emacs.
macOS
Due to linking issues, macOS users must compile irony-server manually:
brew install cmake
brew install llvm
git clone https://github.com/Sarcasm/irony-mode irony-mode
mkdir irony-mode/server/build
pushd irony-mode/server/build
DEST="$HOME/.emacs.d/.local/etc/irony-server/"
cmake -DCMAKE_PREFIX_PATH=/usr/local/opt/llvm \
-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON \
-DCMAKE_INSTALL_PREFIX="$DEST" ../
cmake --build . --use-stderr --config Release --target install
install_name_tool -change @rpath/libclang.dylib \
/usr/local/opt/llvm/lib/libclang.dylib \
"$DEST/bin/irony-server"
# Cleanup
popd
rm -rf irony-mode
rtags
Code navigation requires an rtags server (rdm
) installed. This should be
available through your OS's package manager.
This module will auto-start rdm
when you open C/C++ buffers (so long as one
isn't already running). If you prefer to run it yourself:
rdm &
rc -J $PROJECT_ROOT # loads PROJECT_ROOT's compile_commands.json
Configure
Project compile settings
By default, a set of default compile settings are defined in
+cc-default-compiler-options
for C, C++ and Objective C. Irony, rtags and
flycheck will fall back to these. This variable does nothing for LSP users.
For a more universal solution: both LSP servers and irony will recognize a
compilation database (a compile_commands.json
file). There are many ways to
generate one. Here is an example using CMake and bear:
# For CMake projects
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .
# For non-CMake projects
make clean
bear make
Use M-x +cc/reload-compile-db
to reload your compile db in an already-open
C/C++/ObjC buffer.
Known issues with bear on macOS
MacOS' System Integrity Protection (SIP) might interfere with bear if make
is
under /usr/bin/
which results in an empty compilation database.
From the bear readme:
Security extension/modes on different operating systems might disable library preloads. This case Bear behaves normally, but the result compilation database will be empty. (Please make sure it's not the case when reporting bugs.) Notable examples for enabled security modes are: OS X 10.11 (check with csrutil status | grep 'System Integrity Protection'), and Fedora, CentOS, RHEL (check with sestatus | grep 'SELinux status').
Workaround could be to disable the security feature while running Bear. (This might involve reboot of your computer, so might be heavy workaround.) Another option if the build tool is not installed under certain directories. Or use tools which are using compiler wrappers. (It injects a fake compiler which does record the compiler invocation and calls the real compiler too.) An example for such tool might be scan-build. The build system shall respect CC and CXX environment variables.
A workaround might be to install make
via Homebrew which puts gmake
under /usr/local/
.
brew install make
make clean
bear gmake
Additional info:
Configure LSP servers
Search for your combination of (LSP client package, LSP server)
. You are using
LSP-mode
by default, eglot
if you have :tools (lsp +eglot)
active in your
init.el
file.
LSP-mode with clangd
(setq lsp-clients-clangd-args '("-j=3"
"--background-index"
"--clang-tidy"
"--completion-style=detailed"
"--header-insertion=never"))
(after! lsp-clangd (set-lsp-priority! 'clangd 2))
This will both set your clangd flags and choose clangd
as the default LSP server everywhere clangd can be used.
LSP-mode with ccls
(after! ccls
(setq ccls-initialization-options '(:index (:comments 2) :completion (:detailedLabel t)))
(set-lsp-priority! 'ccls 2)) ; optional as ccls is the default in Doom
This will both set your ccls flags and choose ccls as the default server. CCLS
documentation lists available options, use t
for true
, :json-false
for
false
, and :json-null
for null
.
Eglot with clangd
(set-eglot-client! 'cc-mode '("clangd" "-j=3" "--clang-tidy"))
This will both set your clangd flags and choose clangd as the default server (if
it is the last set-eglot-client! 'cc-mode
in your config).
Eglot with ccls
(set-eglot-client! 'cc-mode '("ccls" "--init={\"index\": {\"threads\": 3}}"))
This will both set your ccls flags and choose ccls as the default server (if it
is the last set-eglot-client! 'cc-mode
in your config). CCLS documentation
lists available options
Appendix
Eglot specific bindings
When using +lsp
and :tools (lsp +eglot)
, lsp-mode is replaced with eglot,
and an additional function to get inheritance type hierarchy is added
Binding | Description |
---|---|
<localleader> c t |
Display inheritance type hierarchy (upwards) |
<prefix> <localleader> c t |
Display inheritance type hierarchy (downwards) |