[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/rust-mode f73f321 264/486: Merge pull request #163 from Wi
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/rust-mode f73f321 264/486: Merge pull request #163 from Wilfred/preserve_point_rustfmt |
Date: |
Sat, 7 Aug 2021 09:25:32 -0400 (EDT) |
branch: elpa/rust-mode
commit f73f3217b24f0fb261d09c4e58a0416a42c82c77
Merge: ba5ff90 2540d7e
Author: Niko Matsakis <niko@alum.mit.edu>
Commit: GitHub <noreply@github.com>
Merge pull request #163 from Wilfred/preserve_point_rustfmt
Correctly restore point position after running rustfmt
---
rust-mode-tests.el | 12 ++++++++++++
rust-mode.el | 17 ++++++++++++-----
2 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/rust-mode-tests.el b/rust-mode-tests.el
index 1e60768..3c3ba03 100644
--- a/rust-mode-tests.el
+++ b/rust-mode-tests.el
@@ -2561,6 +2561,18 @@ Fontification needs to include this whole string or none
of it.
)
)
+(ert-deftest rust-test-revert-hook-preserves-point ()
+ (with-temp-buffer
+ ;; Insert some code, and put point in the middle.
+ (insert "fn foo() {}\n")
+ (insert "fn bar() {}\n")
+ (insert "fn baz() {}\n")
+ (goto-char (point-min))
+ (forward-line 1)
+ (let ((initial-point (point)))
+ (rust--after-revert-hook)
+ (should (equal initial-point (point))))))
+
;; If electric-pair-mode is available, load it and run the tests that use it.
If not,
;; no error--the tests will be skipped.
(require 'elec-pair nil t)
diff --git a/rust-mode.el b/rust-mode.el
index 6259b48..99e4bb4 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -1270,10 +1270,16 @@ This is written mainly to be used as
`end-of-defun-function' for Rust."
(unless (executable-find rust-rustfmt-bin)
(error "Could not locate executable \"%s\"" rust-rustfmt-bin))
- (let ((cur-point (point))
+ (let ((cur-line (line-number-at-pos))
+ (cur-column (current-column))
(cur-win-start (window-start)))
(rust--format-call (current-buffer))
- (goto-char cur-point)
+ ;; Move to the same line and column as before. This is best
+ ;; effort: if rustfmt inserted lines before point, we end up in
+ ;; the wrong place. See issue #162.
+ (goto-char (point-min))
+ (forward-line (1- cur-line))
+ (forward-char cur-column)
(set-window-start (selected-window) cur-win-start))
;; Issue #127: Running this on a buffer acts like a revert, and could cause
@@ -1365,9 +1371,10 @@ This is written mainly to be used as
`end-of-defun-function' for Rust."
;; to use `font-lock-ensure', which doesn't exist in Emacs 24 and earlier.
;; If it's not available, fall back to calling `font-lock-fontify-region'
;; on the whole buffer.
- (if (fboundp 'font-lock-ensure)
- (font-lock-ensure)
- (font-lock-fontify-region (point-min) (point-max))))
+ (save-excursion
+ (if (fboundp 'font-lock-ensure)
+ (font-lock-ensure)
+ (font-lock-fontify-region (point-min) (point-max)))))
(defun rust--before-save-hook ()
(when rust-format-on-save (rust-format-buffer)))
- [nongnu] elpa/rust-mode 92584c3 209/486: Fix the special case for the first line, (continued)
- [nongnu] elpa/rust-mode 92584c3 209/486: Fix the special case for the first line, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode b76e803 208/486: Correctly indent where clauses, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 304ae4b 219/486: Change font-lock face for module names., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode ae49380 221/486: Merge pull request #121 from fbergroth/integrate-rustfmt, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 315cc59 233/486: Re-indent on }, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode bc77e16 240/486: remove emacs 23 support, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 620d718 257/486: Fix #160, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode cffb950f2 258/486: [master] Remove redundant progn., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode b3b0f78 259/486: Merge pull request #161 from Fanael/master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode ba5ff90 260/486: Merge pull request #159 from hotpxl/master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode f73f321 264/486: Merge pull request #163 from Wilfred/preserve_point_rustfmt,
ELPA Syncer <=
- [nongnu] elpa/rust-mode cc59c83 270/486: Recognize imenu items starting with "unsafe", ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode fba7714 271/486: Handle comments when indenting method chains, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 7b32066 032/486: rust-mode.el uses the 'cl macros, so it should actually require them, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 2e671d9 040/486: revisions to emacs compilation regexp, more readable and robust., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 1962971 044/486: Correct indent with trailing spaces/comments on previous line, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode f0e4edc 001/486: Move emacs mode into tree, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 6aa0a91 002/486: rust-mode: tag -> enum. Closes #1577, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 3dbae26 008/486: Remove "iface" from vim and emacs modes., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode d0d3911 007/486: For #2229, recognize 'again' in place of 'cont', final change pending snapshot., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 50e55e4 012/486: Add 'static' to rust-mode.el., ELPA Syncer, 2021/08/07