Skip to content

Commit 7724813

Browse files
authored
Merge pull request #206 from cjhowe7/master
Allow formatting with long lines (fixes #186)
2 parents 3220937 + 610fe1f commit 7724813

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

rust-mode.el

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,12 +1197,26 @@ This is written mainly to be used as `end-of-defun-function' for Rust."
11971197
(with-current-buffer (get-buffer-create "*rustfmt*")
11981198
(erase-buffer)
11991199
(insert-buffer-substring buf)
1200-
(if (zerop (call-process-region (point-min) (point-max) rust-rustfmt-bin t t nil))
1201-
(progn
1202-
(if (not (string= (buffer-string) (with-current-buffer buf (buffer-string))))
1203-
(copy-to-buffer buf (point-min) (point-max)))
1204-
(kill-buffer))
1205-
(error "Rustfmt failed, see *rustfmt* buffer for details"))))
1200+
(let* ((tmpf (make-temp-file "rustfmt"))
1201+
(ret (call-process-region (point-min) (point-max) rust-rustfmt-bin
1202+
t `(t ,tmpf) nil)))
1203+
(unwind-protect
1204+
(cond
1205+
((zerop ret)
1206+
(if (not (string= (buffer-string)
1207+
(with-current-buffer buf (buffer-string))))
1208+
(copy-to-buffer buf (point-min) (point-max)))
1209+
(kill-buffer))
1210+
((= ret 3)
1211+
(if (not (string= (buffer-string)
1212+
(with-current-buffer buf (buffer-string))))
1213+
(copy-to-buffer buf (point-min) (point-max)))
1214+
(erase-buffer)
1215+
(insert-file-contents tmpf)
1216+
(error "Rustfmt could not format some lines, see *rustfmt* buffer for details"))
1217+
(t
1218+
(error "Rustfmt failed, see *rustfmt* buffer for details"))))
1219+
(delete-file tmpf))))
12061220

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

0 commit comments

Comments
 (0)