diff options
| author | Ellis KenyĆ <elken@users.noreply.github.com> | 2022-08-21 23:21:21 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-21 15:21:21 -0700 |
| commit | 04366a90dfc1063c4a22ea2e4ccaa48303a457e0 (patch) | |
| tree | 7302878c9fbaef66a07cb39b2eef57d175057617 | |
| parent | ebb62564a85e53a709c667d0783fcdb11ebbf6da (diff) | |
Only process when there is output to return (#116)
* fix: only process when there is output to return
scalafmt only returns stdout when there are errors, this could also help
in other cases where a formatter returns incorrectly.
Ideally, this would also be improved by basic error checking heuristics
to work out if we need to update the buffer.
* Update changelog
Co-authored-by: Radon Rosborough <radon@intuitiveexplanations.com>
Co-authored-by: Radon Rosborough <radon.neon@gmail.com>
| -rw-r--r-- | CHANGELOG.md | 5 | ||||
| -rw-r--r-- | apheleia.el | 15 |
2 files changed, 13 insertions, 7 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index e81d6e7..bcf1458 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ The format is based on [Keep a Changelog]. fixes issues with formatters that behave differently when receiving input on stdin versus being run on a tty ([#119]). +### Bugs fixed +* When a formatter has a bug and fails to return anything on stdout + (e.g. scalafmt), do not erase the buffer ([#116]). + ### Formatters * [bean-format](https://github.com/beancount/beancount) for Beancount ([#101]). @@ -21,6 +25,7 @@ The format is based on [Keep a Changelog]. [#105]: https://github.com/radian-software/apheleia/pull/105 [#109]: https://github.com/radian-software/apheleia/issues/109 [#110]: https://github.com/radian-software/apheleia/pull/110 +[#116]: https://github.com/radian-software/apheleia/pull/116 [#119]: https://github.com/radian-software/apheleia/pull/119 ## 3.0 (released 2022-06-01) diff --git a/apheleia.el b/apheleia.el index 37d6c89..332499e 100644 --- a/apheleia.el +++ b/apheleia.el @@ -1034,13 +1034,14 @@ function: %s" command))) buffer remote (lambda (stdout) - (if (cdr formatters) - ;; Forward current stdout to remaining formatters, passing along - ;; the current callback and using the current formatters output - ;; as stdin. - (apheleia--run-formatters - (cdr formatters) buffer remote callback stdout) - (funcall callback stdout))) + (unless (string-empty-p (with-current-buffer stdout (buffer-string))) + (if (cdr formatters) + ;; Forward current stdout to remaining formatters, passing along + ;; the current callback and using the current formatters output + ;; as stdin. + (apheleia--run-formatters + (cdr formatters) buffer remote callback stdout) + (funcall callback stdout)))) stdin (car formatters)))) |
