blob: 3428a723095f6ea2aad91a83cf9c70a813459004 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
;;; +apheleia.el -*- lexical-binding: t; -*-
;;; Code:
(require 'cl-lib)
(require 'user-save)
;; https://github.com/raxod502/apheleia/pull/63#issue-1077529623
(cl-defun +apheleia-indent-region (&key buffer scratch formatter callback &allow-other-keys)
(with-current-buffer scratch
(setq-local indent-line-function
(buffer-local-value 'indent-line-function buffer))
(indent-region (point-min)
(point-max))
(funcall callback)))
(define-minor-mode +apheleia/user-save-mode
"Minor mode for reformatting code on `user-save'.
Customize with `apheleia-mode-alist' and `apheleia-formatters'."
:lighter " Apheleia/US"
(if +apheleia/user-save-mode
(add-hook 'user-save-hook #'apheleia--format-after-save nil 'local)
(remove-hook 'user-save-hook #'apheleia--format-after-save 'local)))
(define-globalized-minor-mode +apheleia/user-save-global-mode
+apheleia/user-save-mode +apheleia/user-save-mode)
(put '+apheleia/user-save-mode 'safe-local-variable #'booleanp)
(provide '+apheleia)
;;; +apheleia.el ends here
|