diff options
| author | Ellis KenyĆ <elken@users.noreply.github.com> | 2022-09-11 09:18:30 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-11 09:18:30 +0100 |
| commit | e01ced3ac985eabd51dad348d04974cefa778625 (patch) | |
| tree | 40440c185518f33a1d02f7af364903af050d26b4 | |
| parent | 46d373f4bd0e4c3b46838912cd4c1b667ac557c3 (diff) | |
Guard against missing formatters (#126)
Fixes #122
| -rw-r--r-- | CHANGELOG.md | 5 | ||||
| -rw-r--r-- | apheleia.el | 41 |
2 files changed, 26 insertions, 20 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 0498d7c..7e89f92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,10 @@ The format is based on [Keep a Changelog]. running. Instead, it is disabled in narrowed buffers. Support for narrowed buffers may be added in future but it has never been correctly supported in the past (see [#43]). More at [#124], [#127]. +* Currently, when a formatter invoked via a process isn't installed + 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 + is only attempted when the formatter is found. [#126] ### Formatters * [elm-format](https://github.com/avh4/elm-format) for Elm ([#100]). @@ -53,6 +57,7 @@ The format is based on [Keep a Changelog]. [#124]: https://github.com/radian-software/apheleia/issues/124 [#125]: https://github.com/radian-software/apheleia/pull/125 [#127]: https://github.com/radian-software/apheleia/pull/127 +[#128]: https://github.com/radian-software/apheleia/pull/128 ## 3.0 (released 2022-06-01) ### Breaking changes diff --git a/apheleia.el b/apheleia.el index 379fd0d..f9dbcc5 100644 --- a/apheleia.el +++ b/apheleia.el @@ -862,27 +862,28 @@ purposes." (locate-library "apheleia")))))) exec-path))) (cl-destructuring-bind (input-fname output-fname stdin &rest command) ret - (apheleia--execute-formatter-process - :command command - :stdin (unless input-fname - stdin) - :callback - (lambda (stdout) - (when output-fname - ;; Load output-fname contents into the stdout buffer. - (erase-buffer) - (insert-file-contents-literally output-fname)) - - (funcall callback stdout)) - :ensure - (lambda () - (ignore-errors - (when input-fname - (delete-file input-fname)) + (when (executable-find (car command)) + (apheleia--execute-formatter-process + :command command + :stdin (unless input-fname + stdin) + :callback + (lambda (stdout) (when output-fname - (delete-file output-fname)))) - :remote remote - :formatter formatter))))) + ;; Load output-fname contents into the stdout buffer. + (erase-buffer) + (insert-file-contents-literally output-fname)) + + (funcall callback stdout)) + :ensure + (lambda () + (ignore-errors + (when input-fname + (delete-file input-fname)) + (when output-fname + (delete-file output-fname)))) + :remote remote + :formatter formatter)))))) (defun apheleia--run-formatter-function (func buffer remote callback stdin formatter) |
