Skip to content

Commit b7237b0

Browse files
phillordmookid
authored andcommitted
Add rust-format-diff-buffer
This command displays the output of rustfmt-diff.
1 parent 295e234 commit b7237b0

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

rust-mode.el

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,6 +1456,27 @@ This is written mainly to be used as `end-of-defun-function' for Rust."
14561456
(forward-char columns)))
14571457
(min (point) max-pos)))))
14581458

1459+
(defun rust-format-diff-buffer ()
1460+
"Show diff to current buffer from rustfmt."
1461+
(interactive)
1462+
(unless (executable-find rust-rustfmt-bin)
1463+
(error "Could not locate executable \%s\"" rust-rustfmt-bin))
1464+
(make-process
1465+
:name "rustfmt-diff"
1466+
:command (list rust-rustfmt-bin "--check" (buffer-file-name))
1467+
:buffer
1468+
(with-current-buffer
1469+
(get-buffer-create "*rustfmt-diff*")
1470+
(erase-buffer)
1471+
(current-buffer))
1472+
:sentinel 'rust-format-diff-buffer-sentinel))
1473+
1474+
(defun rust-format-diff-buffer-sentinel (process e)
1475+
(when (eq 'exit (process-status process))
1476+
(if (> (process-exit-status process) 0)
1477+
(display-buffer "*rustfmt-diff*")
1478+
(message "rustfmt check passed."))))
1479+
14591480
(defun rust-format-buffer ()
14601481
"Format the current buffer using rustfmt."
14611482
(interactive)

0 commit comments

Comments
 (0)