summaryrefslogtreecommitdiff
path: root/rust-mode.el
diff options
context:
space:
mode:
authorPhillip Lord <phillip.lord@russet.org.uk>2019-05-28 22:57:37 +0200
committerNathan Moreau <nathan.moreau@m4x.org>2019-09-26 20:24:33 +0200
commitb7237b0edfc6f8518c2f8c8a4d83638960af88e4 (patch)
tree5b7eda3c77dec5fd56e51e07a10be234c49c1a1a /rust-mode.el
parent295e234e5ceb62c047c50ff14bd6ab0a39499816 (diff)
downloadrust-mode-b7237b0edfc6f8518c2f8c8a4d83638960af88e4.tar.gz
Add rust-format-diff-buffer
This command displays the output of rustfmt-diff.
Diffstat (limited to 'rust-mode.el')
-rw-r--r--rust-mode.el21
1 files changed, 21 insertions, 0 deletions
diff --git a/rust-mode.el b/rust-mode.el
index c81f421..85c1a23 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -1456,6 +1456,27 @@ This is written mainly to be used as `end-of-defun-function' for Rust."
(forward-char columns)))
(min (point) max-pos)))))
+(defun rust-format-diff-buffer ()
+ "Show diff to current buffer from rustfmt."
+ (interactive)
+ (unless (executable-find rust-rustfmt-bin)
+ (error "Could not locate executable \%s\"" rust-rustfmt-bin))
+ (make-process
+ :name "rustfmt-diff"
+ :command (list rust-rustfmt-bin "--check" (buffer-file-name))
+ :buffer
+ (with-current-buffer
+ (get-buffer-create "*rustfmt-diff*")
+ (erase-buffer)
+ (current-buffer))
+ :sentinel 'rust-format-diff-buffer-sentinel))
+
+(defun rust-format-diff-buffer-sentinel (process e)
+ (when (eq 'exit (process-status process))
+ (if (> (process-exit-status process) 0)
+ (display-buffer "*rustfmt-diff*")
+ (message "rustfmt check passed."))))
+
(defun rust-format-buffer ()
"Format the current buffer using rustfmt."
(interactive)