diff options
| author | Christian Howe <cjhowe7@gmail.com> | 2017-04-18 15:45:54 -0400 |
|---|---|---|
| committer | Christian Howe <cjhowe7@gmail.com> | 2017-04-18 15:45:54 -0400 |
| commit | 4ec735e0fb993724fc264f6937267a898e30e6bf (patch) | |
| tree | 37af41473146d2268081abf57cce49ea078e8a55 /rust-mode.el | |
| parent | 367a89c423481db18ab1dd346f5b389ca392a69e (diff) | |
| download | rust-mode-4ec735e0fb993724fc264f6937267a898e30e6bf.tar.gz | |
Add stderr output from rustfmt on exit code 3
Diffstat (limited to 'rust-mode.el')
| -rw-r--r-- | rust-mode.el | 26 |
1 files changed, 19 insertions, 7 deletions
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]\\)") |
