branch: elpa/rust-mode
commit bee96e838de53fa7aee7cfc9ea689fcad3816725
Author: Micah Chalmer <[email protected]>
Commit: Micah Chalmer <[email protected]>
Fix emacs indentation of multi-line match patterns
Aligns to the same column if the previous line ends in a single '|' (but
not a '||').
---
rust-mode-tests.el | 38 ++++++++++++++++++++++++++++++++++++++
rust-mode.el | 5 ++---
2 files changed, 40 insertions(+), 3 deletions(-)
diff --git a/rust-mode-tests.el b/rust-mode-tests.el
index 524d474..e8be519 100644
--- a/rust-mode-tests.el
+++ b/rust-mode-tests.el
@@ -425,6 +425,44 @@ fn foo()
"
))
+(ert-deftest indent-match ()
+ (test-indent
+ "
+fn foo() {
+ match blah {
+ Pattern => stuff(),
+ _ => whatever
+ }
+}
+"
+ ))
+
+(ert-deftest indent-match-multiline-pattern ()
+ (test-indent
+ "
+fn foo() {
+ match blah {
+ Pattern |
+ Pattern2 => {
+ hello()
+ },
+ _ => whatever
+ }
+}
+"
+ ))
+
+;; Make sure that in effort to cover match patterns we don't mistreat || or
expressions
+(ert-deftest indent-nonmatch-or-expression ()
+ (test-indent
+ "
+fn foo() {
+ let x = foo() ||
+ bar();
+}
+"
+ ))
+
(setq rust-test-motion-string
"
fn fn1(arg: int) -> bool {
diff --git a/rust-mode.el b/rust-mode.el
index 4e1c74c..988b869 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -85,7 +85,7 @@
;; - { means indent to either nesting-level *
rust-indent-offset,
;; or one further indent from that if either current line
;; begins with 'else', or previous line didn't end in
- ;; semi, comma or brace (other than whitespace and line
+ ;; semi, comma, brace or single pipe (other than whitespace
and line
;; comments) , and wasn't an attribute. But if we have
;; something after the open brace and ending with a comma,
;; treat it as fields and align them. PHEW.
@@ -105,8 +105,7 @@
(beginning-of-line)
(rust-rewind-irrelevant)
(end-of-line)
- (if (looking-back
- "[[,;{}(][[:space:]]*\\(?://.*\\)?")
+ (if (looking-back
"\\(?:[(,:;?[{}]\\|[^|]|\\)[[:space:]]*\\(?://.*\\)?")
(* rust-indent-offset level)
(back-to-indentation)
(if (looking-at "#")