diff --git a/modules/lang/cc/config.el b/modules/lang/cc/config.el index 221d7b165..b2cc3739c 100644 --- a/modules/lang/cc/config.el +++ b/modules/lang/cc/config.el @@ -48,6 +48,18 @@ 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 ?\} ?\{)) + (when (executable-find "clang-format") + (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"))) diff --git a/modules/lang/cc/doctor.el b/modules/lang/cc/doctor.el index f9d2ee687..21c4bba08 100644 --- a/modules/lang/cc/doctor.el +++ b/modules/lang/cc/doctor.el @@ -26,3 +26,7 @@ ;; glslangValidator (unless (executable-find "glslangValidator") (warn! "Couldn't find glslangValidator. GLSL code completion is disabled"))) + +(when (modulep! :editor format) + (unless (executable-find "clang-format") + (warn! "Couldn't find clang-format. Formatting will be disabled.")))