aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRadon Rosborough <radon.neon@gmail.com>2019-09-20 17:04:25 -0700
committerRadon Rosborough <radon.neon@gmail.com>2019-09-20 17:08:43 -0700
commite28a264989c32cc1dda1c8661350fad2306bc619 (patch)
treee62d000dc42b365aadb9a3e61d30818062ab62da
parent49568bb1668c05050cd7ec014c94405435e596b3 (diff)
Disable automatically for remote files
-rw-r--r--README.md3
-rw-r--r--apheleia.el47
2 files changed, 32 insertions, 18 deletions
diff --git a/README.md b/README.md
index a90b66e..21338c2 100644
--- a/README.md
+++ b/README.md
@@ -89,6 +89,9 @@ the configured formatter for the current buffer. Running with a prefix
argument will cause the command to prompt you for which formatter to
run.
+Apheleia does not currently support TRAMP, and is therefore
+automatically disabled for remote files.
+
The following user options are also available:
* `apheleia-post-format-hook`: Normal hook run after Apheleia formats
diff --git a/apheleia.el b/apheleia.el
index 8091b09..bfb382e 100644
--- a/apheleia.el
+++ b/apheleia.el
@@ -513,6 +513,11 @@ even if a formatter is configured."
(defvar apheleia--buffer-hash nil
"Return value of `buffer-hash' when formatter started running.")
+(defun apheleia--disallowed-p ()
+ "Return an error message if Apheleia cannot be run, else nil."
+ (when (and buffer-file-name (file-remote-p buffer-file-name))
+ "Apheleia does not support remote files"))
+
;;;###autoload
(defun apheleia-format-buffer (command &optional callback)
"Run code formatter asynchronously on current buffer, preserving point.
@@ -550,24 +555,30 @@ aborted.
If the formatter actually finishes running and the buffer is
successfully updated (even if the formatter has not made any
changes), CALLBACK, if provided, is invoked with no arguments."
- (interactive (list (apheleia--get-formatter-command
- (if current-prefix-arg
- 'prompt
- 'interactive))))
- (setq-local apheleia--buffer-hash (apheleia--buffer-hash))
- (apheleia--run-formatter
- command
- (lambda (formatted-buffer)
- ;; Short-circuit.
- (when (equal apheleia--buffer-hash (apheleia--buffer-hash))
- (apheleia--create-rcs-patch
- (current-buffer) formatted-buffer
- (lambda (patch-buffer)
- (when (equal apheleia--buffer-hash (apheleia--buffer-hash))
- (apheleia--apply-rcs-patch
- (current-buffer) patch-buffer)
- (when callback
- (funcall callback)))))))))
+ (interactive (progn
+ (when-let ((err (apheleia--disallowed-p)))
+ (user-error err))
+ (list (apheleia--get-formatter-command
+ (if current-prefix-arg
+ 'prompt
+ 'interactive)))))
+ ;; Fail silently if disallowed, since we don't want to throw an
+ ;; error on `post-command-hook'.
+ (unless (apheleia--disallowed-p)
+ (setq-local apheleia--buffer-hash (apheleia--buffer-hash))
+ (apheleia--run-formatter
+ command
+ (lambda (formatted-buffer)
+ ;; Short-circuit.
+ (when (equal apheleia--buffer-hash (apheleia--buffer-hash))
+ (apheleia--create-rcs-patch
+ (current-buffer) formatted-buffer
+ (lambda (patch-buffer)
+ (when (equal apheleia--buffer-hash (apheleia--buffer-hash))
+ (apheleia--apply-rcs-patch
+ (current-buffer) patch-buffer)
+ (when callback
+ (funcall callback))))))))))
(defcustom apheleia-post-format-hook nil
"Normal hook run after Apheleia formats a buffer."