File tree Expand file tree Collapse file tree 1 file changed +19
-7
lines changed Expand file tree Collapse file tree 1 file changed +19
-7
lines changed Original file line number Diff line number Diff line change @@ -1195,13 +1195,25 @@ This is written mainly to be used as `end-of-defun-function' for Rust."
1195
1195
(with-current-buffer (get-buffer-create " *rustfmt*" )
1196
1196
(erase-buffer )
1197
1197
(insert-buffer-substring buf)
1198
- (let ((ret (call-process-region (point-min ) (point-max ) rust-rustfmt-bin t '(t nil ) nil )))
1199
- (if (or (zerop ret) (= ret 3 ))
1200
- (progn
1201
- (if (not (string= (buffer-string ) (with-current-buffer buf (buffer-string ))))
1202
- (copy-to-buffer buf (point-min ) (point-max )))
1203
- (kill-buffer ))
1204
- (error " Rustfmt failed, see *rustfmt* buffer for details " )))))
1198
+ (let ((tmpf (make-temp-file " rustfmt" )))
1199
+ (let ((ret (call-process-region (point-min ) (point-max ) rust-rustfmt-bin
1200
+ t `(t , tmpf ) nil )))
1201
+ (format-message " %d " ret)
1202
+ (cond
1203
+ ((zerop ret)
1204
+ (error " Rustfmt failed, see *rustfmt* buffer for details " ))
1205
+ ((= ret 3 )
1206
+ (if (not (string= (buffer-string )
1207
+ (with-current-buffer buf (buffer-string ))))
1208
+ (copy-to-buffer buf (point-min ) (point-max )))
1209
+ (erase-buffer )
1210
+ (insert-file-contents tmpf)
1211
+ (error " Rustfmt could not format some lines, see *rustfmt* buffer for details " ))
1212
+ (t
1213
+ (if (not (string= (buffer-string )
1214
+ (with-current-buffer buf (buffer-string ))))
1215
+ (copy-to-buffer buf (point-min ) (point-max )))
1216
+ (kill-buffer )))))))
1205
1217
1206
1218
(defconst rust--format-word " \\ b\\ (else\\ |enum\\ |fn\\ |for\\ |if\\ |let\\ |loop\\ |match\\ |struct\\ |unsafe\\ |while\\ )\\ b" )
1207
1219
(defconst rust--format-line " \\ ([\n ]\\ )" )
You can’t perform that action at this time.
0 commit comments