fix(format): clang-format: respect c-basic-offset

In the absence of a .clang-format file, imposing the value of
`c-basic-offset` onto clang-format seems like reasonable, default
behavior. Like all other cases, this can be disabled by unsetting
`apheleia-formatters-respect-indent-level` globally or mode-locally with
`setq-hook!` or similar.
This commit is contained in:
Henrik Lissner 2024-09-14 16:52:10 -04:00
parent d633c15042
commit 7ec570fdf5
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -79,6 +79,18 @@ This is controlled by `+format-on-save-disabled-modes'."
;; `+format-with-lsp-mode' in the appropriate modes.
(add-to-list 'apheleia-formatters '(lsp . +format-lsp-buffer))
;; Apheleia's default clang-format config doesn't respect `c-basic-offset', so
;; force it to in the absence of a .clang-format file.
(setf (alist-get 'clang-format apheleia-formatters)
`("clang-format"
"-assume-filename"
(or (apheleia-formatters-local-buffer-file-name)
(apheleia-formatters-mode-extension)
".c")
(when apheleia-formatters-respect-indent-level
(unless (locate-dominating-file default-directory ".clang-format")
(format "--style={IndentWidth: %d}" c-basic-offset)))))
;; Apheleia's default config for prettier passes an explicit --tab-width N to
;; all prettier formatters, respecting your indent settings in Emacs, but
;; overriding any indent settings in your prettier config files. This changes