Doom emacs for C++

2023/01/17

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:

  1. Install Doom Emacs (see prerequirements)
  2. In init.el under :tools use (debugger +lsp) and under :lang set (cc +lsp)
  3. 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.

  1. Generate compile_commands.json
    1.1 set(CMAKE_EXPORT_COMPILE_COMMANDS ON) for CMake
    2.2 or by using Bear
  2. 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)
  1. Run M-x dap-cpptools-setup needed only once (That’s because I’m using vscode-cpptools, but there are other options listed here)
  2. Setup debug configuration
    4.1 M-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