@@ -28,7 +28,7 @@ function! elixir#indent#indent(lnum)
28
28
\' inside_nested_construct',
29
29
\' starts_with_comment',
30
30
\' inside_generic_block',
31
- \' following_prev_end '
31
+ \' follow_prev_nb '
32
32
\]
33
33
for handler in handlers
34
34
call s: debug (' testing handler elixir#indent#handle_' .handler)
@@ -140,6 +140,39 @@ function! elixir#indent#handle_top_of_file(_lnum, _text, prev_nb_lnum, _prev_nb_
140
140
end
141
141
endfunction
142
142
143
+ function ! elixir#indent#handle_follow_prev_nb (_lnum, _text, prev_nb_lnum, prev_nb_text)
144
+ return s: get_base_indent (a: prev_nb_lnum , a: prev_nb_text )
145
+ endfunction
146
+
147
+ " Given the line at `lnum`, returns the indent of the line that acts as the 'base indent'
148
+ " for this line. In particular it traverses backwards up things like pipelines
149
+ " to find the beginning of the expression
150
+ function ! s: get_base_indent (lnum, text)
151
+ let prev_nb_lnum = prevnonblank (a: lnum - 1 )
152
+ let prev_nb_text = getline (prev_nb_lnum)
153
+
154
+ let binary_operator = ' \%(=\|<>\|>>>\|<=\|||\|+\|\~\~\~\|-\|&&\|<<<\|/\|\^\^\^\|\*\)'
155
+ let data_structure_close = ' \%(\]\|}\|)\)'
156
+ let pipe = ' |>'
157
+
158
+ if s: starts_with (a: text , binary_operator, a: lnum )
159
+ return s: get_base_indent (prev_nb_lnum, prev_nb_text)
160
+ elseif s: starts_with (a: text , pipe, a: lnum )
161
+ return s: get_base_indent (prev_nb_lnum, prev_nb_text)
162
+ elseif s: ends_with (prev_nb_text, binary_operator, prev_nb_lnum)
163
+ return s: get_base_indent (prev_nb_lnum, prev_nb_text)
164
+ elseif s: ends_with (a: text , data_structure_close, a: lnum )
165
+ let data_structure_open = ' \%(\[\|{\|(\)'
166
+ let close_match_idx = match (a: text , data_structure_close . ' \s*$' )
167
+ let _move = cursor (a: lnum , close_match_idx + 1 )
168
+ let [open_match_lnum, open_match_col] = searchpairpos (data_structure_open, ' ' , data_structure_close, ' bnW' )
169
+ let open_match_text = getline (open_match_lnum)
170
+ return s: get_base_indent (open_match_lnum, open_match_text)
171
+ else
172
+ return indent (a: lnum )
173
+ endif
174
+ endfunction
175
+
143
176
" TODO: @jbodah 2017-03-31: remove
144
177
function ! elixir#indent#handle_following_trailing_do (lnum, text, prev_nb_lnum, prev_nb_text)
145
178
if s: ends_with (a: prev_nb_text , s: keyword (' do' ), a: prev_nb_lnum )
0 commit comments