Skip to content

Commit 4ec735e

Browse files
author
Christian Howe
committed
Add stderr output from rustfmt on exit code 3
1 parent 367a89c commit 4ec735e

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

rust-mode.el

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,13 +1195,25 @@ This is written mainly to be used as `end-of-defun-function' for Rust."
11951195
(with-current-buffer (get-buffer-create "*rustfmt*")
11961196
(erase-buffer)
11971197
(insert-buffer-substring buf)
1198-
(let ((ret (call-process-region (point-min) (point-max) rust-rustfmt-bin t '(t nil) nil)))
1199-
(if (or (zerop ret) (= ret 3))
1200-
(progn
1201-
(if (not (string= (buffer-string) (with-current-buffer buf (buffer-string))))
1202-
(copy-to-buffer buf (point-min) (point-max)))
1203-
(kill-buffer))
1204-
(error "Rustfmt failed, see *rustfmt* buffer for details")))))
1198+
(let ((tmpf (make-temp-file "rustfmt")))
1199+
(let ((ret (call-process-region (point-min) (point-max) rust-rustfmt-bin
1200+
t `(t ,tmpf) nil)))
1201+
(format-message "%d" ret)
1202+
(cond
1203+
((zerop ret)
1204+
(error "Rustfmt failed, see *rustfmt* buffer for details"))
1205+
((= ret 3)
1206+
(if (not (string= (buffer-string)
1207+
(with-current-buffer buf (buffer-string))))
1208+
(copy-to-buffer buf (point-min) (point-max)))
1209+
(erase-buffer)
1210+
(insert-file-contents tmpf)
1211+
(error "Rustfmt could not format some lines, see *rustfmt* buffer for details"))
1212+
(t
1213+
(if (not (string= (buffer-string)
1214+
(with-current-buffer buf (buffer-string))))
1215+
(copy-to-buffer buf (point-min) (point-max)))
1216+
(kill-buffer)))))))
12051217

12061218
(defconst rust--format-word "\\b\\(else\\|enum\\|fn\\|for\\|if\\|let\\|loop\\|match\\|struct\\|unsafe\\|while\\)\\b")
12071219
(defconst rust--format-line "\\([\n]\\)")

0 commit comments

Comments
 (0)