summary refs log tree commit diff stats
path: root/lisp/+apheleia.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/+apheleia.el')
-rw-r--r--lisp/+apheleia.el23
1 files changed, 21 insertions, 2 deletions
diff --git a/lisp/+apheleia.el b/lisp/+apheleia.el index 3428a72..51cf145 100644 --- a/lisp/+apheleia.el +++ b/lisp/+apheleia.el
@@ -3,6 +3,7 @@
3;;; Code: 3;;; Code:
4 4
5(require 'cl-lib) 5(require 'cl-lib)
6(require 'el-patch)
6(require 'user-save) 7(require 'user-save)
7 8
8;; https://github.com/raxod502/apheleia/pull/63#issue-1077529623 9;; https://github.com/raxod502/apheleia/pull/63#issue-1077529623
@@ -14,13 +15,31 @@
14 (point-max)) 15 (point-max))
15 (funcall callback))) 16 (funcall callback)))
16 17
18;;; Why does the original function have to check for `apheleia-mode' ?
19(el-patch-defun apheleia--format-after-save ()
20 "Run code formatter for current buffer if any configured, then save."
21 (unless apheleia--format-after-save-in-progress
22 (when (el-patch-swap apheleia-mode
23 (or apheleia-mode
24 +apheleia/user-save-mode))
25 (when-let ((formatters (apheleia--get-formatters)))
26 (apheleia-format-buffer
27 formatters
28 (lambda ()
29 (with-demoted-errors "Apheleia: %s"
30 (when buffer-file-name
31 (let ((apheleia--format-after-save-in-progress t))
32 (apheleia--save-buffer-silently)))
33 (run-hooks 'apheleia-post-format-hook))))))))
34
35
17(define-minor-mode +apheleia/user-save-mode 36(define-minor-mode +apheleia/user-save-mode
18 "Minor mode for reformatting code on `user-save'. 37 "Minor mode for reformatting code on `user-save'.
19Customize with `apheleia-mode-alist' and `apheleia-formatters'." 38Customize with `apheleia-mode-alist' and `apheleia-formatters'."
20 :lighter " Apheleia/US" 39 :lighter " Apheleia/US"
21 (if +apheleia/user-save-mode 40 (if +apheleia/user-save-mode
22 (add-hook 'user-save-hook #'apheleia--format-after-save nil 'local) 41 (add-hook 'user-save-after-save-hook #'apheleia--format-after-save nil 'local)
23 (remove-hook 'user-save-hook #'apheleia--format-after-save 'local))) 42 (remove-hook 'user-save-after-save-hook #'apheleia--format-after-save 'local)))
24 43
25(define-globalized-minor-mode +apheleia/user-save-global-mode 44(define-globalized-minor-mode +apheleia/user-save-global-mode
26 +apheleia/user-save-mode +apheleia/user-save-mode) 45 +apheleia/user-save-mode +apheleia/user-save-mode)