diff options
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/crystal_lang.vim | 2 | ||||
-rw-r--r-- | autoload/dart.vim | 8 | ||||
-rw-r--r-- | autoload/elixir/indent.vim | 298 | ||||
-rw-r--r-- | autoload/rust.vim | 87 | ||||
-rw-r--r-- | autoload/rustfmt.vim | 141 | ||||
-rw-r--r-- | autoload/xml/html5.vim | 2 |
6 files changed, 326 insertions, 212 deletions
diff --git a/autoload/crystal_lang.vim b/autoload/crystal_lang.vim index 8b1252d2..01244746 100644 --- a/autoload/crystal_lang.vim +++ b/autoload/crystal_lang.vim @@ -310,7 +310,7 @@ function! crystal_lang#format(option_str) abort try call setreg('g', formatted, 'v') - silent normal! ggvG$"gp + silent normal! gg0vG$"gp finally call setreg('g', save_g_reg, save_g_regtype) let &l:selection = sel_save diff --git a/autoload/dart.vim b/autoload/dart.vim index 9f04fcc2..76013172 100644 --- a/autoload/dart.vim +++ b/autoload/dart.vim @@ -24,9 +24,11 @@ function! dart#fmt(q_args) abort let joined_lines = system(printf('dartfmt %s', a:q_args), buffer_content) if 0 == v:shell_error let win_view = winsaveview() - silent % delete _ - silent put=joined_lines - silent 1 delete _ + let lines = split(joined_lines, "\n") + silent keepjumps call setline(1, lines) + if line('$') > len(lines) + silent keepjumps execute string(len(lines)+1).',$ delete' + endif call winrestview(win_view) else let errors = split(joined_lines, "\n")[2:] diff --git a/autoload/elixir/indent.vim b/autoload/elixir/indent.vim index fd2f4a3f..4a8b5435 100644 --- a/autoload/elixir/indent.vim +++ b/autoload/elixir/indent.vim @@ -1,6 +1,51 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'elixir') == -1 -function! elixir#indent#debug(str) +if !exists("g:elixir_indent_max_lookbehind") + let g:elixir_indent_max_lookbehind = 30 +endif + +" Return the effective value of 'shiftwidth' +function! s:sw() + return &shiftwidth == 0 ? &tabstop : &shiftwidth +endfunction + +function! elixir#indent#indent(lnum) + let lnum = a:lnum + let text = getline(lnum) + let prev_nb_lnum = prevnonblank(lnum-1) + let prev_nb_text = getline(prev_nb_lnum) + + call s:debug("==> Indenting line " . lnum) + call s:debug("text = '" . text . "'") + + let handlers = [ + \'top_of_file', + \'starts_with_end', + \'starts_with_mid_or_end_block_keyword', + \'following_trailing_do', + \'following_trailing_binary_operator', + \'starts_with_pipe', + \'starts_with_close_bracket', + \'starts_with_binary_operator', + \'inside_nested_construct', + \'starts_with_comment', + \'inside_generic_block', + \'follow_prev_nb' + \] + for handler in handlers + call s:debug('testing handler elixir#indent#handle_'.handler) + 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) + return indent + endif + endfor + + call s:debug("defaulting") + return 0 +endfunction + +function! s:debug(str) if exists("g:elixir_indent_debug") && g:elixir_indent_debug echom a:str endif @@ -8,14 +53,14 @@ endfunction " Returns 0 or 1 based on whether or not the text starts with the given " expression and is not a string or comment -function! elixir#indent#starts_with(text, expr, lnum) +function! s:starts_with(text, expr, lnum) let pos = match(a:text, '^\s*'.a:expr) if pos == -1 return 0 else " NOTE: @jbodah 2017-02-24: pos is the index of the match which is " zero-indexed. Add one to make it the column number - if elixir#indent#is_string_or_comment(a:lnum, pos + 1) + if s:is_string_or_comment(a:lnum, pos + 1) return 0 else return 1 @@ -25,12 +70,12 @@ endfunction " Returns 0 or 1 based on whether or not the text ends with the given " expression and is not a string or comment -function! elixir#indent#ends_with(text, expr, lnum) +function! s:ends_with(text, expr, lnum) let pos = match(a:text, a:expr.'\s*$') if pos == -1 return 0 else - if elixir#indent#is_string_or_comment(a:lnum, pos) + if s:is_string_or_comment(a:lnum, pos) return 0 else return 1 @@ -38,14 +83,9 @@ function! elixir#indent#ends_with(text, expr, lnum) end endfunction -" Returns 0 or 1 based on whether or not the text matches the given expression -function! elixir#indent#contains(text, expr) - return a:text =~ a:expr -endfunction - " Returns 0 or 1 based on whether or not the given line number and column " number pair is a string or comment -function! elixir#indent#is_string_or_comment(line, col) +function! s:is_string_or_comment(line, col) return synIDattr(synID(a:line, a:col, 1), "name") =~ '\%(String\|Comment\)' endfunction @@ -59,35 +99,19 @@ function! elixir#indent#searchpair_back_skip() if getline('.')[curr_col-1] == '' let curr_col = curr_col-1 endif - return elixir#indent#is_string_or_comment(line('.'), curr_col) -endfunction - -" DRY up searchpair calls -function! elixir#indent#searchpair_back(start, mid, end) - let line = line('.') - return searchpair(a:start, a:mid, a:end, 'bnW', "line('.') == " . line . " || elixir#indent#searchpair_back_skip()") -endfunction - -" DRY up searchpairpos calls -function! elixir#indent#searchpairpos_back(start, mid, end) - let line = line('.') - return searchpairpos(a:start, a:mid, a:end, 'bnW', "line('.') == " . line . " || elixir#indent#searchpair_back_skip()") + return s:is_string_or_comment(line('.'), curr_col) endfunction " DRY up regex for keywords that 1) makes sure we only look at complete words " and 2) ignores atoms -function! elixir#indent#keyword(expr) +function! s:keyword(expr) return ':\@<!\<\C\%('.a:expr.'\)\>:\@!' endfunction -function! elixir#indent#starts_with_comment(text) - return match(a:text, '^\s*#') != -1 -endfunction - " Start at the end of text and search backwards looking for a match. Also peek " ahead if we get a match to make sure we get a complete match. This means " that the result should be the position of the start of the right-most match -function! elixir#indent#find_last_pos(lnum, text, match) +function! s:find_last_pos(lnum, text, match) let last = len(a:text) - 1 let c = last @@ -118,13 +142,46 @@ function! elixir#indent#handle_top_of_file(_lnum, _text, prev_nb_lnum, _prev_nb_ end endfunction +function! elixir#indent#handle_follow_prev_nb(_lnum, _text, prev_nb_lnum, prev_nb_text) + return s:get_base_indent(a:prev_nb_lnum, a:prev_nb_text) +endfunction + +" Given the line at `lnum`, returns the indent of the line that acts as the 'base indent' +" for this line. In particular it traverses backwards up things like pipelines +" to find the beginning of the expression +function! s:get_base_indent(lnum, text) + let prev_nb_lnum = prevnonblank(a:lnum - 1) + let prev_nb_text = getline(prev_nb_lnum) + + let binary_operator = '\%(=\|<>\|>>>\|<=\|||\|+\|\~\~\~\|-\|&&\|<<<\|/\|\^\^\^\|\*\)' + let data_structure_close = '\%(\]\|}\|)\)' + let pipe = '|>' + + if s:starts_with(a:text, binary_operator, a:lnum) + return s:get_base_indent(prev_nb_lnum, prev_nb_text) + elseif s:starts_with(a:text, pipe, a:lnum) + return s:get_base_indent(prev_nb_lnum, prev_nb_text) + elseif s:ends_with(prev_nb_text, binary_operator, prev_nb_lnum) + return s:get_base_indent(prev_nb_lnum, prev_nb_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) + 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) + else + return indent(a:lnum) + endif +endfunction + " TODO: @jbodah 2017-03-31: remove function! elixir#indent#handle_following_trailing_do(lnum, text, prev_nb_lnum, prev_nb_text) - if elixir#indent#ends_with(a:prev_nb_text, elixir#indent#keyword('do'), a:prev_nb_lnum) - if elixir#indent#starts_with(a:text, elixir#indent#keyword('end'), a:lnum) + 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) return indent(a:prev_nb_lnum) else - return indent(a:prev_nb_lnum) + &sw + return indent(a:prev_nb_lnum) + s:sw() end else return -1 @@ -134,23 +191,31 @@ endfunction function! elixir#indent#handle_following_trailing_binary_operator(lnum, text, prev_nb_lnum, prev_nb_text) let binary_operator = '\%(=\|<>\|>>>\|<=\|||\|+\|\~\~\~\|-\|&&\|<<<\|/\|\^\^\^\|\*\)' - if elixir#indent#ends_with(a:prev_nb_text, binary_operator, a:prev_nb_lnum) - return indent(a:prev_nb_lnum) + &sw + if s:ends_with(a:prev_nb_text, binary_operator, a:prev_nb_lnum) + return indent(a:prev_nb_lnum) + s:sw() + else + return -1 + endif +endfunction + +function! elixir#indent#handle_following_prev_end(_lnum, _text, prev_nb_lnum, prev_nb_text) + if s:ends_with(a:prev_nb_text, s:keyword('end'), a:prev_nb_lnum) + return indent(a:prev_nb_lnum) else return -1 endif endfunction function! elixir#indent#handle_starts_with_pipe(lnum, text, prev_nb_lnum, prev_nb_text) - if elixir#indent#starts_with(a:text, '|>', a:lnum) + if s:starts_with(a:text, '|>', a:lnum) let match_operator = '\%(!\|=\|<\|>\)\@<!=\%(=\|>\|\~\)\@!' - let pos = elixir#indent#find_last_pos(a:prev_nb_lnum, a:prev_nb_text, match_operator) + let pos = s:find_last_pos(a:prev_nb_lnum, a:prev_nb_text, match_operator) if pos == -1 return indent(a:prev_nb_lnum) else let next_word_pos = match(strpart(a:prev_nb_text, pos+1, len(a:prev_nb_text)-1), '\S') if next_word_pos == -1 - return indent(a:prev_nb_lnum) + &sw + return indent(a:prev_nb_lnum) + s:sw() else return pos + 1 + next_word_pos end @@ -161,7 +226,7 @@ function! elixir#indent#handle_starts_with_pipe(lnum, text, prev_nb_lnum, prev_n endfunction function! elixir#indent#handle_starts_with_comment(_lnum, text, prev_nb_lnum, _prev_nb_text) - if elixir#indent#starts_with_comment(a:text) + if match(a:text, '^\s*#') != -1 return indent(a:prev_nb_lnum) else return -1 @@ -169,8 +234,8 @@ function! elixir#indent#handle_starts_with_comment(_lnum, text, prev_nb_lnum, _p endfunction function! elixir#indent#handle_starts_with_end(lnum, text, _prev_nb_lnum, _prev_nb_text) - if elixir#indent#starts_with(a:text, elixir#indent#keyword('end'), a:lnum) - let pair_lnum = elixir#indent#searchpair_back(elixir#indent#keyword('do\|fn'), '', elixir#indent#keyword('end').'\zs') + if s:starts_with(a:text, s:keyword('end'), a:lnum) + let pair_lnum = searchpair(s:keyword('do\|fn'), '', s:keyword('end').'\zs', 'bnW', "line('.') == " . line('.') . " || elixir#indent#searchpair_back_skip()") return indent(pair_lnum) else return -1 @@ -178,8 +243,8 @@ function! elixir#indent#handle_starts_with_end(lnum, text, _prev_nb_lnum, _prev_ endfunction function! elixir#indent#handle_starts_with_mid_or_end_block_keyword(lnum, text, _prev_nb_lnum, _prev_nb_text) - if elixir#indent#starts_with(a:text, elixir#indent#keyword('catch\|rescue\|after\|else'), a:lnum) - let pair_lnum = elixir#indent#searchpair_back(elixir#indent#keyword('with\|receive\|try\|if\|fn'), elixir#indent#keyword('catch\|rescue\|after\|else').'\zs', elixir#indent#keyword('end')) + if s:starts_with(a:text, s:keyword('catch\|rescue\|after\|else'), a:lnum) + let pair_lnum = searchpair(s:keyword('with\|receive\|try\|if\|fn'), s:keyword('catch\|rescue\|after\|else').'\zs', s:keyword('end'), 'bnW', "line('.') == " . line('.') . " || elixir#indent#searchpair_back_skip()") return indent(pair_lnum) else return -1 @@ -187,8 +252,8 @@ function! elixir#indent#handle_starts_with_mid_or_end_block_keyword(lnum, text, endfunction function! elixir#indent#handle_starts_with_close_bracket(lnum, text, _prev_nb_lnum, _prev_nb_text) - if elixir#indent#starts_with(a:text, '\%(\]\|}\|)\)', a:lnum) - let pair_lnum = elixir#indent#searchpair_back('\%(\[\|{\|(\)', '', '\%(\]\|}\|)\)') + if s:starts_with(a:text, '\%(\]\|}\|)\)', a:lnum) + let pair_lnum = searchpair('\%(\[\|{\|(\)', '', '\%(\]\|}\|)\)', 'bnW', "line('.') == " . line('.') . " || elixir#indent#searchpair_back_skip()") return indent(pair_lnum) else return -1 @@ -198,15 +263,15 @@ endfunction function! elixir#indent#handle_starts_with_binary_operator(lnum, text, prev_nb_lnum, prev_nb_text) let binary_operator = '\%(=\|<>\|>>>\|<=\|||\|+\|\~\~\~\|-\|&&\|<<<\|/\|\^\^\^\|\*\)' - if elixir#indent#starts_with(a:text, binary_operator, a:lnum) + if s:starts_with(a:text, binary_operator, a:lnum) let match_operator = '\%(!\|=\|<\|>\)\@<!=\%(=\|>\|\~\)\@!' - let pos = elixir#indent#find_last_pos(a:prev_nb_lnum, a:prev_nb_text, match_operator) + let pos = s:find_last_pos(a:prev_nb_lnum, a:prev_nb_text, match_operator) if pos == -1 return indent(a:prev_nb_lnum) else let next_word_pos = match(strpart(a:prev_nb_text, pos+1, len(a:prev_nb_text)-1), '\S') if next_word_pos == -1 - return indent(a:prev_nb_lnum) + &sw + return indent(a:prev_nb_lnum) + s:sw() else return pos + 1 + next_word_pos end @@ -221,75 +286,116 @@ endfunction " function, etc... so we need to first figure out what the innermost structure " is then forward execution to the proper handler function! elixir#indent#handle_inside_nested_construct(lnum, text, prev_nb_lnum, prev_nb_text) - let start_pattern = '\C\%(\<if\>\|\<case\>\|\<cond\>\|\<try\>\|\<receive\>\|\<fn\>\|{\|\[\|(\)' + let start_pattern = '\C\%(\<with\>\|\<if\>\|\<case\>\|\<cond\>\|\<try\>\|\<receive\>\|\<fn\>\|{\|\[\|(\)' let end_pattern = '\C\%(\<end\>\|\]\|}\|)\)' - let pair_info = elixir#indent#searchpairpos_back(start_pattern, '', end_pattern) + let pair_info = searchpairpos(start_pattern, '', end_pattern, 'bnW', "line('.') == " . line('.') . " || elixir#indent#searchpair_back_skip()", max([0, a:lnum - g:elixir_indent_max_lookbehind])) let pair_lnum = pair_info[0] let pair_col = pair_info[1] if pair_lnum != 0 || pair_col != 0 let pair_text = getline(pair_lnum) let pair_char = pair_text[pair_col - 1] if pair_char == 'f' - call elixir#indent#debug("testing elixir#indent#do_handle_inside_fn") - return elixir#indent#do_handle_inside_fn(pair_lnum, pair_col, a:lnum, a:text, a:prev_nb_lnum, a:prev_nb_text) + call s:debug("testing s:do_handle_inside_fn") + return s:do_handle_inside_fn(pair_lnum, pair_col, a:lnum, a:text, a:prev_nb_lnum, a:prev_nb_text) elseif pair_char == '[' - call elixir#indent#debug("testing elixir#indent#do_handle_inside_square_brace") - return elixir#indent#do_handle_inside_square_brace(pair_lnum, pair_col, a:lnum, a:text, a:prev_nb_lnum, a:prev_nb_text) + call s:debug("testing s:do_handle_inside_square_brace") + return s:do_handle_inside_square_brace(pair_lnum, pair_col, a:lnum, a:text, a:prev_nb_lnum, a:prev_nb_text) elseif pair_char == '{' - call elixir#indent#debug("testing elixir#indent#do_handle_inside_curly_brace") - return elixir#indent#do_handle_inside_curly_brace(pair_lnum, pair_col, a:lnum, a:text, a:prev_nb_lnum, a:prev_nb_text) + call s:debug("testing s:do_handle_inside_curly_brace") + return s:do_handle_inside_curly_brace(pair_lnum, pair_col, a:lnum, a:text, a:prev_nb_lnum, a:prev_nb_text) elseif pair_char == '(' - call elixir#indent#debug("testing elixir#indent#do_handle_inside_parens") - return elixir#indent#do_handle_inside_parens(pair_lnum, pair_col, a:lnum, a:text, a:prev_nb_lnum, a:prev_nb_text) + call s:debug("testing s:do_handle_inside_parens") + return s:do_handle_inside_parens(pair_lnum, pair_col, a:lnum, a:text, a:prev_nb_lnum, a:prev_nb_text) + elseif pair_char == 'w' + call s:debug("testing s:do_handle_inside_with") + return s:do_handle_inside_with(pair_lnum, pair_col, a:lnum, a:text, a:prev_nb_lnum, a:prev_nb_text) else - call elixir#indent#debug("testing elixir#indent#do_handle_inside_keyword_block") - return elixir#indent#do_handle_inside_keyword_block(pair_lnum, pair_col, a:lnum, a:text, a:prev_nb_lnum, a:prev_nb_text) + call s:debug("testing s:do_handle_inside_keyword_block") + return s:do_handle_inside_keyword_block(pair_lnum, pair_col, a:lnum, a:text, a:prev_nb_lnum, a:prev_nb_text) end else return -1 end endfunction -function! elixir#indent#do_handle_inside_keyword_block(pair_lnum, _pair_col, _lnum, text, prev_nb_lnum, prev_nb_text) +function! s:do_handle_inside_with(pair_lnum, pair_col, lnum, text, prev_nb_lnum, prev_nb_text) + if a:pair_lnum == a:lnum + " This is the `with` line or an inline `with`/`do` + call s:debug("current line is `with`") + return -1 + else + " Determine if in with/do, do/else|end, or else/end + let start_pattern = '\C\%(\<with\>\|\<else\>\|\<do\>\)' + let end_pattern = '\C\%(\<end\>\)' + let pair_info = searchpairpos(start_pattern, '', end_pattern, 'bnW', "line('.') == " . line('.') . " || elixir#indent#searchpair_back_skip()") + let pair_lnum = pair_info[0] + let pair_col = pair_info[1] + + let pair_text = getline(pair_lnum) + let pair_char = pair_text[pair_col - 1] + + if s:starts_with(a:text, '\Cdo:', a:lnum) + call s:debug("current line is do:") + return pair_col - 1 + s:sw() + elseif s:starts_with(a:text, '\Celse:', a:lnum) + call s:debug("current line is else:") + return pair_col - 1 + elseif s:starts_with(a:text, '\C\(\<do\>\|\<else\>\)', a:lnum) + call s:debug("current line is do/else") + return pair_col - 1 + elseif s:starts_with(pair_text, '\C\(do\|else\):', pair_lnum) + call s:debug("inside do:/else:") + return pair_col - 1 + s:sw() + elseif pair_char == 'w' + call s:debug("inside with/do") + return pair_col + 4 + elseif pair_char == 'd' + call s:debug("inside do/else|end") + return pair_col - 1 + s:sw() + else + call s:debug("inside else/end") + return s:do_handle_inside_pattern_match_block(pair_lnum, a:text, a:prev_nb_lnum, a:prev_nb_text) + end + end +endfunction + +function! s:do_handle_inside_keyword_block(pair_lnum, _pair_col, _lnum, text, prev_nb_lnum, prev_nb_text) let keyword_pattern = '\C\%(\<case\>\|\<cond\>\|\<try\>\|\<receive\>\|\<after\>\|\<catch\>\|\<rescue\>\|\<else\>\)' if a:pair_lnum - " last line is a "receive" or something - if elixir#indent#starts_with(a:prev_nb_text, keyword_pattern, a:prev_nb_lnum) - call elixir#indent#debug("prev nb line is keyword") - return indent(a:prev_nb_lnum) + &sw - elseif elixir#indent#contains(a:text, '->') - call elixir#indent#debug("contains ->") - " TODO: @jbodah 2017-03-31: test contains ignores str + comments - return indent(a:pair_lnum) + &sw - elseif elixir#indent#contains(a:prev_nb_text, '->') - call elixir#indent#debug("prev nb line contains ->") - return indent(a:prev_nb_lnum) + &sw + " last line is a "receive" or something + if s:starts_with(a:prev_nb_text, keyword_pattern, a:prev_nb_lnum) + call s:debug("prev nb line is keyword") + return indent(a:prev_nb_lnum) + s:sw() else - call elixir#indent#debug("doesnt start with comment or contain ->") - return indent(a:prev_nb_lnum) + return s:do_handle_inside_pattern_match_block(a:pair_lnum, a:text, a:prev_nb_lnum, a:prev_nb_text) end else return -1 endif endfunction -function! elixir#indent#do_handle_inside_fn(pair_lnum, _pair_col, lnum, text, prev_nb_lnum, prev_nb_text) +" Implements indent for pattern-matching blocks (e.g. case, fn, with/else) +function! s:do_handle_inside_pattern_match_block(block_start_lnum, text, prev_nb_lnum, prev_nb_text) + if a:text =~ '->' + call s:debug("current line contains ->") + return indent(a:block_start_lnum) + s:sw() + elseif a:prev_nb_text =~ '->' + call s:debug("prev nb line contains ->") + return indent(a:prev_nb_lnum) + s:sw() + else + return indent(a:prev_nb_lnum) + end +endfunction + +function! s:do_handle_inside_fn(pair_lnum, _pair_col, lnum, text, prev_nb_lnum, prev_nb_text) if a:pair_lnum && a:pair_lnum != a:lnum - if elixir#indent#contains(a:text, '->') - return indent(a:pair_lnum) + &sw - else - if elixir#indent#ends_with(a:prev_nb_text, '->', a:prev_nb_lnum) - return indent(a:prev_nb_lnum) + &sw - else - return indent(a:prev_nb_lnum) - end - end + return s:do_handle_inside_pattern_match_block(a:pair_lnum, a:text, a:prev_nb_lnum, a:prev_nb_text) else return -1 endif endfunction -function! elixir#indent#do_handle_inside_square_brace(pair_lnum, pair_col, _lnum, _text, _prev_nb_lnum, _prev_nb_text) +function! s:do_handle_inside_square_brace(pair_lnum, pair_col, _lnum, _text, _prev_nb_lnum, _prev_nb_text) " If in list... if a:pair_lnum != 0 || a:pair_col != 0 let pair_text = getline(a:pair_lnum) @@ -298,24 +404,24 @@ function! elixir#indent#do_handle_inside_square_brace(pair_lnum, pair_col, _lnum if indent_pos != -1 return indent_pos + a:pair_col else - return indent(a:pair_lnum) + &sw + return indent(a:pair_lnum) + s:sw() endif else return -1 end endfunction -function! elixir#indent#do_handle_inside_curly_brace(pair_lnum, _pair_col, _lnum, _text, _prev_nb_lnum, _prev_nb_text) - return indent(a:pair_lnum) + &sw +function! s:do_handle_inside_curly_brace(pair_lnum, _pair_col, _lnum, _text, _prev_nb_lnum, _prev_nb_text) + return indent(a:pair_lnum) + s:sw() endfunction -function! elixir#indent#do_handle_inside_parens(pair_lnum, pair_col, _lnum, _text, prev_nb_lnum, prev_nb_text) +function! s:do_handle_inside_parens(pair_lnum, pair_col, _lnum, _text, prev_nb_lnum, prev_nb_text) if a:pair_lnum - if elixir#indent#ends_with(a:prev_nb_text, '(', a:prev_nb_lnum) - return indent(a:prev_nb_lnum) + &sw + if s:ends_with(a:prev_nb_text, '(', a:prev_nb_lnum) + return indent(a:prev_nb_lnum) + s:sw() elseif a:pair_lnum == a:prev_nb_lnum " Align indent (e.g. "def add(a,") - let pos = elixir#indent#find_last_pos(a:prev_nb_lnum, a:prev_nb_text, '[^(]\+,') + let pos = s:find_last_pos(a:prev_nb_lnum, a:prev_nb_text, '[^(]\+,') if pos == -1 return 0 else @@ -330,14 +436,14 @@ function! elixir#indent#do_handle_inside_parens(pair_lnum, pair_col, _lnum, _tex endfunction function! elixir#indent#handle_inside_generic_block(lnum, _text, prev_nb_lnum, prev_nb_text) - let pair_lnum = searchpair(elixir#indent#keyword('do\|fn'), '', elixir#indent#keyword('end'), 'bW', "line('.') == ".a:lnum." || elixir#indent#is_string_or_comment(line('.'), col('.'))") + let pair_lnum = searchpair(s:keyword('do\|fn'), '', s:keyword('end'), 'bW', "line('.') == ".a:lnum." || s:is_string_or_comment(line('.'), col('.'))", max([0, a:lnum - g:elixir_indent_max_lookbehind])) if pair_lnum " TODO: @jbodah 2017-03-29: this should probably be the case in *all* " blocks - if elixir#indent#ends_with(a:prev_nb_text, ',', a:prev_nb_lnum) - return indent(pair_lnum) + 2 * &sw + if s:ends_with(a:prev_nb_text, ',', a:prev_nb_lnum) + return indent(pair_lnum) + 2 * s:sw() else - return indent(pair_lnum) + &sw + return indent(pair_lnum) + s:sw() endif else return -1 diff --git a/autoload/rust.vim b/autoload/rust.vim index fe7ddff8..6edc48f7 100644 --- a/autoload/rust.vim +++ b/autoload/rust.vim @@ -3,6 +3,7 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'rust') == -1 " Author: Kevin Ballard " Description: Helper functions for Rust commands/mappings " Last Modified: May 27, 2014 +" For bugs, patches and license go to https://github.com/rust-lang/rust.vim " Jump {{{1 @@ -366,53 +367,57 @@ endfunction " gist.vim available under the BSD license, available at " http://github.com/mattn/gist-vim function! s:has_webapi() - if !exists("*webapi#http#post") - try - call webapi#http#post() - catch - endtry - endif - return exists("*webapi#http#post") + if !exists("*webapi#http#post") + try + call webapi#http#post() + catch + endtry + endif + return exists("*webapi#http#post") endfunction function! rust#Play(count, line1, line2, ...) abort - redraw - - let l:rust_playpen_url = get(g:, 'rust_playpen_url', 'https://play.rust-lang.org/') - let l:rust_shortener_url = get(g:, 'rust_shortener_url', 'https://is.gd/') - - if !s:has_webapi() - echohl ErrorMsg | echomsg ':RustPlay depends on webapi.vim (https://github.com/mattn/webapi-vim)' | echohl None - return - endif - - let bufname = bufname('%') - if a:count < 1 - let content = join(getline(a:line1, a:line2), "\n") - else - let save_regcont = @" - let save_regtype = getregtype('"') - silent! normal! gvy - let content = @" - call setreg('"', save_regcont, save_regtype) - endif - - let body = l:rust_playpen_url."?code=".webapi#http#encodeURI(content) - - if strlen(body) > 5000 - echohl ErrorMsg | echomsg 'Buffer too large, max 5000 encoded characters ('.strlen(body).')' | echohl None - return - endif - - let payload = "format=simple&url=".webapi#http#encodeURI(body) - let res = webapi#http#post(l:rust_shortener_url.'create.php', payload, {}) - let url = res.content - - redraw | echomsg 'Done: '.url + redraw + + let l:rust_playpen_url = get(g:, 'rust_playpen_url', 'https://play.rust-lang.org/') + let l:rust_shortener_url = get(g:, 'rust_shortener_url', 'https://is.gd/') + + if !s:has_webapi() + echohl ErrorMsg | echomsg ':RustPlay depends on webapi.vim (https://github.com/mattn/webapi-vim)' | echohl None + return + endif + + let bufname = bufname('%') + if a:count < 1 + let content = join(getline(a:line1, a:line2), "\n") + else + let save_regcont = @" + let save_regtype = getregtype('"') + silent! normal! gvy + let content = @" + call setreg('"', save_regcont, save_regtype) + endif + + let body = l:rust_playpen_url."?code=".webapi#http#encodeURI(content) + + if strlen(body) > 5000 + echohl ErrorMsg | echomsg 'Buffer too large, max 5000 encoded characters ('.strlen(body).')' | echohl None + return + endif + + let payload = "format=simple&url=".webapi#http#encodeURI(body) + let res = webapi#http#post(l:rust_shortener_url.'create.php', payload, {}) + let url = res.content + + if exists('g:rust_clip_command') + call system(g:rust_clip_command, url) + endif + + redraw | echomsg 'Done: '.url endfunction " }}}1 -" vim: set noet sw=4 ts=4: +" vim: set noet sw=8 ts=8: endif diff --git a/autoload/rustfmt.vim b/autoload/rustfmt.vim index a43c07cc..307fead7 100644 --- a/autoload/rustfmt.vim +++ b/autoload/rustfmt.vim @@ -3,108 +3,109 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'rust') == -1 " Author: Stephen Sugden <stephen@stephensugden.com> " " Adapted from https://github.com/fatih/vim-go +" For bugs, patches and license go to https://github.com/rust-lang/rust.vim if !exists("g:rustfmt_autosave") - let g:rustfmt_autosave = 0 + let g:rustfmt_autosave = 0 endif if !exists("g:rustfmt_command") - let g:rustfmt_command = "rustfmt" + let g:rustfmt_command = "rustfmt" endif if !exists("g:rustfmt_options") - let g:rustfmt_options = "" + let g:rustfmt_options = "" endif if !exists("g:rustfmt_fail_silently") - let g:rustfmt_fail_silently = 0 + let g:rustfmt_fail_silently = 0 endif let s:got_fmt_error = 0 function! s:RustfmtCommandRange(filename, line1, line2) - let l:arg = {"file": shellescape(a:filename), "range": [a:line1, a:line2]} - return printf("%s %s --write-mode=overwrite --file-lines '[%s]'", g:rustfmt_command, g:rustfmt_options, json_encode(l:arg)) + let l:arg = {"file": shellescape(a:filename), "range": [a:line1, a:line2]} + return printf("%s %s --write-mode=overwrite --file-lines '[%s]'", g:rustfmt_command, g:rustfmt_options, json_encode(l:arg)) endfunction function! s:RustfmtCommand(filename) - return g:rustfmt_command . " --write-mode=overwrite " . g:rustfmt_options . " " . shellescape(a:filename) + return g:rustfmt_command . " --write-mode=overwrite " . g:rustfmt_options . " " . shellescape(a:filename) endfunction function! s:RunRustfmt(command, curw, tmpname) - if exists("*systemlist") - let out = systemlist(a:command) - else - let out = split(system(a:command), '\r\?\n') - endif - - if v:shell_error == 0 || v:shell_error == 3 - " remove undo point caused via BufWritePre - try | silent undojoin | catch | endtry - - " Replace current file with temp file, then reload buffer - call rename(a:tmpname, expand('%')) - silent edit! - let &syntax = &syntax - - " only clear location list if it was previously filled to prevent - " clobbering other additions - if s:got_fmt_error - let s:got_fmt_error = 0 - call setloclist(0, []) - lwindow - endif - elseif g:rustfmt_fail_silently == 0 - " otherwise get the errors and put them in the location list - let errors = [] - - for line in out - " src/lib.rs:13:5: 13:10 error: expected `,`, or `}`, found `value` - let tokens = matchlist(line, '^\(.\{-}\):\(\d\+\):\(\d\+\):\s*\(\d\+:\d\+\s*\)\?\s*error: \(.*\)') - if !empty(tokens) - call add(errors, {"filename": @%, - \"lnum": tokens[2], - \"col": tokens[3], - \"text": tokens[5]}) - endif - endfor - - if empty(errors) - % | " Couldn't detect rustfmt error format, output errors - endif - - if !empty(errors) - call setloclist(0, errors, 'r') - echohl Error | echomsg "rustfmt returned error" | echohl None - endif - - let s:got_fmt_error = 1 - lwindow - " We didn't use the temp file, so clean up - call delete(a:tmpname) - endif - - call winrestview(a:curw) + if exists("*systemlist") + let out = systemlist(a:command) + else + let out = split(system(a:command), '\r\?\n') + endif + + if v:shell_error == 0 || v:shell_error == 3 + " remove undo point caused via BufWritePre + try | silent undojoin | catch | endtry + + " Replace current file with temp file, then reload buffer + call rename(a:tmpname, expand('%')) + silent edit! + let &syntax = &syntax + + " only clear location list if it was previously filled to prevent + " clobbering other additions + if s:got_fmt_error + let s:got_fmt_error = 0 + call setloclist(0, []) + lwindow + endif + elseif g:rustfmt_fail_silently == 0 + " otherwise get the errors and put them in the location list + let errors = [] + + for line in out + " src/lib.rs:13:5: 13:10 error: expected `,`, or `}`, found `value` + let tokens = matchlist(line, '^\(.\{-}\):\(\d\+\):\(\d\+\):\s*\(\d\+:\d\+\s*\)\?\s*error: \(.*\)') + if !empty(tokens) + call add(errors, {"filename": @%, + \"lnum": tokens[2], + \"col": tokens[3], + \"text": tokens[5]}) + endif + endfor + + if empty(errors) + % | " Couldn't detect rustfmt error format, output errors + endif + + if !empty(errors) + call setloclist(0, errors, 'r') + echohl Error | echomsg "rustfmt returned error" | echohl None + endif + + let s:got_fmt_error = 1 + lwindow + " We didn't use the temp file, so clean up + call delete(a:tmpname) + endif + + call winrestview(a:curw) endfunction function! rustfmt#FormatRange(line1, line2) - let l:curw = winsaveview() - let l:tmpname = expand("%:p:h") . "/." . expand("%:p:t") . ".rustfmt" - call writefile(getline(1, '$'), l:tmpname) + let l:curw = winsaveview() + let l:tmpname = expand("%:p:h") . "/." . expand("%:p:t") . ".rustfmt" + call writefile(getline(1, '$'), l:tmpname) - let command = s:RustfmtCommandRange(l:tmpname, a:line1, a:line2) + let command = s:RustfmtCommandRange(l:tmpname, a:line1, a:line2) - call s:RunRustfmt(command, l:curw, l:tmpname) + call s:RunRustfmt(command, l:curw, l:tmpname) endfunction function! rustfmt#Format() - let l:curw = winsaveview() - let l:tmpname = expand("%:p:h") . "/." . expand("%:p:t") . ".rustfmt" - call writefile(getline(1, '$'), l:tmpname) + let l:curw = winsaveview() + let l:tmpname = expand("%:p:h") . "/." . expand("%:p:t") . ".rustfmt" + call writefile(getline(1, '$'), l:tmpname) - let command = s:RustfmtCommand(l:tmpname) + let command = s:RustfmtCommand(l:tmpname) - call s:RunRustfmt(command, l:curw, l:tmpname) + call s:RunRustfmt(command, l:curw, l:tmpname) endfunction endif diff --git a/autoload/xml/html5.vim b/autoload/xml/html5.vim index 982fe29a..4123dbe0 100644 --- a/autoload/xml/html5.vim +++ b/autoload/xml/html5.vim @@ -587,7 +587,7 @@ let g:xmldata_html5 = { \ ], \ 'input': [ \ [], - \ extend(copy(global_attributes), {'type': ['text', 'password', 'checkbox', 'radio', 'button', 'submit', 'reset', 'file', 'hidden', 'image', 'datetime', 'datetime-local', 'date', 'month', 'time', 'week', 'number', 'range', 'email', 'url', 'search', 'tel', 'color'], 'name': [], 'disabled': ['disabled', ''], 'form': [], 'maxlength': [], 'readonly': ['readonly', ''], 'size': [], 'value': [], 'autocomplete': autofill_tokens, 'autofocus': ['autofocus', ''], 'list': [], 'pattern': [], 'required': ['required', ''], 'placeholder': [], 'checked': ['checked'], 'accept': [], 'multiple': ['multiple', ''], 'alt': [], 'src': [], 'height': [], 'width': [], 'min': [], 'max': [], 'step': [], 'formenctype': ['application/x-www-form-urlencoded', 'multipart/form-data', 'text/plain'], 'formmethod': ['get', 'post', 'put', 'delete'], 'formtarget': [], 'formnovalidate': ['formnovalidate', '']}) + \ extend(copy(global_attributes), {'type': ['text', 'password', 'checkbox', 'radio', 'button', 'submit', 'reset', 'file', 'hidden', 'image', 'datetime-local', 'date', 'month', 'time', 'week', 'number', 'range', 'email', 'url', 'search', 'tel', 'color'], 'name': [], 'disabled': ['disabled', ''], 'form': [], 'maxlength': [], 'readonly': ['readonly', ''], 'size': [], 'value': [], 'autocomplete': autofill_tokens, 'autofocus': ['autofocus', ''], 'list': [], 'pattern': [], 'required': ['required', ''], 'placeholder': [], 'checked': ['checked'], 'accept': [], 'multiple': ['multiple', ''], 'alt': [], 'src': [], 'height': [], 'width': [], 'min': [], 'max': [], 'step': [], 'formenctype': ['application/x-www-form-urlencoded', 'multipart/form-data', 'text/plain'], 'formmethod': ['get', 'post', 'put', 'delete'], 'formtarget': [], 'formnovalidate': ['formnovalidate', '']}) \ ], \ 'ins': [ \ flow_elements, |