diff options
Diffstat (limited to 'lisp/+apheleia.el')
-rw-r--r-- | lisp/+apheleia.el | 50 |
1 files changed, 0 insertions, 50 deletions
diff --git a/lisp/+apheleia.el b/lisp/+apheleia.el deleted file mode 100644 index 51cf145..0000000 --- a/lisp/+apheleia.el +++ /dev/null | |||
@@ -1,50 +0,0 @@ | |||
1 | ;;; +apheleia.el -*- lexical-binding: t; -*- | ||
2 | |||
3 | ;;; Code: | ||
4 | |||
5 | (require 'cl-lib) | ||
6 | (require 'el-patch) | ||
7 | (require 'user-save) | ||
8 | |||
9 | ;; https://github.com/raxod502/apheleia/pull/63#issue-1077529623 | ||
10 | (cl-defun +apheleia-indent-region (&key buffer scratch formatter callback &allow-other-keys) | ||
11 | (with-current-buffer scratch | ||
12 | (setq-local indent-line-function | ||
13 | (buffer-local-value 'indent-line-function buffer)) | ||
14 | (indent-region (point-min) | ||
15 | (point-max)) | ||
16 | (funcall callback))) | ||
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 | |||
36 | (define-minor-mode +apheleia/user-save-mode | ||
37 | "Minor mode for reformatting code on `user-save'. | ||
38 | Customize with `apheleia-mode-alist' and `apheleia-formatters'." | ||
39 | :lighter " Apheleia/US" | ||
40 | (if +apheleia/user-save-mode | ||
41 | (add-hook 'user-save-after-save-hook #'apheleia--format-after-save nil 'local) | ||
42 | (remove-hook 'user-save-after-save-hook #'apheleia--format-after-save 'local))) | ||
43 | |||
44 | (define-globalized-minor-mode +apheleia/user-save-global-mode | ||
45 | +apheleia/user-save-mode +apheleia/user-save-mode) | ||
46 | |||
47 | (put '+apheleia/user-save-mode 'safe-local-variable #'booleanp) | ||
48 | |||
49 | (provide '+apheleia) | ||
50 | ;;; +apheleia.el ends here | ||