summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2017-05-31 16:58:27 -0600
committerGitHub <noreply@github.com>2017-05-31 16:58:27 -0600
commit77248135153a6c15cfc35ff9d5db550a5b1a8197 (patch)
treec7f2c11a15e85143001dd026eab03cb81303a0b2
parent3220937aca17fd3200c9616d97a3484f55b604d5 (diff)
parent610fe1fb69f072b2a13c907d03a547a07b993c8c (diff)
downloadrust-mode-77248135153a6c15cfc35ff9d5db550a5b1a8197.tar.gz
Merge pull request #206 from cjhowe7/master
Allow formatting with long lines (fixes #186)
-rw-r--r--rust-mode.el26
1 files changed, 20 insertions, 6 deletions
diff --git a/rust-mode.el b/rust-mode.el
index 9f9e391..1a9d77d 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -1197,12 +1197,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)
- (if (zerop (call-process-region (point-min) (point-max) rust-rustfmt-bin t t nil))
- (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"))
+ (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]\\)")