Skip to content

Commit a388aee

Browse files
authored
Merge pull request #351 from elixir-lang/multi-function-indent
fix indentation when following previous end block
2 parents b418436 + 4ddbdde commit a388aee

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

autoload/elixir/indent.vim

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ function! elixir#indent#indent(lnum)
2222
\'starts_with_binary_operator',
2323
\'inside_nested_construct',
2424
\'starts_with_comment',
25-
\'inside_generic_block'
25+
\'inside_generic_block',
26+
\'following_prev_end'
2627
\]
2728
for handler in handlers
2829
call s:debug('testing handler elixir#indent#handle_'.handler)
@@ -157,6 +158,14 @@ function! elixir#indent#handle_following_trailing_binary_operator(lnum, text, pr
157158
endif
158159
endfunction
159160

161+
function! elixir#indent#handle_following_prev_end(_lnum, _text, prev_nb_lnum, prev_nb_text)
162+
if s:ends_with(a:prev_nb_text, s:keyword('end'), a:prev_nb_lnum)
163+
return indent(a:prev_nb_lnum)
164+
else
165+
return -1
166+
endif
167+
endfunction
168+
160169
function! elixir#indent#handle_starts_with_pipe(lnum, text, prev_nb_lnum, prev_nb_text)
161170
if s:starts_with(a:text, '|>', a:lnum)
162171
let match_operator = '\%(!\|=\|<\|>\)\@<!=\%(=\|>\|\~\)\@!'

spec/indent/def_spec.rb

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,60 @@ def handle_call({:release_lock, key}, _from, state) do
1515
1616
def
1717
EOF
18+
19+
i <<~EOF
20+
defmodule HiMom do
21+
def hi do
22+
puts "hi"
23+
end
24+
25+
26+
27+
28+
29+
30+
31+
32+
33+
34+
35+
36+
37+
38+
39+
40+
41+
42+
43+
44+
45+
46+
47+
48+
49+
50+
51+
52+
53+
54+
55+
56+
57+
58+
59+
60+
61+
62+
63+
64+
65+
66+
67+
68+
69+
def mom do
70+
puts "mom"
71+
end
72+
end
73+
EOF
1874
end

0 commit comments

Comments
 (0)