aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md4
-rw-r--r--apheleia.el23
2 files changed, 13 insertions, 14 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 067d6c6..9212f50 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,8 @@ The format is based on [Keep a Changelog].
## Unreleased
### Enhancements
* shfmt uses 4 spaces instead of tabs by default.
+* Formatters using `'filepath` (OCamlFormat and Prettier) are no
+ longer prevented from running on a modified buffer ([#109], [#110]).
### Formatters
* [bean-format](https://github.com/beancount/beancount) for Beancount
@@ -14,6 +16,8 @@ The format is based on [Keep a Changelog].
[#101]: https://github.com/radian-software/apheleia/pull/101
[#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
## 3.0 (released 2022-06-01)
### Breaking changes
diff --git a/apheleia.el b/apheleia.el
index ce188f7..70609cd 100644
--- a/apheleia.el
+++ b/apheleia.el
@@ -767,26 +767,21 @@ cmd is to be run."
it's first in the sequence"))
(unless remote-match
(error "Formatter uses `file' but process will run on different \
-machine from the machine file is available on")))
+machine from the machine file is available on"))
+ (setq stdin nil)
+ ;; If `buffer-file-name' is nil then there is no backing
+ ;; file, so `buffer-modified-p' should be ignored (it always
+ ;; returns non-nil).
+ (when (and (buffer-modified-p) buffer-file-name)
+ (cl-return)))
;; We always strip out the remote-path prefix for file/filepath.
(let ((file-name (apheleia--strip-remote
(or buffer-file-name
(concat default-directory
(apheleia--safe-buffer-name))))))
(setq command (mapcar (lambda (arg)
- (when (eq arg 'file)
- (setq stdin nil))
(if (memq arg '(file filepath))
- (prog1 file-name
- ;; If `buffer-file-name' is
- ;; nil then there is no
- ;; backing file, so
- ;; `buffer-modified-p' should
- ;; be ignored (it always
- ;; returns non-nil).
- (when (and (buffer-modified-p)
- buffer-file-name)
- (cl-return)))
+ file-name
arg))
command))))
(when (or (memq 'input command) (memq 'inplace command))
@@ -919,7 +914,7 @@ being run, for diagnostic purposes."
(apply-partially #'kill-buffer scratch)))))
(defcustom apheleia-formatters
- '((bean-format . ("bean-format" filepath))
+ '((bean-format . ("bean-format"))
(black . ("black" "-"))
(brittany . ("brittany"))
(clang-format . ("clang-format"))