doomemacs/modules/lang/cc
Henrik Lissner 09cb4f6716
Major refactor & optimization of how modules load their packages
Now that we are loading package autoloads files (as part of the
generated doom-package-autoload-file when running make autoloads), many
:commands properties are redundant. In fact, many def-package! blocks
are redundant.

In some cases, we can do without a config.el file entirely, and can move
into the autoloads file or rely entirely on package autoloads.

Also, many settings have been moved in their module's autoloads files,
which makes them available ASAP; their use no longer depends on module
load order.

This gained me a modest ~10% boost in startup speed.
2018-05-25 00:46:16 +02:00
..
autoload.el Major refactor & optimization of how modules load their packages 2018-05-25 00:46:16 +02:00
config.el Major refactor & optimization of how modules load their packages 2018-05-25 00:46:16 +02:00
doctor.el Major refactor & optimization of how modules load their packages 2018-05-25 00:46:16 +02:00
packages.el lang/cc: refactor (nest configs and chain packages) 2018-05-16 00:16:13 +02:00
README.org lang/cc: rename +cc-{include-paths,compiler-options} #305 2017-12-27 17:10:28 -05:00

:lang cc

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.

C contends with Haskell and Ruby for my favorite language. That said, it's more accurate to say I write C, but a C++ feature or three.

The module provides nominal support for Objective-C, which I really only use to inspect generated glue code for iOS mobile apps. Otherwise, I prefer Swift.

Table of Contents   TOC

Install

This module requires:

  • irony-server
  • rtags

irony-server

Irony powers the code completion, eldoc and syntax checking systems.

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/$(hostname)/etc/irony-server/"
cmake -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

sudo pacman --needed --noconfirm -S clang cmake

Then run M-x irony-install-server in Emacs.

rtags

Code navigation requires an rtags server (rdm) installed and running. 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). If you prefer to run it yourself, outside of Emacs:

rdm &
rc -J $PROJECT_ROOT  # loads PROJECT_ROOT's compile_commands.json

Configure

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.

To make these tools aware of project specific build settings, you need a JSON compilation database present (i.e. a compile_commands.json file).

There are many ways to generate one. I use 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.