For C++ I mainly use CLion but sometimes, especially when using a laptop I want something simpler.
So I tried to setup and configure Doom Emacs.
My needs:
- Vim mode
- LSP support
- Interactive debugger
- Install Doom Emacs (see prerequirements)
- In
init.el
under:tools
use(debugger +lsp)
and under:lang
set(cc +lsp)
- In
config.el
add(require 'dap-cpptools)
That’s all for the emacs configuration. Now let’s configure C++ project for auto-completion, reference findings, etc.
- Generate
compile_commands.json
1.1set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
for CMake
2.2 or by using Bear - Add project by pressing SPC-p-a, open it by SPC-p-p, select file
There should be a message under modeline in minibuffer:
LSP :: Connected to [clangd:56087/starting].
LSP :: clangd:56087 initialized successfully in folders: (/home/max/src/scarecrow2d)
- Run
M-x dap-cpptools-setup
needed only once (That’s because I’m using vscode-cpptools, but there are other options listed here) - Setup debug configuration
4.1M-x dap-edit-debug-template
, here is template for my project
(dap-register-debug-template
"cpptools::Run Configuration"
(list :type "cppdbg"
:request "launch"
:name "cpptools::Run Configuration"
:MIMode "gdb"
:program "${workspaceFolder}/build/sc2d_client/sc2d_client"
:cwd "${workspaceFolder}/build/"))
4.2 Eval buffer with M-x eval-buffer
5. Open debugger M-x SPC-o-d
Things to discover
- dap-hydra
- add binds for debugging
- save debug-template in separate
.el
file - resize debug windows
- setup build commands / cmake