Skip to content

Commit

Permalink
Fix emacs indentation of multi-line match patterns
Browse files Browse the repository at this point in the history
Aligns to the same column if the previous line ends in a single '|' (but
not a '||').
  • Loading branch information
MicahChalmer committed Feb 22, 2014
1 parent 52755b7 commit 7fbcda1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
38 changes: 38 additions & 0 deletions src/etc/emacs/rust-mode-tests.el
Expand Up @@ -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 {
Expand Down
5 changes: 2 additions & 3 deletions src/etc/emacs/rust-mode.el
Expand Up @@ -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.
Expand All @@ -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 "#")
Expand Down

0 comments on commit 7fbcda1

Please sign in to comment.