Function: apheleia--get-formatters
apheleia--get-formatters is a natively compiled function defined in
apheleia-formatters.el.
Signature
(apheleia--get-formatters &optional INTERACTIVE)
Documentation
Return the list of formatters to use for the current buffer.
This is a list of symbols that may appear as cars in
apheleia-formatters, or nil if no formatter is configured for
the current buffer.
Consult the values of apheleia-mode-alist and
apheleia-formatter to determine which formatter is configured.
Consult also apheleia-mode-predicates, if non-nil.
If INTERACTIVE is non-nil, then prompt the user for which
formatter to run if none is configured, instead of returning nil.
If INTERACTIVE is the special symbol prompt, then prompt
even if a formatter is configured.
Source Code
;; Defined in /nix/store/lwcwryzabcmvjcwwzzs65jrwf7p7d7cs-emacs-packages-deps/share/emacs/site-lisp/elpa/apheleia-20260915.1628/apheleia-formatters.el
(defun apheleia--get-formatters (&optional interactive)
"Return the list of formatters to use for the current buffer.
This is a list of symbols that may appear as cars in
`apheleia-formatters', or nil if no formatter is configured for
the current buffer.
Consult the values of `apheleia-mode-alist' and
`apheleia-formatter' to determine which formatter is configured.
Consult also `apheleia-mode-predicates', if non-nil.
If INTERACTIVE is non-nil, then prompt the user for which
formatter to run if none is configured, instead of returning nil.
If INTERACTIVE is the special symbol `prompt', then prompt
even if a formatter is configured."
(or (and (not (eq interactive 'prompt))
(apheleia--ensure-list
(or apheleia-formatter
;; Go through the mode alist. There are two types of
;; entries, mode and regex. We should return whichever
;; entry matches first in the list. However, if two
;; modes match, then we should return the entry for
;; the more specific mode.
;;
;; Implementation: Iterate once. If we match a regex,
;; immediately return, unless we already matched a
;; mode (setting the `formatters' variable), in which
;; case do not return, but also keep going to see if
;; there is a more specific mode later in the list. If
;; we match a mode, save the entry for later
;; reference, as well as the mode that matched it.
;; Update that saved entry only when we find a more
;; specific mode (i.e., a mode that is derived from
;; but not equal to the previously saved mode). Return
;; at the end of the loop the saved entry, if we
;; didn't exit early.
(let* ((unset (make-symbol "gensym-unset"))
(matched-mode nil)
(formatters unset)
(mode major-mode))
(cl-dolist (pred apheleia-mode-predicates)
(when-let* ((new-mode (funcall pred)))
(setq mode new-mode)
(cl-return)))
(cl-dolist (entry apheleia-mode-alist
(unless (eq formatters unset)
formatters))
(when (and (stringp (car entry))
buffer-file-name
(string-match-p
(car entry) buffer-file-name)
(eq formatters unset))
(cl-return (cdr entry)))
(when (and (symbolp (car entry))
(provided-mode-derived-p mode (car entry))
(or (eq formatters unset)
(and
(not (eq (car entry) matched-mode))
(provided-mode-derived-p
(car entry) matched-mode))))
(setq matched-mode (car entry))
(setq formatters (cdr entry))))))))
(and interactive
(list
(intern
(completing-read
"Formatter: "
(or (map-keys apheleia-formatters)
(user-error
"No formatters in `apheleia-formatters'"))
nil 'require-match))))))