[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/rust-mode 2d12c3e 072/486: Emacs: always jump the cursor i
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/rust-mode 2d12c3e 072/486: Emacs: always jump the cursor if needed on indent |
Date: |
Sat, 7 Aug 2021 09:24:51 -0400 (EDT) |
branch: elpa/rust-mode
commit 2d12c3ed21b581d44376d8f068ddfdaad4a901e9
Author: Micah Chalmer <micah@micahchalmer.net>
Commit: Alex Crichton <alex@alexcrichton.com>
Emacs: always jump the cursor if needed on indent
The rust-mode-indent-line function had a check, which ran after all the
calculations for how to indent had already happened, that skipped
actually performing the indent if the line was already at the right
indentation.
Because of that, the cursor did not jump to the indentation if the line
wasn't changing. This was particularly annoying if there was nothing
but spaces on the line and you were at the beginning of it--it looked
like the indent just wasn't working.
This removes the check and adds test cases to cover this.
---
rust-mode-tests.el | 43 ++++++++++++++++++++++++++++++++++++++++++-
rust-mode.el | 16 ++++++++--------
2 files changed, 50 insertions(+), 9 deletions(-)
diff --git a/rust-mode-tests.el b/rust-mode-tests.el
index 63c1a07..a4e8379 100644
--- a/rust-mode-tests.el
+++ b/rust-mode-tests.el
@@ -570,6 +570,11 @@ fn indenting_middle_of_line() {
pull_me_back_in();
}
}
+
+fn indented_already() {
+
+ // The previous line already has its spaces
+}
"
;; Symbol -> (line column)
@@ -596,7 +601,15 @@ fn indenting_middle_of_line() {
(after-whitespace-indent-start (13 1))
(after-whitespace-indent-target (13 8))
(middle-pull-indent-start (15 19))
- (middle-pull-indent-target (15 12))))
+ (middle-pull-indent-target (15 12))
+ (blank-line-indented-already-bol-start (20
0))
+ (blank-line-indented-already-bol-target (20
4))
+ (blank-line-indented-already-middle-start
(20 2))
+ (blank-line-indented-already-middle-target
(20 4))
+ (nonblank-line-indented-already-bol-start
(21 0))
+ (nonblank-line-indented-already-bol-target
(21 4))
+ (nonblank-line-indented-already-middle-start
(21 2))
+
(nonblank-line-indented-already-middle-target (21 4))))
(defun rust-get-buffer-pos (pos-symbol)
"Get buffer position from POS-SYMBOL.
@@ -793,3 +806,31 @@ All positions are position symbols found in
`rust-test-positions-alist'."
'middle-pull-indent-start
'middle-pull-indent-target
#'indent-for-tab-command))
+
+(ert-deftest indent-line-blank-line-indented-already-bol ()
+ (rust-test-motion
+ rust-test-indent-motion-string
+ 'blank-line-indented-already-bol-start
+ 'blank-line-indented-already-bol-target
+ #'indent-for-tab-command))
+
+(ert-deftest indent-line-blank-line-indented-already-middle ()
+ (rust-test-motion
+ rust-test-indent-motion-string
+ 'blank-line-indented-already-middle-start
+ 'blank-line-indented-already-middle-target
+ #'indent-for-tab-command))
+
+(ert-deftest indent-line-nonblank-line-indented-already-bol ()
+ (rust-test-motion
+ rust-test-indent-motion-string
+ 'nonblank-line-indented-already-bol-start
+ 'nonblank-line-indented-already-bol-target
+ #'indent-for-tab-command))
+
+(ert-deftest indent-line-nonblank-line-indented-already-middle ()
+ (rust-test-motion
+ rust-test-indent-motion-string
+ 'nonblank-line-indented-already-middle-start
+ 'nonblank-line-indented-already-middle-target
+ #'indent-for-tab-command))
diff --git a/rust-mode.el b/rust-mode.el
index b304df8..3a99af3 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -140,14 +140,14 @@
;; Otherwise, we are continuing the same expression from
the previous line,
;; so add one additional indent level
(+ baseline rust-indent-offset))))))))))
- (when (not (eq (current-indentation) indent))
- ;; If we're at the beginning of the line (before or at the current
- ;; indentation), jump with the indentation change. Otherwise, save the
- ;; excursion so that adding the indentations will leave us at the
- ;; equivalent position within the line to where we were before.
- (if (<= (current-column) (current-indentation))
- (indent-line-to indent)
- (save-excursion (indent-line-to indent))))))
+
+ ;; If we're at the beginning of the line (before or at the current
+ ;; indentation), jump with the indentation change. Otherwise, save the
+ ;; excursion so that adding the indentations will leave us at the
+ ;; equivalent position within the line to where we were before.
+ (if (<= (current-column) (current-indentation))
+ (indent-line-to indent)
+ (save-excursion (indent-line-to indent)))))
;; Font-locking definitions and helpers
- [nongnu] elpa/rust-mode 0a81930 041/486: extend file regexp to match files with embedded spaces., (continued)
- [nongnu] elpa/rust-mode 0a81930 041/486: extend file regexp to match files with embedded spaces., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 6a6dc4e 042/486: fix typo in rust-mode.el, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 5b34e59 053/486: Add paragraph fill and auto-fill for multi-line comments, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 69811ea 052/486: Add custom group for rust-mode, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 0bf2920 048/486: Fix glitches with struct field aligned indents, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode d6b2c32 060/486: Add Imenu support for rust-mode., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 131cebb 055/486: Fix regression of multi-line statement indents, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode b5de342 070/486: Fix typo in emacs ERT test, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode fa51087 057/486: Minor cleanup and formatting tweaks to the rust-mode README, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 4e0a334 081/486: emacs: do not highlight `#foo]` as an attribute, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 2d12c3e 072/486: Emacs: always jump the cursor if needed on indent,
ELPA Syncer <=
- [nongnu] elpa/rust-mode 5ebe4c7 080/486: emacs: highlight `macro_name!` in macro invocations using [] delimiters, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 76bcb8d 074/486: etc: attempts at fixing editor highlighting for new attribute syntax, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode a59ef8e 090/486: Fix spelling mistakes in comments., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 9c0846a 101/486: Add test for '\'' single quote char literal, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 55080f6 100/486: Fix syntax and highlighting for char literals, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 8a69f69 104/486: Use old code style for emacs 23 compat, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 9e83b30 110/486: Merge pull request #21 from pnkfelix/tests-allow-override-of-which-emacs, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 55e7483 113/486: Add a hook so that we briefly highlight the matching `<` when `>` is typed., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 439da40 115/486: disable emacs23 testing on travis., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode d2c6d6c 116/486: Merge pull request #26 from pnkfelix/disable-emacs23-testing, ELPA Syncer, 2021/08/07