@@ -1195,24 +1195,26 @@ 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 ((tmpf (make-temp-file " rustfmt" )))
1199
- (let ((ret (call-process-region (point-min ) (point-max ) rust-rustfmt-bin
1200
- t `(t , tmpf ) nil )))
1201
- (cond
1202
- ((zerop ret)
1203
- (if (not (string= (buffer-string )
1204
- (with-current-buffer buf (buffer-string ))))
1205
- (copy-to-buffer buf (point-min ) (point-max )))
1206
- (kill-buffer ))
1207
- ((= ret 3 )
1208
- (if (not (string= (buffer-string )
1209
- (with-current-buffer buf (buffer-string ))))
1210
- (copy-to-buffer buf (point-min ) (point-max )))
1211
- (erase-buffer )
1212
- (insert-file-contents tmpf)
1213
- (error " Rustfmt could not format some lines, see *rustfmt* buffer for details " ))
1214
- (t
1215
- (error " Rustfmt failed, see *rustfmt* buffer for details " )))))))
1198
+ (let* ((tmpf (make-temp-file " rustfmt" ))
1199
+ (ret (call-process-region (point-min ) (point-max ) rust-rustfmt-bin
1200
+ t `(t , tmpf ) nil )))
1201
+ (unwind-protect
1202
+ (cond
1203
+ ((zerop ret)
1204
+ (if (not (string= (buffer-string )
1205
+ (with-current-buffer buf (buffer-string ))))
1206
+ (copy-to-buffer buf (point-min ) (point-max )))
1207
+ (kill-buffer ))
1208
+ ((= ret 3 )
1209
+ (if (not (string= (buffer-string )
1210
+ (with-current-buffer buf (buffer-string ))))
1211
+ (copy-to-buffer buf (point-min ) (point-max )))
1212
+ (erase-buffer )
1213
+ (insert-file-contents tmpf)
1214
+ (error " Rustfmt could not format some lines, see *rustfmt* buffer for details " ))
1215
+ (t
1216
+ (error " Rustfmt failed, see *rustfmt* buffer for details " ))))
1217
+ (delete-file tmpf))))
1216
1218
1217
1219
(defconst rust--format-word " \\ b\\ (else\\ |enum\\ |fn\\ |for\\ |if\\ |let\\ |loop\\ |match\\ |struct\\ |unsafe\\ |while\\ )\\ b" )
1218
1220
(defconst rust--format-line " \\ ([\n ]\\ )" )
0 commit comments