The C/C++ configuration (lisp/lang-cc.el) is built to handle complex codebases by deeply integrating with modern tools like clangd and CMake.
- Advanced LSP Intelligence: Powered by
clangdfor highly accurate completions, cross-referencing, and refactoring. - Smart Build System Detection: Automatically locates
compile_commands.jsonin common build directories (e.g.,build/,out/). - Zero-Config CMake Setup: Automatically generates compilation databases for fresh CMake projects.
- Manual Formatting: Binds
clang-formatto a dedicated shortcut.
To enable all features, ensure the following CLI tools are available in your PATH:
# macOS
brew install llvm
# Ubuntu/Debian
sudo apt install clangd clang-formatThe configuration uses clangd for the language server and clang-format for buffer formatting.
Emacs automatically configures the compile-command by searching for Makefile, CMake build directories (build/, out/), or a root CMakeLists.txt.
| Shortcut | Action |
|---|---|
C-c C-c |
Compile the current project or file. |
C-c C-k |
Recompile using the last compilation command. |
C-c C-m |
Configure the current CMake project manually. |
Tip: If a CMakeLists.txt is found but no build directory exists, it will automatically setup the build environment and export compilation commands.
For single-file programs, you can compile and run them quickly:
| Shortcut | Action |
|---|---|
C-c C-r |
Run the current single-file C or C++ binary. |
Maintain a consistent code style across your project:
| Shortcut | Action |
|---|---|
C-c C-f |
Format the current buffer with clang-format. |
Note: Ensure you have a .clang-format file in your project root to define your preferred style rules.
eglot&clangd: We dynamically pass--compile-commands-dirtoclangdwhen a build directory is found, ensuring the language server fully understands your project's include paths and macros.c-ts-mode&c++-ts-mode: We automatically remap standardc-modeandc++-modeto their tree-sitter backed versions if the grammars are installed.- Tree-sitter: Run
M-x install-c/c++-treesit-grammarsto install grammars for both C and C++ for pixel-perfect syntax highlighting.