From 4ec735e0fb993724fc264f6937267a898e30e6bf Mon Sep 17 00:00:00 2001 From: Christian Howe Date: Tue, 18 Apr 2017 15:45:54 -0400 Subject: Add stderr output from rustfmt on exit code 3 --- rust-mode.el | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'rust-mode.el') diff --git a/rust-mode.el b/rust-mode.el index 1fce291..8d81efa 100644 --- a/rust-mode.el +++ b/rust-mode.el @@ -1195,13 +1195,25 @@ This is written mainly to be used as `end-of-defun-function' for Rust." (with-current-buffer (get-buffer-create "*rustfmt*") (erase-buffer) (insert-buffer-substring buf) - (let ((ret (call-process-region (point-min) (point-max) rust-rustfmt-bin t '(t nil) nil))) - (if (or (zerop ret) (= ret 3)) - (progn - (if (not (string= (buffer-string) (with-current-buffer buf (buffer-string)))) - (copy-to-buffer buf (point-min) (point-max))) - (kill-buffer)) - (error "Rustfmt failed, see *rustfmt* buffer for details"))))) + (let ((tmpf (make-temp-file "rustfmt"))) + (let ((ret (call-process-region (point-min) (point-max) rust-rustfmt-bin + t `(t ,tmpf) nil))) + (format-message "%d" ret) + (cond + ((zerop ret) + (error "Rustfmt failed, see *rustfmt* buffer for details")) + ((= ret 3) + (if (not (string= (buffer-string) + (with-current-buffer buf (buffer-string)))) + (copy-to-buffer buf (point-min) (point-max))) + (erase-buffer) + (insert-file-contents tmpf) + (error "Rustfmt could not format some lines, see *rustfmt* buffer for details")) + (t + (if (not (string= (buffer-string) + (with-current-buffer buf (buffer-string)))) + (copy-to-buffer buf (point-min) (point-max))) + (kill-buffer))))))) (defconst rust--format-word "\\b\\(else\\|enum\\|fn\\|for\\|if\\|let\\|loop\\|match\\|struct\\|unsafe\\|while\\)\\b") (defconst rust--format-line "\\([\n]\\)") -- cgit v1.2.3