doomemacs/modules/lang/cc
Henrik Lissner 9ef5ca2922 bump: :lang
Andersbakken/rtags@65113e2a13 -> Andersbakken/rtags@cdff9b47fc
Emacs-Kotlin-Mode-Maintainers/kotlin-mode@0e4bafb31d -> Emacs-Kotlin-Mode-Maintainers/kotlin-mode@876cc27dc1
Groovy-Emacs-Modes/groovy-emacs-modes@99eaf70720 -> Groovy-Emacs-Modes/groovy-emacs-modes@84f89b68ec
JuliaEditorSupport/julia-emacs@fe6f6f7a80 -> JuliaEditorSupport/julia-emacs@06f6fdb94c
NixOS/nix-mode@3cca5b6527 -> NixOS/nix-mode@8e20de5ba7
OVYA/php-cs-fixer@c5b5d8a498 -> OVYA/php-cs-fixer@cc9a3624dc
ProofGeneral/PG@bc86736abb -> ProofGeneral/PG@e2b4227e1f
Raku/raku-mode@7496ad3a03 -> Raku/raku-mode@eaac071f17
Somelauw/evil-markdown@064fe9b476 -> Somelauw/evil-markdown@8e6cc68af8
StanfordLegion/terra-mode@eab9e59ded -> StanfordLegion/terra-mode@ceef8cae5b
amake/flutter.el@960b63576a -> amake/flutter.el@81c524a43c
ananthakumaran/tide@ccff099e94 -> ananthakumaran/tide@296c0e0e3a
asok/projectile-rails@6a18ada356 -> asok/projectile-rails@30828afbfa
beancount/beancount-mode@02fe03ee44 -> beancount/beancount-mode@dbafe6a73d
bradyt/dart-mode@43975c9208 -> bradyt/dart-mode@3bac14200f
brianc/jade-mode@4dbde92542 -> brianc/jade-mode@111460b056
brotzeit/rustic@6ca73bb3cc -> brotzeit/rustic@804ebfe029
cdominik/cdlatex@614a8d94f6 -> cdominik/cdlatex@f215b70c5c
clojure-emacs/clojure-mode@3e426b3a47 -> clojure-emacs/clojure-mode@e1dc7caee7
cython/cython@fae33cf7d4 -> cython/cython@aea4e6b84b
dgutov/robe@e1304d123d -> dgutov/robe@fd972e912d
emacs-csharp/csharp-mode@093f0f21a9 -> emacs-csharp/csharp-mode@fe8a68e984
emacs-ess/ESS@4fefd0feaa -> emacs-ess/ESS@a7ce81bb76
emacs-geiser/gauche@66e51430bd -> emacs-geiser/gauche@fd52cbaed9
emacs-geiser/geiser@4099dce8f5 -> emacs-geiser/geiser@327ff01e5b
emacs-lsp/lsp-metals@ca927e5a83 -> emacs-lsp/lsp-metals@695291761b
emacs-php/php-mode@cbf2723264 -> emacs-php/php-mode@535aec8173
emacs-straight/auctex@ea410dce4f -> emacs-straight/auctex@3b0a080ae5
emacs-typescript/typescript.el@1043025d42 -> emacs-typescript/typescript.el@2a58631230
erlang/otp@645ea8110d -> erlang/otp@118cb37bd5
ethereum/emacs-solidity@5f6ef3156f -> ethereum/emacs-solidity@6f7bd1641e
factor/factor@b989a860d1 -> factor/factor@7b451bb813
fsharp/emacs-fsharp-mode@93b1fbc31d -> fsharp/emacs-fsharp-mode@c90d762c06
fxbois/web-mode@8ef47935d6 -> fxbois/web-mode@61f057a6ba
greghendershott/racket-mode@7f12cb1ff2 -> greghendershott/racket-mode@a879a8d67b
haskell/haskell-mode@98ba392236 -> haskell/haskell-mode@8402caa341
hhvm/hack-mode@f9315be699 -> hhvm/hack-mode@4c1c2b0939
idris-hackers/idris-mode@f52ad0b477 -> idris-hackers/idris-mode@3cc9361b4c
immerrr/lua-mode@2bd9077dd0 -> immerrr/lua-mode@5a9bee8d5f
iyefrat/evil-tex@87445d4d23 -> iyefrat/evil-tex@aa0ddf8e76
jimhourihan/glsl-mode@b071120164 -> jimhourihan/glsl-mode@9b2e5f28e4
joaotavora/sly@41f4d65048 -> joaotavora/sly@540a8c5b9a
jrblevin/markdown-mode@359347b2bb -> jrblevin/markdown-mode@862ae8addd
jwiegley/emacs-async@9a8cd0c3d5 -> jwiegley/emacs-async@5d365ffc6a
liblit/demangle-mode@aaef0bd77a -> liblit/demangle-mode@04f545adab
necaris/conda.el@6db0720b6d -> necaris/conda.el@4de6eccda5
ocaml-ppx/ocamlformat@5dd6574d8f -> ocaml-ppx/ocamlformat@22a3707da3
ocaml/dune@75ecfe3421 -> ocaml/dune@4d0a47edd5
ocaml/merlin@5731826810 -> ocaml/merlin@e4791e2298
ocaml/merlin@5731826810 -> ocaml/merlin@e4791e2298
ocaml/tuareg@b59c422759 -> ocaml/tuareg@00faf47a7c
pashky/restclient.el@2cc1fd3496 -> pashky/restclient.el@176d9cb655
polymode/polymode@7d1f822f08 -> polymode/polymode@54888d6c15
s-kostyaev/go-gen-test@44c202ac97 -> s-kostyaev/go-gen-test@35df36dcd5
seagle0128/grip-mode@c0ca789903 -> seagle0128/grip-mode@1c82e27bee
smihica/emmet-mode@1acb821e01 -> smihica/emmet-mode@6b2e554f7f
swift-emacs/swift-mode@1b47a09f1c -> swift-emacs/swift-mode@800efe2910
technomancy/fennel-mode@a908db8696 -> technomancy/fennel-mode@47152970a9
vspinu/company-math@a796053590 -> vspinu/company-math@45778f5731
yoshiki/yaml-mode@3a57058468 -> yoshiki/yaml-mode@63b637f846
ziglang/zig-mode@0babe7ec52 -> ziglang/zig-mode@aba01b6199
2021-09-15 01:22:33 +02:00
..
autoload.el Add lookup-documentation handler for cmake-mode 2020-11-17 12:46:10 -05:00
config.el refactor: rename orig-fn arg in advice to fn 2021-08-04 01:53:12 -04:00
doctor.el lang/cc: fix false negatives from rc/rdm checks #1864 2019-10-23 16:07:59 -04:00
packages.el bump: :lang 2021-09-15 01:22:33 +02:00
README.org Update suggested clangd flags in lang/cc docs 2021-05-19 21:41:09 +02:00

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.

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
  • You will need a C/C++ compiler, like gcc or clang.

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

    • 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
  • 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"
                                "--header-insertion-decorators=0"))
(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)