branch: elpa/rust-mode
commit 131cebba67c27ca5b632b80a49a5568be39a10a7
Author: Micah Chalmer <[email protected]>
Commit: Micah Chalmer <[email protected]>
Fix regression of multi-line statement indents
---
rust-mode-tests.el | 12 ++++++++++++
rust-mode.el | 47 ++++++++++++++++++++++++-----------------------
2 files changed, 36 insertions(+), 23 deletions(-)
diff --git a/rust-mode-tests.el b/rust-mode-tests.el
index a7cb261..ac5b1b1 100644
--- a/rust-mode-tests.el
+++ b/rust-mode-tests.el
@@ -378,3 +378,15 @@ fn nexted_fns(a: fn(b:int,
}
"
))
+
+(ert-deftest indent-multi-line-expr ()
+ (test-indent
+ "
+fn foo()
+{
+ x();
+ let a =
+ b();
+}
+"
+))
diff --git a/rust-mode.el b/rust-mode.el
index e809a34..a61d916 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -48,13 +48,12 @@
(if (/= starting (point))
(rust-rewind-irrelevant))))
-(defun rust-first-indent-after-brace ()
+(defun rust-align-to-expr-after-brace ()
(save-excursion
(forward-char)
- (if (looking-at "[[:blank:]]*\\(?://.*\\)?$")
- ;; We don't want to indent out to the open bracket if the
- ;; open bracket ends the line
- (* rust-indent-offset (rust-paren-level))
+ ;; We don't want to indent out to the open bracket if the
+ ;; open bracket ends the line
+ (when (not (looking-at "[[:blank:]]*\\(?://.*\\)?$"))
(when (looking-at "[[:space:]]") (forward-to-word 1))
(current-column))))
@@ -69,7 +68,8 @@
((looking-at "->")
(save-excursion
(backward-list)
- (rust-first-indent-after-brace)))
+ (or (rust-align-to-expr-after-brace)
+ (* rust-indent-offset (+ 1 level)))))
;; A closing brace is 1 level unindended
((looking-at "}") (* rust-indent-offset (- level 1)))
@@ -91,24 +91,25 @@
(let ((pt (point)))
(rust-rewind-irrelevant)
(backward-up-list)
- (if (looking-at "[[({]")
- (rust-first-indent-after-brace)
- (progn
- (goto-char pt)
- (back-to-indentation)
- (if (looking-at "\\<else\\>")
- (* rust-indent-offset (+ 1 level))
- (progn
- (goto-char pt)
- (beginning-of-line)
- (rust-rewind-irrelevant)
- (end-of-line)
- (if (looking-back "[[,;{}(][[:space:]]*\\(?://.*\\)?")
- (* rust-indent-offset level)
- (back-to-indentation)
- (if (looking-at "#")
+ (or (and (looking-at "[[({]")
+ (rust-align-to-expr-after-brace))
+ (progn
+ (goto-char pt)
+ (back-to-indentation)
+ (if (looking-at "\\<else\\>")
+ (* rust-indent-offset (+ 1 level))
+ (progn
+ (goto-char pt)
+ (beginning-of-line)
+ (rust-rewind-irrelevant)
+ (end-of-line)
+ (if (looking-back
+ "[[,;{}(][[:space:]]*\\(?://.*\\)?")
(* rust-indent-offset level)
- (* rust-indent-offset (+ 1 level))))))))))
+ (back-to-indentation)
+ (if (looking-at "#")
+ (* rust-indent-offset level)
+ (* rust-indent-offset (+ 1 level))))))))))
;; Otherwise we're in a column-zero definition
(t 0))))))