Skip to content

Commit c92459a

Browse files
committed
---
yaml --- r: 104566 b: refs/heads/try c: 45008f9 h: refs/heads/master v: v3
1 parent 1886467 commit c92459a

File tree

3 files changed

+75
-10
lines changed

3 files changed

+75
-10
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 62f1d68439dcfd509eaca29887afa97f22938373
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 6e7f170fedd3c526a643c0b2d13863acd982be02
5-
refs/heads/try: 7fbcda1c655736ec5bc058c25c6e720030ee039e
5+
refs/heads/try: 45008f9b3e455d8d9619238e6a0c1981ffaf2860
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/etc/emacs/rust-mode-tests.el

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,26 @@ struct Foo {
488488
}
489489
"
490490
rust-test-region-string rust-test-motion-string
491+
rust-test-indent-motion-string
492+
"
493+
fn blank_line(arg:int) -> bool {
494+
495+
}
496+
497+
fn indenting_closing_brace() {
498+
if(true) {
499+
}
500+
}
501+
502+
fn indenting_middle_of_line() {
503+
if(true) {
504+
push_me_out();
505+
} else {
506+
pull_me_back_in();
507+
}
508+
}
509+
"
510+
491511
;; Symbol -> (line column)
492512
rust-test-positions-alist '((start-of-fn1 (2 0))
493513
(start-of-fn1-middle-of-line (2 15))
@@ -502,7 +522,17 @@ struct Foo {
502522
(middle-of-fn3 (16 4))
503523
(middle-of-struct (21 10))
504524
(before-start-of-struct (19 0))
505-
(after-end-of-struct (23 0))))
525+
(after-end-of-struct (23 0))
526+
(blank-line-indent-start (3 0))
527+
(blank-line-indent-target (3 4))
528+
(closing-brace-indent-start (8 1))
529+
(closing-brace-indent-target (8 5))
530+
(middle-push-indent-start (13 2))
531+
(middle-push-indent-target (13 9))
532+
(after-whitespace-indent-start (13 1))
533+
(after-whitespace-indent-target (13 8))
534+
(middle-pull-indent-start (15 19))
535+
(middle-pull-indent-target (15 12))))
506536

507537
(defun rust-get-buffer-pos (pos-symbol)
508538
"Get buffer position from POS-SYMBOL.
@@ -664,3 +694,38 @@ All positions are position symbols found in `rust-test-positions-alist'."
664694
'middle-of-struct
665695
'before-start-of-struct 'after-end-of-struct
666696
#'mark-defun))
697+
698+
(ert-deftest indent-line-blank-line-motion ()
699+
(rust-test-motion
700+
rust-test-indent-motion-string
701+
'blank-line-indent-start
702+
'blank-line-indent-target
703+
#'indent-for-tab-command))
704+
705+
(ert-deftest indent-line-closing-brace-motion ()
706+
(rust-test-motion
707+
rust-test-indent-motion-string
708+
'closing-brace-indent-start
709+
'closing-brace-indent-target
710+
#'indent-for-tab-command))
711+
712+
(ert-deftest indent-line-middle-push-motion ()
713+
(rust-test-motion
714+
rust-test-indent-motion-string
715+
'middle-push-indent-start
716+
'middle-push-indent-target
717+
#'indent-for-tab-command))
718+
719+
(ert-deftest indent-line-after-whitespace-motion ()
720+
(rust-test-motion
721+
rust-test-indent-motion-string
722+
'after-whitespace-indent-start
723+
'after-whitespace-indent-target
724+
#'indent-for-tab-command))
725+
726+
(ert-deftest indent-line-middle-pull-motion ()
727+
(rust-test-motion
728+
rust-test-indent-motion-string
729+
'middle-pull-indent-start
730+
'middle-pull-indent-target
731+
#'indent-for-tab-command))

branches/try/src/etc/emacs/rust-mode.el

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,14 @@
114114

115115
;; Otherwise we're in a column-zero definition
116116
(t 0))))))
117-
(cond
118-
;; If we're to the left of the indentation, reindent and jump to it.
119-
((<= (current-column) indent)
120-
(indent-line-to indent))
121-
122-
;; We're to the right; if it needs indent, do so but save excursion.
123-
((not (eq (current-indentation) indent))
124-
(save-excursion (indent-line-to indent))))))
117+
(when (not (eq (current-indentation) indent))
118+
;; If we're at the beginning of the line (before or at the current
119+
;; indentation), jump with the indentation change. Otherwise, save the
120+
;; excursion so that adding the indentations will leave us at the
121+
;; equivalent position within the line to where we were before.
122+
(if (<= (current-column) (current-indentation))
123+
(indent-line-to indent)
124+
(save-excursion (indent-line-to indent))))))
125125

126126

127127
;; Font-locking definitions and helpers

0 commit comments

Comments
 (0)