doomemacs/modules/lang/cc
Henrik Lissner 2e86cceb3f
Bump :lang
200ok-ch/counsel-jq@104c77b -> 200ok-ch/counsel-jq@f5bfed8
Andersbakken/rtags@e6c7005 -> Andersbakken/rtags@63a7d9b
FStarLang/fstar-mode.el@5670fc0 -> FStarLang/fstar-mode.el@3afbf04
Kungsgeten/org-brain@6e3d861) -> Kungsgeten/org-brain@1ae4fd4)
NixOS/nix-mode@bb0b49e -> NixOS/nix-mode@e32c6bf
OVYA/php-cs-fixer@95eace9 -> OVYA/php-cs-fixer@c5b5d8a
ProofGeneral/PG@0fdb1ae -> ProofGeneral/PG@702f5b9
Sarcasm/irony-mode@1e1aaba -> Sarcasm/irony-mode@76fd37f
abicky/nodejs-repl.el@f5ce3d5 -> abicky/nodejs-repl.el@3b84105
agda/agda@08191e6 -> agda/agda@5070bd8
amake/flutter.el@78b3c57 -> amake/flutter.el@696228a
ananthakumaran/tide@ac5f070 -> ananthakumaran/tide@a43a37b
arnested/php-extras@81ebd7c -> arnested/php-extras@d410c5a
borkdude/flycheck-clj-kondo@152df7f -> borkdude/flycheck-clj-kondo@a558bda
brotzeit/rustic@7c9d55b -> brotzeit/rustic@91ad5db
chachi/cuda-mode@9ae9eac -> chachi/cuda-mode@7f59351
clojure-emacs/cider@f1c2a79 -> clojure-emacs/cider@ef47c1d
clojure-emacs/clojure-mode@75c2889 -> clojure-emacs/clojure-mode@53ef8ac
cpitclaudel/company-coq@b096cb5 -> cpitclaudel/company-coq@4da7b41
cython/cython@ba6cbed -> cython/cython@21b4e53
dgutov/robe@082da38 -> dgutov/robe@f04dcc7
dominikh/go-mode.el@d17d210 -> dominikh/go-mode.el@fdf46fe
dominikh/go-mode.el@d17d210 -> dominikh/go-mode.el@fdf46fe
elixir-editors/emacs-elixir@01b3324 -> elixir-editors/emacs-elixir@b78e7f7
emacs-ess/ESS@a694b26 -> emacs-ess/ESS@d013616
emacs-lsp/lsp-dart@c1ff5ce -> emacs-lsp/lsp-dart@b81b1ec
emacs-lsp/lsp-java@3f1ed17 -> emacs-lsp/lsp-java@f43b00a
emacs-lsp/lsp-metals@e42c0b2) -> emacs-lsp/lsp-metals@31dafff)
emacs-lsp/lsp-pyright@ccd0007 -> emacs-lsp/lsp-pyright@d9e7d3c
emacs-lsp/lsp-python-ms@a0c56f4 -> emacs-lsp/lsp-python-ms@c4ebc7a
emacs-php/php-mode@f4c7c69 -> emacs-php/php-mode@7e5722c
emacs-straight/adaptive-wrap@319db64 -> emacs-straight/adaptive-wrap@8f60ee7
emacs-straight/csv-mode@6353374 -> emacs-straight/csv-mode@eb3ec00
emacs-straight/org-mode@a88806b -> emacs-straight/org-mode@7c8dce7
emacs-straight/rainbow-mode@fdff98b -> emacs-straight/rainbow-mode@949166c
emacs-straight/sml-mode@60b01d7 -> emacs-straight/sml-mode@0338e97
emacs-typescript/typescript.el@e6f68ab -> emacs-typescript/typescript.el@54f14c4
erlang/otp@8efb945 -> erlang/otp@8fc0641
factor/factor@c6e15bd -> factor/factor@94a922a
felipeochoa/rjsx-mode@0061587 -> felipeochoa/rjsx-mode@b697fe4
fsharp/emacs-fsharp-mode@68dfc22 -> fsharp/emacs-fsharp-mode@13fbf4c
fxbois/web-mode@b4b0a85 -> fxbois/web-mode@890e837
galaunay/poetry.el@eb238d9 -> galaunay/poetry.el@d5163fe
godotengine/emacs-gdscript-mode@55a6637 -> godotengine/emacs-gdscript-mode@75fe658
greghendershott/racket-mode@0ca8b26 -> greghendershott/racket-mode@3563081
haskell/haskell-mode@e726776 -> haskell/haskell-mode@0d39c84
hlissner/evil-org-mode@658dadf) -> hlissner/evil-org-mode@a9706da)
hvesalai/emacs-sbt-mode@4358ed8 -> hvesalai/emacs-sbt-mode@7b121fc
hvesalai/emacs-scala-mode@1d08e88 -> hvesalai/emacs-scala-mode@9d3b56e
hylang/hy-mode@7256844 -> hylang/hy-mode@5253533
joaotavora/sly@fce4f9b -> joaotavora/sly@68561f1
jorgenschaefer/emacs-buttercup@cccdedf -> jorgenschaefer/emacs-buttercup@2f24a44
jorgenschaefer/pyvenv@861998b -> jorgenschaefer/pyvenv@0bf4b87
josteink/csharp-mode@f46d656 -> josteink/csharp-mode@4916829
jrblevin/markdown-mode@152eae2 -> jrblevin/markdown-mode@dcad557
kaushalmodi/ox-hugo@1909c6e) -> kaushalmodi/ox-hugo@f24c9bd)
nim-lang/nim-mode@16a245e -> nim-lang/nim-mode@d832d6b
ocaml-ppx/ocamlformat@1dec6c3 -> ocaml-ppx/ocamlformat@860266b
ocaml/dune@f967df6 -> ocaml/dune@4d097cd
ocaml/merlin@06833e9 -> ocaml/merlin@28193d5
oer/org-re-reveal@2035217 -> oer/org-re-reveal@0062756
org-roam/org-roam@d913447) -> org-roam/org-roam@be95b42)
rexim/org-cliplink@82402ca -> rexim/org-cliplink@13e0940
salmanebah/opencl-mode@55cb49c -> salmanebah/opencl-mode@15091ef
senny/rvm.el@6897576) -> senny/rvm.el@b2498a4)
skuro/plantuml-mode@5889166 -> skuro/plantuml-mode@ea45a13
swift-emacs/swift-mode@e65a80a -> swift-emacs/swift-mode@0bc8d8d
technomancy/fennel-mode@7a8824a -> technomancy/fennel-mode@fa56106
wbolster/emacs-python-pytest@a2f88b1 -> wbolster/emacs-python-pytest@4a1c4c8
xuchunyang/elisp-demos@3cca496 -> xuchunyang/elisp-demos@ed9578d
yoshiki/yaml-mode@68fecb5 -> yoshiki/yaml-mode@fc5e1c5

Fixes #4237
2020-12-05 16:37:59 -05:00
..
autoload.el Add lookup-documentation handler for cmake-mode 2020-11-17 12:46:10 -05:00
config.el Extract CPU counting to doom-num-cpus function 2020-11-29 14:49:14 -05: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 2020-12-05 16:37:59 -05:00
README.org Adding doc update for cmake-language-server 2020-11-18 06:25:36 +01: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.

  • Debian/Ubuntu: sudo apt-get install clangd-9
  • macOS: brew install llvm
  • Windows: install from LLVM download page
  • clangd is available on some Linux distros from a clang-tools package, if you'd like to avoid the full llvm.
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, 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  # 1gb+ installation! May take a while!

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

Arch Linux

pacman -S clang cmake

openSUSE

sudo zypper install clang cmake

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)