aboutsummaryrefslogtreecommitdiff
path: root/Emacs/.config/emacs/config.org
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2022-09-14 00:34:20 +0100
committerAryadev Chavali <aryadev@aryadevchavali.com>2022-09-14 00:47:16 +0100
commit4767422b39daeaf2a155192520f94f49a12071af (patch)
tree37a728a462c62420ba342ca40f742f74621d767b /Emacs/.config/emacs/config.org
parent6bb587d877268210ae0bfec79e32996292ac5b4f (diff)
downloaddotfiles-4767422b39daeaf2a155192520f94f49a12071af.tar.gz
dotfiles-4767422b39daeaf2a155192520f94f49a12071af.tar.bz2
dotfiles-4767422b39daeaf2a155192520f94f49a12071af.zip
(Emacs)+auto-save for C/C++ to clang-format buffer
Nicer to do this and have a formatted file to commit on git than commit a non-formatted file and realise after a push.
Diffstat (limited to 'Emacs/.config/emacs/config.org')
-rw-r--r--Emacs/.config/emacs/config.org17
1 files changed, 12 insertions, 5 deletions
diff --git a/Emacs/.config/emacs/config.org b/Emacs/.config/emacs/config.org
index c1ed907..a35f9cb 100644
--- a/Emacs/.config/emacs/config.org
+++ b/Emacs/.config/emacs/config.org
@@ -2576,16 +2576,23 @@ format [[file:~/Dotfiles/ClangFormat/.clang-format][config file]] in my dotfiles
:straight nil
:load-path "/usr/share/clang/"
:after cc-mode
- :commands +code/clang-format-region-or-buffer
+ :commands (+code/clang-format-region-or-buffer)
:general
(leader
:keymaps '(c-mode-map c++-mode-map)
"cf" #'+code/clang-format-region-or-buffer)
:config
- (add-hook 'after-save-hook (proc (interactive)
- (if (or (eq major-mode 'c-mode)
- (eq major-mode 'c++-mode))
- (clang-format-buffer))))
+ (defvar +code/clang-format-automatically t
+ "Automatically call clang-format every time save occurs in C/C++
+buffer")
+
+ (+dx/create-auto-save
+ +code/clang-format-on-save
+ (and +code/clang-format-automatically
+ (or (eq major-mode 'c-mode)
+ (eq major-mode 'c++-mode)))
+ (clang-format-buffer))
+
(defun +code/clang-format-region-or-buffer ()
(interactive)
(if (mark)