Skip to content

Commit d71fe94

Browse files
committed
restore points when an error occurs too
1 parent 7724813 commit d71fe94

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

rust-mode.el

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,19 +1326,20 @@ This is written mainly to be used as `end-of-defun-function' for Rust."
13261326
(rust--format-get-loc buffer start)
13271327
(rust--format-get-loc buffer point))
13281328
window-loc)))))
1329-
(rust--format-call (current-buffer))
1330-
(dolist (loc buffer-loc)
1331-
(let* ((buffer (pop loc))
1332-
(pos (rust--format-get-pos buffer (pop loc))))
1333-
(with-current-buffer buffer
1334-
(goto-char pos))))
1335-
(dolist (loc window-loc)
1336-
(let* ((window (pop loc))
1337-
(buffer (window-buffer window))
1338-
(start (rust--format-get-pos buffer (pop loc)))
1339-
(pos (rust--format-get-pos buffer (pop loc))))
1340-
(set-window-start window start)
1341-
(set-window-point window pos))))
1329+
(unwind-protect
1330+
(rust--format-call (current-buffer))
1331+
(dolist (loc buffer-loc)
1332+
(let* ((buffer (pop loc))
1333+
(pos (rust--format-get-pos buffer (pop loc))))
1334+
(with-current-buffer buffer
1335+
(goto-char pos))))
1336+
(dolist (loc window-loc)
1337+
(let* ((window (pop loc))
1338+
(buffer (window-buffer window))
1339+
(start (rust--format-get-pos buffer (pop loc)))
1340+
(pos (rust--format-get-pos buffer (pop loc))))
1341+
(set-window-start window start)
1342+
(set-window-point window pos)))))
13421343

13431344
(message "Formatted buffer with rustfmt."))
13441345

0 commit comments

Comments
 (0)