Function: apheleia-formatters-indent

apheleia-formatters-indent is a natively compiled function defined in apheleia-utils.el.

Signature

(apheleia-formatters-indent TAB-FLAG INDENT-FLAG &optional INDENT-VAR)

Documentation

Set flag for indentation.

Helper function for apheleia-formatters which allows you to supply alternating flags based on the current buffers indent configuration. If the buffer is indented with tabs then returns TAB-FLAG. Otherwise if INDENT-VAR is set in the buffer return INDENT-FLAG and the value of INDENT-VAR. Use this to easily configure the indentation level of a formatter. If INDENT-VAR is unset then intelligently try to determine the indentation variable based on the current mode.

If apheleia-formatters-respect-indent-level is nil then this always returns nil to defer to the formatter.

Aliases

apheleia-formatters-js-indent (obsolete since 4.1)

Source Code

;; Defined in /nix/store/lwcwryzabcmvjcwwzzs65jrwf7p7d7cs-emacs-packages-deps/share/emacs/site-lisp/elpa/apheleia-20260915.1628/apheleia-utils.el
(defun apheleia-formatters-indent (tab-flag indent-flag &optional indent-var)
  "Set flag for indentation.
Helper function for `apheleia-formatters' which allows you to supply
alternating flags based on the current buffers indent configuration. If the
buffer is indented with tabs then returns TAB-FLAG. Otherwise if INDENT-VAR
is set in the buffer return INDENT-FLAG and the value of INDENT-VAR. Use this
to easily configure the indentation level of a formatter. If INDENT-VAR is
unset then intelligently try to determine the indentation variable based on
the current mode.

If `apheleia-formatters-respect-indent-level' is nil then this
always returns nil to defer to the formatter."
  (cond
   ((not apheleia-formatters-respect-indent-level) nil)
   (indent-tabs-mode tab-flag)
   (t
    (unless indent-var
      (setq indent-var
            (cl-case major-mode
              (cperl-mode 'cperl-indent-level)
              (css-mode 'css-indent-offset)
              (css-ts-mode 'css-indent-offset)
              (graphql-mode 'graphql-indent-level)
              (html-mode 'sgml-basic-offset)
              (js-jsx-mode 'js-indent-level)
              (js-ts-mode 'js-indent-level)
              (js-mode 'js-indent-level)
              (js2-jsx-mode 'js2-basic-offset)
              (js2-mode 'js2-basic-offset)
              (js3-mode 'js3-indent-level)
              (json-mode 'js-indent-level)
              (js-json-mode 'js-indent-level)
              (json-ts-mode 'json-ts-mode-indent-offset)
              (nxml-mode 'nxml-child-indent)
              (robot-mode 'robot-mode-basic-offset)
              (perl-mode 'perl-indent-level)
              (python-mode 'python-indent-offset)
              (ruby-mode 'ruby-indent-level)
              (ruby-ts-mode 'ruby-indent-level)
              (scss-mode 'css-indent-offset)
              (svelte-mode 'svelte-basic-offset)
              (web-mode 'web-mode-indent-style)
              (tsx-ts-mode 'typescript-ts-mode-indent-offset)
              (typescript-mode 'typescript-indent-level)
              (typescript-ts-mode 'typescript-ts-mode-indent-offset)
              (yaml-mode 'yaml-indent-offset)
              (yaml-ts-mode 'yaml-indent-offset))))

    (when-let* ((indent (and indent-var
                             (boundp indent-var)
                             (symbol-value indent-var))))
      (list indent-flag (number-to-string indent))))))