Skip to content

Commit ad674a1

Browse files
committed
save excursion when formatting
close #392
1 parent b173b3a commit ad674a1

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

rust-rustfmt.el

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,11 @@ Return the created process."
331331
;; If emacs version >= 26.2, we can use replace-buffer-contents to
332332
;; preserve location and markers in buffer, otherwise we can try to
333333
;; save locations as best we can, though we still lose markers.
334-
(if (version<= "26.2" emacs-version)
335-
(rust--format-buffer-using-replace-buffer-contents)
336-
(rust--format-buffer-saving-position-manually)))
334+
(save-excursion
335+
(save-window-excursion
336+
(if (version<= "26.2" emacs-version)
337+
(rust--format-buffer-using-replace-buffer-contents)
338+
(rust--format-buffer-saving-position-manually)))))
337339

338340
(defun rust-enable-format-on-save ()
339341
"Enable formatting using rustfmt when saving buffer."

0 commit comments

Comments
 (0)