Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#208] Allow ignoring Emacs indentation settings #211

Merged
merged 3 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ The format is based on [Keep a Changelog].
* Disable formatting of go module files with gofmt. This was never supported
([#214]).

### Features
* New user option `apheleia-formatters-respect-indent-level`,
defaulting to `t`. You can set this to `nil` to disable Apheleia
configuring formatters to use the same indent settings as the Emacs
major mode is using ([#208]).

### Enhancements
* Use the `prettier-json` formatter for `js-json-mode` ([#209]).
* Prettier is now enabled in `svelte-mode`.
Expand Down Expand Up @@ -68,6 +74,7 @@ The format is based on [Keep a Changelog].
[#182]: https://github.com/radian-software/apheleia/pull/182
[#187]: https://github.com/radian-software/apheleia/pull/187
[#196]: https://github.com/radian-software/apheleia/pull/196
[#208]: https://github.com/radian-software/apheleia/discussions/208
[#209]: https://github.com/radian-software/apheleia/pull/209
[#213]: https://github.com/radian-software/apheleia/pull/213
[#214]: https://github.com/radian-software/apheleia/pull/214
Expand Down
11 changes: 10 additions & 1 deletion apheleia-utils.el
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,23 @@
(require 'cl-lib)
(require 'subr-x)

(defcustom apheleia-formatters-respect-indent-level t
"Whether formatters should respect Emacs' indent configuration."
:type 'boolean
:group 'apheleia)

(defun apheleia-formatters-indent (tab-flag indent-flag 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."
to easily configure the indentation level of a formatter.

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)
(indent-var
(when-let ((indent (and (boundp indent-var)
Expand Down
14 changes: 8 additions & 6 deletions apheleia.el
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,14 @@
"-ln" (cl-case (bound-and-true-p sh-shell)
(sh "posix")
(t "bash"))
"-i" (number-to-string
(cond
(indent-tabs-mode 0)
((boundp 'sh-basic-offset)
sh-basic-offset)
(t 4)))
(when apheleia-formatters-respect-indent-level
(list
"-i" (number-to-string
(cond
(indent-tabs-mode 0)
((boundp 'sh-basic-offset)
sh-basic-offset)
(t 4)))))
"-"))
(rufo . ("rufo" "--filename" filepath "--simple-exit"))
(stylua . ("stylua" "-"))
Expand Down