Last active
June 17, 2019 20:57
-
-
Save mlabbe/25d0a917516270d81d0a8b7817b0847a to your computer and use it in GitHub Desktop.
Run clang-format only when projects have a .clang-format in their root, while deferring the load of all packages with use-package
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use-package cc-mode | |
:defer t | |
:init | |
(add-hook 'before-save-hook #'clang-format-buffer-smart) | |
:config | |
(progn | |
(defun clang-format-buffer-smart() | |
"Reformat buffer only if .clang-format exists in the projectile root." | |
(when (file-exists-p (expand-file-name ".clang-format" (projectile-project-root))) | |
(clang-format-buffer))) | |
) | |
:bind (:map c-mode-base-map | |
("C-c u" . clang-format-buffer)) | |
) | |
(use-package clang-format | |
:ensure t | |
:after cc-mode | |
:config | |
(setq clang-format-style-option "file") | |
:commands clang-format clang-format-buffer clang-format-region) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment