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.el51
1 files changed, 49 insertions, 2 deletions
diff --git a/lisp/+apheleia.el b/lisp/+apheleia.el index 469232a..df651b8 100644 --- a/lisp/+apheleia.el +++ b/lisp/+apheleia.el
@@ -2,14 +2,61 @@
2 2
3;;; Code: 3;;; Code:
4 4
5(require 'apheleia)
6(require 'cl-lib)
7
5;; https://github.com/raxod502/apheleia/pull/63#issue-1077529623 8;; https://github.com/raxod502/apheleia/pull/63#issue-1077529623
6(defun +apheleia-indent-region (orig scratch callback _error) 9(cl-defun +apheleia-indent-region (&key buffer scratch formatter callback &allow-other-keys)
7 (with-current-buffer scratch 10 (with-current-buffer scratch
8 (setq-local indent-line-function 11 (setq-local indent-line-function
9 (buffer-local-value 'indent-line-function orig)) 12 (buffer-local-value 'indent-line-function buffer))
10 (indent-region (point-min) 13 (indent-region (point-min)
11 (point-max)) 14 (point-max))
12 (funcall callback))) 15 (funcall callback)))
13 16
17
18;;; `setup' integration
19
20(require 'setup)
21
22(setup-define :apheleia
23 (lambda (name formatter &optional mode -pend)
24 (let* ((mode (or mode (setup-get 'mode)))
25 (current-formatters (and -pend
26 (alist-get mode apheleia-formatters))))
27 `(progn
28 (setf (alist-get ',name apheleia-formatters)
29 ,formatter)
30 (setf (alist-get ',mode apheleia-mode-alist)
31 ',(pcase -pend
32 (:append (append (ensure-list current-formatters)
33 (list name)))
34 (:prepend (cons name (ensure-list current-formatters)))
35 ('nil name)
36 (_ (error "Improper `:apheleia' -PEND argument")))))))
37 :documentation
38 "Register a formatter to `apheleia''s lists.
39NAME is the name given to the formatter in `apheleia-formatters'
40and `apheleia-mode-alist'. FORMATTER is the command paired with
41NAME in `apheleia-formatters'. MODE is the mode or modes to add
42NAME to in `apheleia-mode-alist'. If MODE is not given or nil,
43use the setup form's MODE. Optional argument -PEND can be one of
44`:append' or `:prepend', and if given will append or prepend the
45given NAME to the current formatters for the MODE in
46`apheleia-mode-alist', rather than replace them (the default).
47
48Example:
49(setup
50 (:apheleia isort (\"isort\" \"--stdout\" \"-\")
51 python-mode))
52; =>
53(progn
54 (setf (alist-get 'isort apheleia-formatters)
55 '(\"isort\" \"--stdout\" \"-\"))
56 (setf (alist-get 'python-mode apheleia-mode-alist)
57 'isort))
58
59This form cannot be repeated, and it cannot be used as HEAD.")
60
14(provide '+apheleia) 61(provide '+apheleia)
15;;; +apheleia.el ends here 62;;; +apheleia.el ends here