[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/rust-mode 2540d7e 262/486: Go back to the current line and
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/rust-mode 2540d7e 262/486: Go back to the current line and column after formatting. |
Date: |
Sat, 7 Aug 2021 09:25:32 -0400 (EDT) |
branch: elpa/rust-mode
commit 2540d7eff0faa7e966b6c4391e53617800275f85
Author: Wilfred Hughes <me@wilfred.me.uk>
Commit: Wilfred Hughes <me@wilfred.me.uk>
Go back to the current line and column after formatting.
The previous approach simply moved to the same character offset. This is
unlikely to preserve the position of point, as rustfmt often changes
whitespace, changing the number of characters before point.
Instead, we go back to the line number and column number we were on
before. Provided that rustfmt has not radically changed the number of
lines, this will typically put point back to its previous position, or
at least close.
Improves, but doesn't completely solve, issue #162.
---
rust-mode.el | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/rust-mode.el b/rust-mode.el
index 1fbc3e8..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
- [nongnu] elpa/rust-mode 5231709 177/486: Speed up calls to "looking-back", (continued)
- [nongnu] elpa/rust-mode 5231709 177/486: Speed up calls to "looking-back", ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode c801dda 197/486: Merge pull request #77 from tromey/fix-byte-compiler-add-lexbind, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode cdaf3fc 201/486: Update MELPA URL, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 1761a9c 204/486: Merge pull request #105 from MicahChalmer/remove-misc, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode f8d94cb 229/486: Use catch and throw instead of block and return, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 40c33fd 250/486: add code to handle new-style rustc errors, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode c69adaf 254/486: Add menu titles for items in imenu, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode dae5af7 298/486: Merge pull request #198 from tromey/indentation-fix, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode bfe4056 452/486: Re-implement rust-in-macro for performance, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode eaf95af 210/486: Merge pull request #111 from mrBliss/where-indentation, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 2540d7e 262/486: Go back to the current line and column after formatting.,
ELPA Syncer <=
- [nongnu] elpa/rust-mode 52870b6 203/486: Remove unused require of misc.el, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 95d089c 211/486: Merge pull request #110 from mrBliss/fix-103, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 00e5366 224/486: Merge pull request #122 from kraai/remove-duplicate-keywords, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 0601540 205/486: Merge pull request #96 from MicahChalmer/add-licenses, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 1492106 232/486: Fix hook args for after-revert-hook, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 2f42da8 228/486: Add rust-promote-module-into-dir, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 0914b48 234/486: Merge pull request #133 from kraai/avoid-cl, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 917503b 244/486: Fix failing tests, and add a test for the fix., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode a8a5e14 245/486: Fix for emacs24, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode ed0b390 246/486: Merge pull request #148 from bmastenbrook/master, ELPA Syncer, 2021/08/07