]> git.armaanb.net Git - config.org.git/commitdiff
Add c-mode settings
authorArmaan Bhojwani <me@armaanb.net>
Fri, 11 Jun 2021 16:46:37 +0000 (12:46 -0400)
committerArmaan Bhojwani <me@armaanb.net>
Fri, 11 Jun 2021 16:46:37 +0000 (12:46 -0400)
config.org

index 691d8d8153973c42b9c2ec4f7e2bce4f6c13e1c1..1592d2dd5bcf5df1a9d07161d72b6a29c9437a58 100644 (file)
@@ -606,13 +606,28 @@ A very good Git interface.
     :straight (git-email :repo "https://git.sr.ht/~yoctocell/git-email")
     :config (git-email-piem-mode))
 #+end_src
-* General text editing
-** Indentation
-Automatically indent after every change. I'm not sure how much I like this. It slows down the editor and code sometimes ends up in a half-indented state meaning I have to manually reformat using "==" anyways.
-#+begin_src emacs-lisp
-  (use-package aggressive-indent
-    :config (global-aggressive-indent-mode))
+** C
+Modified from https://eklitzke.org/smarter-emacs-clang-format.
+
+Style is basically ddevault's style guide but with 4 spaces instead of 8 char tabs.
+#+begin_src emacs-lisp
+  (use-package clang-format
+    :custom (clang-format-style "{
+        BasedOnStyle: llvm,
+        AlwaysBreakAfterReturnType: AllDefinitions,
+        IndentWidth: 4,
+        }"))
+
+  (defun clang-format-buffer-smart ()
+    "Reformat buffer if .clang-format exists in the projectile root."
+    (when (file-exists-p (expand-file-name ".clang-format" (projectile-project-root)))
+      (when (if (eq major-mode 'c-mode))
+        (message "Formatting with clang-format...")
+        (clang-format-buffer))))
+
+  (add-hook 'before-save-hook 'clang-format-buffer-smart nil)
 #+end_src
+* General text editing
 ** Spell checking
 Spell check in text mode, and in prog-mode comments.
 #+begin_src emacs-lisp