diff options
Diffstat (limited to 'autoload/elixir')
-rw-r--r-- | autoload/elixir/indent.vim | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/autoload/elixir/indent.vim b/autoload/elixir/indent.vim index 4a8b5435..aca5a2fd 100644 --- a/autoload/elixir/indent.vim +++ b/autoload/elixir/indent.vim @@ -18,11 +18,15 @@ function! elixir#indent#indent(lnum) call s:debug("==> Indenting line " . lnum) call s:debug("text = '" . text . "'") + let [_, curs_lnum, curs_col, _] = getpos('.') + call cursor(lnum, 0) + let handlers = [ \'top_of_file', \'starts_with_end', \'starts_with_mid_or_end_block_keyword', \'following_trailing_do', + \'following_trailing_rocket', \'following_trailing_binary_operator', \'starts_with_pipe', \'starts_with_close_bracket', @@ -37,11 +41,13 @@ function! elixir#indent#indent(lnum) let indent = function('elixir#indent#handle_'.handler)(lnum, text, prev_nb_lnum, prev_nb_text) if indent != -1 call s:debug('line '.lnum.': elixir#indent#handle_'.handler.' returned '.indent) + call cursor(curs_lnum, curs_col) return indent endif endfor call s:debug("defaulting") + call cursor(curs_lnum, curs_col) return 0 endfunction @@ -166,7 +172,7 @@ function! s:get_base_indent(lnum, text) elseif s:ends_with(a:text, data_structure_close, a:lnum) let data_structure_open = '\%(\[\|{\|(\)' let close_match_idx = match(a:text, data_structure_close . '\s*$') - let _move = cursor(a:lnum, close_match_idx + 1) + call cursor(a:lnum, close_match_idx + 1) let [open_match_lnum, open_match_col] = searchpairpos(data_structure_open, '', data_structure_close, 'bnW') let open_match_text = getline(open_match_lnum) return s:get_base_indent(open_match_lnum, open_match_text) @@ -175,7 +181,6 @@ function! s:get_base_indent(lnum, text) endif endfunction -" TODO: @jbodah 2017-03-31: remove function! elixir#indent#handle_following_trailing_do(lnum, text, prev_nb_lnum, prev_nb_text) if s:ends_with(a:prev_nb_text, s:keyword('do'), a:prev_nb_lnum) if s:starts_with(a:text, s:keyword('end'), a:lnum) @@ -188,6 +193,14 @@ function! elixir#indent#handle_following_trailing_do(lnum, text, prev_nb_lnum, p endif endfunction +function! elixir#indent#handle_following_trailing_rocket(lnum, text, prev_nb_lnum, prev_nb_text) + if s:ends_with(a:prev_nb_text, '->', a:prev_nb_lnum) + return indent(a:prev_nb_lnum) + s:sw() + else + return -1 + endif +endfunction + function! elixir#indent#handle_following_trailing_binary_operator(lnum, text, prev_nb_lnum, prev_nb_text) let binary_operator = '\%(=\|<>\|>>>\|<=\|||\|+\|\~\~\~\|-\|&&\|<<<\|/\|\^\^\^\|\*\)' |