Assume filename correctly (#128)

Fixes #108

Co-authored-by: Radon Rosborough <radon@intuitiveexplanations.com>
This commit is contained in:
Ellis Kenyő 2022-09-14 03:05:22 +01:00 committed by GitHub
parent e01ced3ac9
commit 9101a3380c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 2 deletions

View file

@ -29,6 +29,9 @@ The format is based on [Keep a Changelog].
correctly; it throws an error. It doesn't make sense to attempt to correctly; it throws an error. It doesn't make sense to attempt to
format if we can't find the correct formatter, so instead formatting format if we can't find the correct formatter, so instead formatting
is only attempted when the formatter is found. [#126] is only attempted when the formatter is found. [#126]
* clang-format doesn't handle filenames correctly by default. Support
for guessing the flags from first the file name then the major mode
in the case of a temporary buffer was added in [#128]
### Formatters ### Formatters
* [elm-format](https://github.com/avh4/elm-format) for Elm ([#100]). * [elm-format](https://github.com/avh4/elm-format) for Elm ([#100]).
@ -56,6 +59,7 @@ The format is based on [Keep a Changelog].
[#123]: https://github.com/radian-software/apheleia/issues/123 [#123]: https://github.com/radian-software/apheleia/issues/123
[#124]: https://github.com/radian-software/apheleia/issues/124 [#124]: https://github.com/radian-software/apheleia/issues/124
[#125]: https://github.com/radian-software/apheleia/pull/125 [#125]: https://github.com/radian-software/apheleia/pull/125
[#126]: https://github.com/radian-software/apheleia/pull/126
[#127]: https://github.com/radian-software/apheleia/pull/127 [#127]: https://github.com/radian-software/apheleia/pull/127
[#128]: https://github.com/radian-software/apheleia/pull/128 [#128]: https://github.com/radian-software/apheleia/pull/128

View file

@ -925,7 +925,15 @@ being run, for diagnostic purposes."
'((bean-format . ("bean-format")) '((bean-format . ("bean-format"))
(black . ("black" "-")) (black . ("black" "-"))
(brittany . ("brittany")) (brittany . ("brittany"))
(clang-format . ("clang-format")) (clang-format . ("clang-format"
"-assume-filename"
(or (buffer-file-name)
(cdr (assoc major-mode
'((c-mode . ".c")
(c++-mode . ".cpp")
(cuda-mode . ".cu")
(protobuf-mode . ".proto"))))
".c")))
(dart-format . ("dart" "format")) (dart-format . ("dart" "format"))
(elm-format . ("elm-format" "--yes" "--stdin")) (elm-format . ("elm-format" "--yes" "--stdin"))
(fish-indent . ("fish_indent")) (fish-indent . ("fish_indent"))

View file

@ -271,7 +271,9 @@ environment variable, defaulting to all formatters."
in-temp-file) in-temp-file)
(`output (`output
out-temp-file) out-temp-file)
(_ arg))) ((guard (stringp arg))
arg)
(_ (eval arg))))
command)) command))
(setq command (delq 'npx command)) (setq command (delq 'npx command))
(setq stdout-buffer (get-buffer-create (setq stdout-buffer (get-buffer-create