File tree Expand file tree Collapse file tree 1 file changed +20
-6
lines changed Expand file tree Collapse file tree 1 file changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -1197,12 +1197,26 @@ This is written mainly to be used as `end-of-defun-function' for Rust."
1197
1197
(with-current-buffer (get-buffer-create " *rustfmt*" )
1198
1198
(erase-buffer )
1199
1199
(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))))
1206
1220
1207
1221
(defconst rust--format-word " \\ b\\ (else\\ |enum\\ |fn\\ |for\\ |if\\ |let\\ |loop\\ |match\\ |struct\\ |unsafe\\ |while\\ )\\ b" )
1208
1222
(defconst rust--format-line " \\ ([\n ]\\ )" )
You can’t perform that action at this time.
0 commit comments