refactor(cc): configure clang-format in :editor format

These should be upstreamed.
This commit is contained in:
Henrik Lissner
2025-04-09 18:19:19 -04:00
parent 9a525ea030
commit ae2cdd1c91
2 changed files with 6 additions and 11 deletions

View File

@ -79,6 +79,12 @@ This is controlled by `+format-on-save-disabled-modes'."
;; `+format-with-lsp-mode' in the appropriate modes.
(add-to-list 'apheleia-formatters '(lsp . +format-lsp-buffer))
;; Use clang-format for cuda and protobuf files.
(add-to-list 'apheleia-mode-alist '(cuda-mode . clang-format))
(add-to-list 'apheleia-mode-alist '(protobuf-mode . clang-format))
(add-to-list 'apheleia-formatters-mode-extension-assoc '(cuda-mode . ".cu"))
(add-to-list 'apheleia-formatters-mode-extension-assoc '(protobuf-mode . ".proto"))
;; Apheleia's default clang-format config doesn't respect `c-basic-offset', so
;; force it to in the absence of a .clang-format file.
(setf (alist-get 'clang-format apheleia-formatters)

View File

@ -32,17 +32,6 @@ This is ignored by ccls.")
(set-docsets! 'c-mode "C")
(set-docsets! 'c++-mode "C++" "Boost")
(set-electric! '(c-mode c++-mode objc-mode java-mode) :chars '(?\n ?\} ?\{))
(set-formatter!
'clang-format
'("clang-format"
"-assume-filename"
(or (buffer-file-name)
(cdr (assoc major-mode
'((c-mode . ".c")
(c++-mode . ".cpp")
(cuda-mode . ".cu")
(protobuf-mode . ".proto"))))))
:modes '(c-mode c++-mode protobuf-mode cuda-mode))
(set-rotate-patterns! 'c++-mode
:symbols '(("public" "protected" "private")
("class" "struct")))