diff options
| author | Micah Chalmer <micah@micahchalmer.net> | 2014-02-22 02:49:09 -0500 |
|---|---|---|
| committer | Micah Chalmer <micah@micahchalmer.net> | 2014-02-22 13:11:48 -0500 |
| commit | bee96e838de53fa7aee7cfc9ea689fcad3816725 (patch) | |
| tree | 364fc61cc409e98e112f55437cc0209a06a1dc34 | |
| parent | 9672625e8c22fd507a6b36b0c1e8632d31115528 (diff) | |
| download | rust-mode-bee96e838de53fa7aee7cfc9ea689fcad3816725.tar.gz | |
Fix emacs indentation of multi-line match patterns
Aligns to the same column if the previous line ends in a single '|' (but
not a '||').
| -rw-r--r-- | rust-mode-tests.el | 38 | ||||
| -rw-r--r-- | 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 "#") |
