[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/rust-mode 0800660 068/486: Emacs: stay at the correct posi
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/rust-mode 0800660 068/486: Emacs: stay at the correct position when indenting |
Date: |
Sat, 7 Aug 2021 09:24:50 -0400 (EDT) |
branch: elpa/rust-mode
commit 08006607ab96e1b4bdfd12ddb43d143d28763e76
Author: Micah Chalmer <micah@micahchalmer.net>
Commit: Micah Chalmer <micah@micahchalmer.net>
Emacs: stay at the correct position when indenting
When indenting a non-blank line, stay at the same cursor position
relative to the content after indenting.
---
rust-mode-tests.el | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
rust-mode.el | 16 ++++++-------
2 files changed, 74 insertions(+), 9 deletions(-)
diff --git a/rust-mode-tests.el b/rust-mode-tests.el
index e8be519..c0543b6 100644
--- a/rust-mode-tests.el
+++ b/rust-mode-tests.el
@@ -488,6 +488,26 @@ struct Foo {
}
"
rust-test-region-string rust-test-motion-string
+ rust-test-indent-motion-string
+ "
+fn blank_line(arg:int) -> bool {
+
+}
+
+fn indenting_closing_brace() {
+ if(true) {
+}
+}
+
+fn indenting_middle_of_line() {
+ if(true) {
+ push_me_out();
+} else {
+ pull_me_back_in();
+}
+}
+"
+
;; Symbol -> (line column)
rust-test-positions-alist '((start-of-fn1 (2 0))
(start-of-fn1-middle-of-line (2 15))
@@ -502,7 +522,17 @@ struct Foo {
(middle-of-fn3 (16 4))
(middle-of-struct (21 10))
(before-start-of-struct (19 0))
- (after-end-of-struct (23 0))))
+ (after-end-of-struct (23 0))
+ (blank-line-indent-start (3 0))
+ (blank-line-indent-target (3 4))
+ (closing-brace-indent-start (8 1))
+ (closing-brace-indent-target (8 5))
+ (middle-push-indent-start (13 2))
+ (middle-push-indent-target (13 9))
+ (after-whitespace-indent-start (13 1))
+ (after-whitespace-indent-target (13 8))
+ (middle-pull-indent-start (15 19))
+ (middle-pull-indent-target (15 12))))
(defun rust-get-buffer-pos (pos-symbol)
"Get buffer position from POS-SYMBOL.
@@ -664,3 +694,38 @@ All positions are position symbols found in
`rust-test-positions-alist'."
'middle-of-struct
'before-start-of-struct 'after-end-of-struct
#'mark-defun))
+
+(ert-deftest indent-line-blank-line-motion ()
+ (rust-test-motion
+ rust-test-indent-motion-string
+ 'blank-line-indent-start
+ 'blank-line-indent-target
+ #'indent-for-tab-command))
+
+(ert-deftest indent-line-closing-brace-motion ()
+ (rust-test-motion
+ rust-test-indent-motion-string
+ 'closing-brace-indent-start
+ 'closing-brace-indent-target
+ #'indent-for-tab-command))
+
+(ert-deftest indent-line-middle-push-motion ()
+ (rust-test-motion
+ rust-test-indent-motion-string
+ 'middle-push-indent-start
+ 'middle-push-indent-target
+ #'indent-for-tab-command))
+
+(ert-deftest indent-line-after-whitespace-motion ()
+ (rust-test-motion
+ rust-test-indent-motion-string
+ 'after-whitespace-indent-start
+ 'after-whitespace-indent-target
+ #'indent-for-tab-command))
+
+(ert-deftest indent-line-middle-pull-motion ()
+ (rust-test-motion
+ rust-test-indent-motion-string
+ 'middle-pull-indent-start
+ 'middle-pull-indent-target
+ #'indent-for-tab-command))
diff --git a/rust-mode.el b/rust-mode.el
index 988b869..a2e1fc0 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -114,14 +114,14 @@
;; Otherwise we're in a column-zero definition
(t 0))))))
- (cond
- ;; If we're to the left of the indentation, reindent and jump to it.
- ((<= (current-column) indent)
- (indent-line-to indent))
-
- ;; We're to the right; if it needs indent, do so but save excursion.
- ((not (eq (current-indentation) indent))
- (save-excursion (indent-line-to indent))))))
+ (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))))))
;; Font-locking definitions and helpers
- [nongnu] elpa/rust-mode 8cd18cc 385/486: Merge pull request #293 from TristanCacqueray/master, (continued)
- [nongnu] elpa/rust-mode 8cd18cc 385/486: Merge pull request #293 from TristanCacqueray/master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode df31a6e 393/486: Don't call syntax-ppss twice for strings ending with r., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 942d465 398/486: Update Debian installation instructions, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode af84c0f 403/486: Merge pull request #319 from phillord/feature/update-emacs-versions, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 4c8754b 430/486: Merge pull request #343 from haroldcarr/master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 4381a89 433/486: Fix scrolling after rustfmt. (#351), ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 2a8ca9e 443/486: rust-format-show-buffer: default to true., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 15d31a9 013/486: removed a comma from the keyword list to get, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode e39142b 033/486: Allow customization of indent offset, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 8dc92b2 073/486: Update emacs mode to support new `#![inner(attribute)]` syntax., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 0800660 068/486: Emacs: stay at the correct position when indenting,
ELPA Syncer <=
- [nongnu] elpa/rust-mode bc78d17 075/486: rust-mode cleanup., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 5e34201 061/486: Add defun motions for rust-mode., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 0e58eb3 076/486: emacs: Add 'box' to keywords, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 226102c 086/486: emacs: Add shebang to test script, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 186583d 096/486: Mark _ as a word constituent to avoid highlighting parts of identifiers as keywords, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 04e4b49 103/486: Add .travis.yml, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode ec81a95 114/486: Merge pull request #22 from nikomatsakis/align-method-chain, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 351cc91 112/486: Merge pull request #16 from MicahChalmer/add-travis, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode b3f87b9 122/486: Make the test driver script a little more informative., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 19bc0e9 121/486: Merge pull request #30 from MicahChalmer/emacs23-fixup, ELPA Syncer, 2021/08/07