diff options
| author | Adam Stankiewicz <sheerun@sher.pl> | 2017-12-06 12:56:27 +0100 | 
|---|---|---|
| committer | Adam Stankiewicz <sheerun@sher.pl> | 2017-12-06 12:56:27 +0100 | 
| commit | dce9e8dec5ef51730291c7bbff3e3997433eabbd (patch) | |
| tree | 1ca7140cd4244dfdff3d8d58f936d9dc159c9d4e /indent | |
| parent | 30c87b73deff05c7dd9590228c0615a3299f39ff (diff) | |
| download | vim-polyglot-dce9e8dec5ef51730291c7bbff3e3997433eabbd.tar.gz vim-polyglot-dce9e8dec5ef51730291c7bbff3e3997433eabbd.zip | |
Update
Diffstat (limited to 'indent')
| -rw-r--r-- | indent/javascript.vim | 36 | ||||
| -rw-r--r-- | indent/terraform.vim | 25 | 
2 files changed, 35 insertions, 26 deletions
| diff --git a/indent/javascript.vim b/indent/javascript.vim index f6fda1dc..010077d4 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: September 18, 2017 +" Last Change: December 4, 2017  " Only load this indent file when no other was loaded.  if exists('b:did_indent') @@ -121,11 +121,14 @@ function s:SkipFunc()      if eval(s:skip_expr)        return 1      endif -  elseif search('\m`\|\${\|\*\/','nW'.s:z,s:looksyn) && eval(s:skip_expr) -    let s:check_in = 1 -    return 1 +  elseif search('\m`\|\${\|\*\/','nW'.s:z,s:looksyn) +    if eval(s:skip_expr) +      let s:check_in = 1 +      return 1 +    endif +  else +    let s:synid_cache[:] += [[line2byte('.') + col('.') - 1], ['']]    endif -  let s:synid_cache[:] += [[line2byte('.') + col('.') - 1], ['']]    let [s:looksyn, s:top_col] = getpos('.')[1:2]  endfunction @@ -242,18 +245,18 @@ function s:Continues()  endfunction  " Check if line 'lnum' has a balanced amount of parentheses. -function s:Balanced(lnum) -  let [l:open, l:line] = [0, getline(a:lnum)] -  let pos = match(l:line, '[][(){}]') +function s:Balanced(lnum,line) +  let l:open = 0 +  let pos = match(a:line, '[][(){}]')    while pos != -1      if s:SynAt(a:lnum,pos + 1) !~? b:syng_strcom -      let l:open += match(' ' . l:line[pos],'[[({]') +      let l:open += match(' ' . a:line[pos],'[[({]')        if l:open < 0          return        endif      endif -    let pos = match(l:line, !l:open ? '[][(){}]' : '()' =~ l:line[pos] ? -          \ '[()]' : '{}' =~ l:line[pos] ? '[{}]' : '[][]', pos + 1) +    let pos = match(a:line, !l:open ? '[][(){}]' : '()' =~ a:line[pos] ? +          \ '[()]' : '{}' =~ a:line[pos] ? '[{}]' : '[][]', pos + 1)    endwhile    return !l:open  endfunction @@ -266,8 +269,13 @@ function s:OneScope()            \ s:Pure('s:PreviousToken') != '.' && !(tok == 'while' && s:DoWhile())    elseif s:Token() =~# '^else$\|^do$'      return s:Pure('s:PreviousToken') != '.' +  elseif strpart(getline('.'),col('.')-2,2) == '=>' +    call cursor(0,col('.')-1) +    if s:PreviousToken() == ')' +      return s:GetPair('(', ')', 'bW', s:skip_expr) +    endif +    return 1    endif -  return strpart(getline('.'),col('.')-2,2) == '=>'  endfunction  function s:DoWhile() @@ -358,7 +366,7 @@ function GetJavascriptIndent()        return -1      endif    elseif s:stack[-1] =~? b:syng_str -    if b:js_cache[0] == v:lnum - 1 && s:Balanced(v:lnum-1) +    if b:js_cache[0] == v:lnum - 1 && s:Balanced(v:lnum-1,getline(v:lnum-1))        let b:js_cache[0] = v:lnum      endif      return -1 @@ -385,7 +393,7 @@ function GetJavascriptIndent()    call cursor(v:lnum,1)    let idx = index([']',')','}'],l:line[0])    if b:js_cache[0] > l:lnum && b:js_cache[0] < v:lnum || -        \ b:js_cache[0] == l:lnum && s:Balanced(l:lnum) +        \ b:js_cache[0] == l:lnum && s:Balanced(l:lnum,pline)      call call('cursor',b:js_cache[1:])    else      let [s:looksyn, s:top_col, s:check_in, s:l1] = [v:lnum - 1,0,0, diff --git a/indent/terraform.vim b/indent/terraform.vim index 5a29dfb4..9a081ff8 100644 --- a/indent/terraform.vim +++ b/indent/terraform.vim @@ -1,13 +1,13 @@  if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'terraform') == -1 +" Only load this file if no other indent file was loaded  if exists("b:did_indent")    finish  endif -  let b:did_indent = 1  setlocal nolisp -setlocal autoindent +setlocal autoindent sw=2 ts=2  setlocal indentexpr=TerraformIndent(v:lnum)  setlocal indentkeys+=<:>,0=},0=) @@ -16,29 +16,30 @@ if exists("*TerraformIndent")  endif  function! TerraformIndent(lnum) -  " previous non-blank line -  let prevlnum = prevnonblank(a:lnum-1) - -  " beginning of file? -  if prevlnum == 0 +  " Beginning of the file should have no indent +  if a:lnum == 0      return 0    endif -  " previous line without comments +  " Previous non-blank line should continue the indent level +  let prevlnum = prevnonblank(a:lnum-1) + +  " Previous line without comments should continue the indent level    let prevline = substitute(getline(prevlnum), '//.*$', '', '')    let previndent = indent(prevlnum)    let thisindent = previndent -  " block open? +  " Config block starting with [ { ( should increase the indent level    if prevline =~ '[\[{\(]\s*$'      let thisindent += &sw    endif -  " current line without comments +  " Current line without comments should continue the indent level    let thisline = substitute(getline(a:lnum), '//.*$', '', '') -  " block close? -  if thisline =~ '^\s*[\)\]}]' +  " Config block ending with ) } ] should get the indentation +  " level from the initial config block +  if thisline =~ '^\s*[\)}\]]'      let thisindent -= &sw    endif | 
