emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/rust-mode b7237b0 405/486: Add rust-format-diff-buffer


From: ELPA Syncer
Subject: [nongnu] elpa/rust-mode b7237b0 405/486: Add rust-format-diff-buffer
Date: Sat, 7 Aug 2021 09:26:02 -0400 (EDT)

branch: elpa/rust-mode
commit b7237b0edfc6f8518c2f8c8a4d83638960af88e4
Author: Phillip Lord <phillip.lord@russet.org.uk>
Commit: Nathan Moreau <nathan.moreau@m4x.org>

    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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]