From b7237b0edfc6f8518c2f8c8a4d83638960af88e4 Mon Sep 17 00:00:00 2001 From: Phillip Lord Date: Tue, 28 May 2019 22:57:37 +0200 Subject: Add rust-format-diff-buffer This command displays the output of rustfmt-diff. --- rust-mode.el | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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) -- cgit v1.2.3