From ad674a1d43a7ffefd3dba33599c6aa5f49d70e43 Mon Sep 17 00:00:00 2001 From: brotzeit Date: Fri, 7 Jan 2022 11:11:21 +0100 Subject: save excursion when formatting close #392 --- rust-rustfmt.el | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'rust-rustfmt.el') diff --git a/rust-rustfmt.el b/rust-rustfmt.el index 0690b84..530abaa 100644 --- a/rust-rustfmt.el +++ b/rust-rustfmt.el @@ -331,9 +331,11 @@ Return the created process." ;; If emacs version >= 26.2, we can use replace-buffer-contents to ;; preserve location and markers in buffer, otherwise we can try to ;; save locations as best we can, though we still lose markers. - (if (version<= "26.2" emacs-version) - (rust--format-buffer-using-replace-buffer-contents) - (rust--format-buffer-saving-position-manually))) + (save-excursion + (save-window-excursion + (if (version<= "26.2" emacs-version) + (rust--format-buffer-using-replace-buffer-contents) + (rust--format-buffer-saving-position-manually))))) (defun rust-enable-format-on-save () "Enable formatting using rustfmt when saving buffer." -- cgit v1.2.3