From af870100716f20ee4daef9cc527a9ecf41b54114 Mon Sep 17 00:00:00 2001 From: Adam Stankiewicz Date: Wed, 17 May 2017 11:07:28 +0200 Subject: Update --- indent/ansible.vim | 5 + indent/elixir.vim | 127 ++++++++---------------- indent/haskell.vim | 90 +++++++++-------- indent/javascript.vim | 262 ++++++++++++++++++++++++++++++++------------------ indent/plantuml.vim | 4 +- indent/ruby.vim | 96 +++++++++--------- indent/vue.vim | 59 ++++++++---- 7 files changed, 357 insertions(+), 286 deletions(-) (limited to 'indent') diff --git a/indent/ansible.vim b/indent/ansible.vim index b3a9642f..d94d3a2c 100644 --- a/indent/ansible.vim +++ b/indent/ansible.vim @@ -27,7 +27,12 @@ endif function GetAnsibleIndent(lnum) if a:lnum == 1 || !prevnonblank(a:lnum-1) + return 0 + endif + if exists("g:ansible_unindent_after_newline") + if (a:lnum -1) != prevnonblank(a:lnum - 1) return 0 + endif endif let prevlnum = prevnonblank(a:lnum - 1) let maintain = indent(prevlnum) diff --git a/indent/elixir.vim b/indent/elixir.vim index d1ea4ad4..0ddaec44 100644 --- a/indent/elixir.vim +++ b/indent/elixir.vim @@ -1,97 +1,48 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'elixir') == -1 -setlocal nosmartindent -setlocal indentexpr=elixir#indent() -setlocal indentkeys+=0),0],0=\|>,=-> -setlocal indentkeys+=0=end,0=else,0=match,0=elsif,0=catch,0=after,0=rescue - -if exists("b:did_indent") || exists("*elixir#indent") +if exists("b:did_indent") finish end let b:did_indent = 1 -let s:cpo_save = &cpo -set cpo&vim - -function! elixir#indent() - " initiates the `old_ind` dictionary - let b:old_ind = get(b:, 'old_ind', {}) - " initiates the `line` dictionary - let line = s:build_line(v:lnum) - - if s:is_beginning_of_file(line) - " Reset `old_ind` dictionary at the beginning of the file - let b:old_ind = {} - " At the start of the file use zero indent. - return 0 - elseif !s:is_indentable_line(line) - " Keep last line indentation if the current line does not have an - " indentable syntax - return indent(line.last_non_blank.num) - else - " Calculates the indenation level based on the rules - " All the rules are defined in `autoload/elixir/indent.vim` - let ind = indent(line.last_non_blank.num) - call s:debug('>>> line = ' . string(line.current)) - call s:debug('>>> ind = ' . ind) - let ind = s:indent('deindent_case_arrow', ind, line) - let ind = s:indent('indent_parenthesis', ind, line) - let ind = s:indent('indent_square_brackets', ind, line) - let ind = s:indent('indent_brackets', ind, line) - let ind = s:indent('deindent_opened_symbols', ind, line) - let ind = s:indent('indent_pipeline_assignment', ind, line) - let ind = s:indent('indent_pipeline_continuation', ind, line) - let ind = s:indent('indent_after_pipeline', ind, line) - let ind = s:indent('indent_assignment', ind, line) - let ind = s:indent('indent_ending_symbols', ind, line) - let ind = s:indent('indent_keywords', ind, line) - let ind = s:indent('deindent_keywords', ind, line) - let ind = s:indent('deindent_ending_symbols', ind, line) - let ind = s:indent('indent_case_arrow', ind, line) - let ind = s:indent('indent_ecto_queries', ind, line) - call s:debug('<<< final = ' . ind) - return ind - end -endfunction - -function s:indent(rule, ind, line) - let Fn = function('elixir#indent#'.a:rule) - let ind = Fn(a:ind, a:line) - call s:debug(a:rule . ' = ' . ind) - return ind -endfunction - -function s:debug(message) - if get(g:, 'elixir_indent_debug', 0) - echom a:message - end -endfunction - -function! s:is_beginning_of_file(line) - return a:line.last_non_blank.num == 0 +setlocal indentexpr=elixir#indent(v:lnum) + +setlocal indentkeys+=0=end,0=catch,0=rescue,0=after,0=else,=->,0},0],0),0=\|>,0=<> +" TODO: @jbodah 2017-02-27: all operators should cause reindent when typed + +function! elixir#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 elixir#indent#debug("==> Indenting line " . lnum) + call elixir#indent#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' + \] + for handler in handlers + call elixir#indent#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 elixir#indent#debug('line '.lnum.': elixir#indent#handle_'.handler.' returned '.indent) + return indent + endif + endfor + + call elixir#indent#debug("defaulting") + return 0 endfunction -function! s:is_indentable_line(line) - return elixir#util#is_indentable_at(a:line.current.num, 1) -endfunction - -function! s:build_line(line) - let line = { 'current': {}, 'last': {}, 'last_non_blank': {} } - let line.current = s:new_line(a:line) - let line.last = s:new_line(line.current.num - 1) - let line.last_non_blank = s:new_line(prevnonblank(line.current.num - 1)) - - return line -endfunction - -function! s:new_line(num) - return { - \ "num": a:num, - \ "text": getline(a:num) - \ } -endfunction - -let &cpo = s:cpo_save -unlet s:cpo_save - endif diff --git a/indent/haskell.vim b/indent/haskell.vim index 43dc97a6..e63515ce 100644 --- a/indent/haskell.vim +++ b/indent/haskell.vim @@ -13,11 +13,7 @@ if exists('b:did_indent') finish endif -if !exists('g:haskell_indent_disable') - let g:haskell_indent_disable = 0 -endif - -if g:haskell_indent_disable != 0 +if get(g:, 'haskell_indent_disable', 0) finish endif @@ -68,7 +64,7 @@ if !exists('g:haskell_indent_guard') endif setlocal indentexpr=GetHaskellIndent() -setlocal indentkeys=0},0),0],!^F,o,O,0\=,0=where,0=let,0=deriving, +setlocal indentkeys=0},0),0],!^F,o,O,0=where,0=let,0=deriving, function! s:isInBlock(hlstack) return index(a:hlstack, 'haskellDelimiter') > -1 || index(a:hlstack, 'haskellParens') > -1 || index(a:hlstack, 'haskellBrackets') > -1 || index(a:hlstack, 'haskellBlock') > -1 || index(a:hlstack, 'haskellBlockComment') > -1 || index(a:hlstack, 'haskellPragma') > -1 @@ -159,15 +155,6 @@ function! GetHaskellIndent() return 0 endif - " " comment indentation - " if l:line =~ '^\s*--' - " let l:s = match(l:prevline, '-- ') - " if l:s > -1 - " endif - " " if l:prevline =~ '^\s*--' - " " return match(l:prevline, '\S') - " " endif - " { foo :: Int " >>, " @@ -258,12 +245,16 @@ function! GetHaskellIndent() " where " >>foo " + if l:prevline =~ '\C\\s*$' + return match(l:prevline, '\S') + get(g:, 'haskell_indent_after_bare_where', &shiftwidth) + endif + " do " >>foo " " foo = " >>bar - if l:prevline =~ '\C\(\\|\\|=\)\s*$' + if l:prevline =~ '\C\(\\|=\)\s*$' return match(l:prevline, '\S') + &shiftwidth endif @@ -279,7 +270,7 @@ function! GetHaskellIndent() " case foo of " >>bar -> quux if l:prevline =~ '\C\.\+\\s*$' - if exists('g:haskell_indent_case_alternative') && g:haskell_indent_case_alternative + if get(g:,'haskell_indent_case_alternative', 0) return match(l:prevline, '\S') + &shiftwidth else return match(l:prevline, '\C\') + g:haskell_indent_case @@ -319,6 +310,14 @@ function! GetHaskellIndent() endif endif + " foo :: Int + " -> Int + " >>>>-> Int + " + " foo :: Monad m + " => Functor f + " >>>>=> Int + " " foo :: Int " -> Int " foo x @@ -327,32 +326,36 @@ function! GetHaskellIndent() " :: Int " -> Int " foo x - if l:prevline =~ '^\s*[-=]>' && l:line !~ '^\s*[-=]>' - if s:isInBlock(l:hlstack) - return match(l:prevline, '[^\s-=>]') + if l:prevline =~ '^\s*[-=]>' + if l:line =~ '^\s*[-=]>' + return match(l:prevline, '[-=]') else - let l:m = matchstr(l:line, '^\s*\zs\<\S\+\>\ze') - let l:l = l:prevline - let l:c = 1 - - while v:lnum != l:c - " fun decl - if l:l =~ ('^\s*' . l:m . '\(\s*::\|\n\s\+::\)') - let l:s = match(l:l, l:m) - if match(l:l, '\C^\s*\') > -1 - return l:s - 8 - else - return l:s + if s:isInBlock(l:hlstack) + return match(l:prevline, '[^-=]') + else + let l:m = matchstr(l:line, '^\s*\zs\<\S\+\>\ze') + let l:l = l:prevline + let l:c = 1 + + while v:lnum != l:c + " fun decl + if l:l =~ ('^\s*' . l:m . '\(\s*::\|\n\s\+::\)') + let l:s = match(l:l, l:m) + if match(l:l, '\C^\s*\') > -1 + return l:s - 8 + else + return l:s + endif + " empty line, stop looking + elseif l:l =~ '^$' + return 0 endif - " empty line, stop looking - elseif l:l =~ '^$' - return 0 - endif - let l:c += 1 - let l:l = getline(v:lnum - l:c) - endwhile + let l:c += 1 + let l:l = getline(v:lnum - l:c) + endwhile - return 0 + return 0 + endif endif endif @@ -403,12 +406,17 @@ function! GetHaskellIndent() " in foo " where bar + " + " or + " + " foo + " >>where if l:line =~ '\C^\s*\' if match(l:prevline, '\C^\s\+in\s\+') == 0 return match(l:prevline, 'in') - g:haskell_indent_in endif - return match(l:prevline, '\S') + &shiftwidth + return match(l:prevline, '\S') + get(g:, 'haskell_indent_before_where', &shiftwidth) endif " let x = 1 diff --git a/indent/javascript.vim b/indent/javascript.vim index 7029ed22..8f922eca 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -4,7 +4,7 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'javascript') == " Language: Javascript " Maintainer: Chris Paul ( https://github.com/bounceme ) " URL: https://github.com/pangloss/vim-javascript -" Last Change: March 9, 2017 +" Last Change: May 16, 2017 " Only load this indent file when no other was loaded. if exists('b:did_indent') @@ -12,6 +12,10 @@ if exists('b:did_indent') endif let b:did_indent = 1 +" indent correctly if inside '] }, + \ { 'name': 'javascript', 'pairs': [''] }, + \ ] + +for language in s:languages + " Set 'indentexpr' if the user has an indent file installed for the language + if strlen(globpath(&rtp, 'indent/'. language.name .'.vim')) + let language.indentexpr = s:get_indentexpr(language.name) + endif endfor +let s:html_indent = s:get_indentexpr('html') + let b:did_indent = 1 setlocal indentexpr=GetVueIndent() -if exists("*GetVueIndent") +if exists('*GetVueIndent') finish endif function! GetVueIndent() - if searchpair('