Skip to content

Commit be4f19a

Browse files
committed
Fix regression of multi-line statement indents
1 parent fcf1878 commit be4f19a

File tree

2 files changed

+36
-23
lines changed

2 files changed

+36
-23
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,3 +378,15 @@ fn nexted_fns(a: fn(b:int,
378378
}
379379
"
380380
))
381+
382+
(ert-deftest indent-multi-line-expr ()
383+
(test-indent
384+
"
385+
fn foo()
386+
{
387+
x();
388+
let a =
389+
b();
390+
}
391+
"
392+
))

src/etc/emacs/rust-mode.el

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,12 @@
4848
(if (/= starting (point))
4949
(rust-rewind-irrelevant))))
5050

51-
(defun rust-first-indent-after-brace ()
51+
(defun rust-align-to-expr-after-brace ()
5252
(save-excursion
5353
(forward-char)
54-
(if (looking-at "[[:blank:]]*\\(?://.*\\)?$")
55-
;; We don't want to indent out to the open bracket if the
56-
;; open bracket ends the line
57-
(* rust-indent-offset (rust-paren-level))
54+
;; We don't want to indent out to the open bracket if the
55+
;; open bracket ends the line
56+
(when (not (looking-at "[[:blank:]]*\\(?://.*\\)?$"))
5857
(when (looking-at "[[:space:]]") (forward-to-word 1))
5958
(current-column))))
6059

@@ -69,7 +68,8 @@
6968
((looking-at "->")
7069
(save-excursion
7170
(backward-list)
72-
(rust-first-indent-after-brace)))
71+
(or (rust-align-to-expr-after-brace)
72+
(* rust-indent-offset (+ 1 level)))))
7373

7474
;; A closing brace is 1 level unindended
7575
((looking-at "}") (* rust-indent-offset (- level 1)))
@@ -91,24 +91,25 @@
9191
(let ((pt (point)))
9292
(rust-rewind-irrelevant)
9393
(backward-up-list)
94-
(if (looking-at "[[({]")
95-
(rust-first-indent-after-brace)
96-
(progn
97-
(goto-char pt)
98-
(back-to-indentation)
99-
(if (looking-at "\\<else\\>")
100-
(* rust-indent-offset (+ 1 level))
101-
(progn
102-
(goto-char pt)
103-
(beginning-of-line)
104-
(rust-rewind-irrelevant)
105-
(end-of-line)
106-
(if (looking-back "[[,;{}(][[:space:]]*\\(?://.*\\)?")
107-
(* rust-indent-offset level)
108-
(back-to-indentation)
109-
(if (looking-at "#")
94+
(or (and (looking-at "[[({]")
95+
(rust-align-to-expr-after-brace))
96+
(progn
97+
(goto-char pt)
98+
(back-to-indentation)
99+
(if (looking-at "\\<else\\>")
100+
(* rust-indent-offset (+ 1 level))
101+
(progn
102+
(goto-char pt)
103+
(beginning-of-line)
104+
(rust-rewind-irrelevant)
105+
(end-of-line)
106+
(if (looking-back
107+
"[[,;{}(][[:space:]]*\\(?://.*\\)?")
110108
(* rust-indent-offset level)
111-
(* rust-indent-offset (+ 1 level))))))))))
109+
(back-to-indentation)
110+
(if (looking-at "#")
111+
(* rust-indent-offset level)
112+
(* rust-indent-offset (+ 1 level))))))))))
112113

113114
;; Otherwise we're in a column-zero definition
114115
(t 0))))))

0 commit comments

Comments
 (0)