From af3eb37c8e51084261f2ad4bfe1d36fffbcfaebf Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 8 Jun 2022 17:59:53 -0500 Subject: blep --- lisp/+apheleia.el | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) (limited to 'lisp/+apheleia.el') 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 @@ ;;; Code: +(require 'apheleia) +(require 'cl-lib) + ;; https://github.com/raxod502/apheleia/pull/63#issue-1077529623 -(defun +apheleia-indent-region (orig scratch callback _error) +(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 orig)) + (buffer-local-value 'indent-line-function buffer)) (indent-region (point-min) (point-max)) (funcall callback))) + +;;; `setup' integration + +(require 'setup) + +(setup-define :apheleia + (lambda (name formatter &optional mode -pend) + (let* ((mode (or mode (setup-get 'mode))) + (current-formatters (and -pend + (alist-get mode apheleia-formatters)))) + `(progn + (setf (alist-get ',name apheleia-formatters) + ,formatter) + (setf (alist-get ',mode apheleia-mode-alist) + ',(pcase -pend + (:append (append (ensure-list current-formatters) + (list name))) + (:prepend (cons name (ensure-list current-formatters))) + ('nil name) + (_ (error "Improper `:apheleia' -PEND argument"))))))) + :documentation + "Register a formatter to `apheleia''s lists. +NAME is the name given to the formatter in `apheleia-formatters' +and `apheleia-mode-alist'. FORMATTER is the command paired with +NAME in `apheleia-formatters'. MODE is the mode or modes to add +NAME to in `apheleia-mode-alist'. If MODE is not given or nil, +use the setup form's MODE. Optional argument -PEND can be one of +`:append' or `:prepend', and if given will append or prepend the +given NAME to the current formatters for the MODE in +`apheleia-mode-alist', rather than replace them (the default). + +Example: +(setup + (:apheleia isort (\"isort\" \"--stdout\" \"-\") + python-mode)) +; => +(progn + (setf (alist-get 'isort apheleia-formatters) + '(\"isort\" \"--stdout\" \"-\")) + (setf (alist-get 'python-mode apheleia-mode-alist) + 'isort)) + +This form cannot be repeated, and it cannot be used as HEAD.") + (provide '+apheleia) ;;; +apheleia.el ends here -- cgit 1.4.1-21-gabe81