Files
serenity/Documentation/EmacsConfiguration.md
kleines Filmröllchen 9ae2dd5596 Documentation: Consolidate and extend clangd configuration docs
These were previously spread over multiple editor documentation files,
so we consolidate them into one while dropping outdated (or unexplained)
options. A new ClangdConfiguration file is created that will house the
common config.

Furthermore, since clangd 20 supports the header style options
(implemented by yours truly), document that this feature is now
available and what AngledHeaders globs to use for Serenity specifically.
2025-03-12 17:37:37 -04:00

1.7 KiB

Emacs Project Configuration

Emacs can be configured with lsp-mode and clangd to work well.

clangd

The official clangd extension can be used for C++ comprehension. Refer to ClangdConfiguration for how to configure clangd.

There are a few different ways to specify which clangd to use:

  • By default, without configuration lsp-mode will try to find and use your system clangd. This is the easiest solution, but your system clangd might be out of date.
  • You can manually specify any clangd binary with lsp-clangd-binary-path.
  • You can have lsp-mode manage your clangd installation with emacs' lsp-install-server. This will install a clangd binary for you.

lsp-mode

(use-package lsp-mode
  :hook ((c++-mode) . lsp-deferred)
  :commands lsp
  :config
  ;; clangd arguments, refer to ClangdConfiguration.md for what other arguments may be needed.
  (setq lsp-clients-clangd-args '("-j=4" "-background-index" "--log=error" "--clang-tidy" "--enable-config"))
  ;; Optionally, set the location of clangd -- See above for options.
  (setq lsp-clangd-binary-path "/usr/bin/clangd"))

clang-format

There are multiple packages to handle auto formatting with clang-format, within emacs. Choose what works best for your setup:

Alternatively, this can be done without additional packages, using lsp-mode. You can use the following .dir-locals.el file placed in the project root:

((c++-mode
  (eval add-hook 'before-save-hook #'lsp-format-buffer nil t)))