;;; +apheleia.el -*- lexical-binding: t; -*- ;;; Code: (require 'apheleia) (require 'cl-lib) ;; 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))) ;;; `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