(Emacs/config)~Rework clang-format a bit

Use before-save-hook rather than after-save-hook, which solves the
double save issue.
This commit is contained in:
2024-06-25 12:56:12 +01:00
parent 0beb166d47
commit 14d3f58928

View File

@@ -3175,10 +3175,13 @@ Tons of stuff, namely:
(statement-cont . +))))) (statement-cont . +)))))
#+end_src #+end_src
*** Clang format *** Clang format
Clang format comes inbuilt with clang, so download that before using clang-format is a program that formats C/C++ files. It's highly
this. Formats C/C++ files depending on a format (checkout the Clang configurable and quite fast. I have a root configuration in my
format [[file:~/Dotfiles/ClangFormat/.clang-format][config file]] in Dotfiles (check it out
my dotfiles). [[file:~/Dotfiles/ClangFormat/).clang-format][here]].
Clang format comes inbuilt with clang/LLVM, so it's quite likely to be
on your machine.
#+begin_src emacs-lisp #+begin_src emacs-lisp
(use-package clang-format (use-package clang-format
@@ -3198,8 +3201,8 @@ my dotfiles).
(let ((save-func (proc (interactive) (let ((save-func (proc (interactive)
(clang-format-buffer)))) (clang-format-buffer))))
(if clang-format-mode (if clang-format-mode
(add-hook 'after-save-hook save-func nil t) (add-hook 'before-save-hook save-func nil t)
(remove-hook 'after-save-hook save-func t)))) (remove-hook 'before-save-hook save-func t))))
(defun +code/clang-format-region-or-buffer () (defun +code/clang-format-region-or-buffer ()
(interactive) (interactive)
(if (mark) (if (mark)