diff options
| author | Christian Howe <cjhowe7@gmail.com> | 2017-05-31 14:34:26 -0400 |
|---|---|---|
| committer | Christian Howe <cjhowe7@gmail.com> | 2017-05-31 14:34:26 -0400 |
| commit | 610fe1fb69f072b2a13c907d03a547a07b993c8c (patch) | |
| tree | 949067b6c9fd2fd7fd2cf4d49c9553ee7b1ab2fe /rust-mode.el | |
| parent | 0256f0290e5c79d124530b6b621d2a6fc5a19bf4 (diff) | |
| download | rust-mode-610fe1fb69f072b2a13c907d03a547a07b993c8c.tar.gz | |
Address review comments
Diffstat (limited to 'rust-mode.el')
| -rw-r--r-- | rust-mode.el | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/rust-mode.el b/rust-mode.el index a2b5fc5..aafb9a8 100644 --- a/rust-mode.el +++ b/rust-mode.el @@ -1195,24 +1195,26 @@ 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 ((tmpf (make-temp-file "rustfmt"))) - (let ((ret (call-process-region (point-min) (point-max) rust-rustfmt-bin - t `(t ,tmpf) nil))) - (cond - ((zerop ret) - (if (not (string= (buffer-string) - (with-current-buffer buf (buffer-string)))) - (copy-to-buffer buf (point-min) (point-max))) - (kill-buffer)) - ((= 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 - (error "Rustfmt failed, see *rustfmt* buffer for details"))))))) + (let* ((tmpf (make-temp-file "rustfmt")) + (ret (call-process-region (point-min) (point-max) rust-rustfmt-bin + t `(t ,tmpf) nil))) + (unwind-protect + (cond + ((zerop ret) + (if (not (string= (buffer-string) + (with-current-buffer buf (buffer-string)))) + (copy-to-buffer buf (point-min) (point-max))) + (kill-buffer)) + ((= 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 + (error "Rustfmt failed, see *rustfmt* buffer for details")))) + (delete-file tmpf)))) (defconst rust--format-word "\\b\\(else\\|enum\\|fn\\|for\\|if\\|let\\|loop\\|match\\|struct\\|unsafe\\|while\\)\\b") (defconst rust--format-line "\\([\n]\\)") |
