summaryrefslogtreecommitdiffstats
path: root/indent
diff options
context:
space:
mode:
authorAdam Stankiewicz <sheerun@sher.pl>2016-06-26 18:03:28 +0200
committerAdam Stankiewicz <sheerun@sher.pl>2016-06-26 18:03:28 +0200
commitc69562f864cb0ee973142a45091f6cb46ce0b1df (patch)
treef10ac7812b56cfa944367bae62f8cea0ffd54414 /indent
parent40c54bc12b5700f6bffed12209489e1f669f6423 (diff)
downloadvim-polyglot-2.9.3.tar.gz
vim-polyglot-2.9.3.zip
Updatev2.9.3
Diffstat (limited to 'indent')
-rw-r--r--indent/blade.vim26
-rw-r--r--indent/go.vim80
-rw-r--r--indent/gohtmltmpl.vim2
-rw-r--r--indent/javascript.vim149
-rw-r--r--indent/proto.vim21
5 files changed, 158 insertions, 120 deletions
diff --git a/indent/blade.vim b/indent/blade.vim
index 4c89ed61..e5bf510c 100644
--- a/indent/blade.vim
+++ b/indent/blade.vim
@@ -7,13 +7,20 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'blade') == -1
if exists("b:did_indent")
finish
endif
+
runtime! indent/html.vim
+let s:htmlindent = &indentexpr
+unlet! b:did_indent
+
+runtime! indent/php.vim
+let s:phpindent = &indentexpr
unlet! b:did_indent
+
let b:did_indent = 1
setlocal autoindent
setlocal indentexpr=GetBladeIndent()
-setlocal indentkeys=o,O,*<Return>,<>>,!^F,=@else,=@end,=@empty,=@show
+setlocal indentkeys=o,O,*<Return>,<>>,!^F,=@else,=@end,=@empty,=@show,=@stop
" Only define the function once.
if exists("*GetBladeIndent")
@@ -30,13 +37,19 @@ function! GetBladeIndent()
let cline = substitute(substitute(getline(v:lnum), '\s\+$', '', ''), '^\s\+', '', '')
let indent = indent(lnum)
let cindent = indent(v:lnum)
- if cline =~# '@\%(else\|elseif\|empty\|end\|show\)'
+ if cline =~# '@\%(else\|elseif\|empty\|end\|show\|stop\)' ||
+ \ cline =~# '\%(<?.*\)\@<!?>\|\%({{.*\)\@<!}}\|\%({!!.*\)\@<!!!}'
let indent = indent - &sw
else
if exists("*GetBladeIndentCustom")
let hindent = GetBladeIndentCustom()
+ elseif searchpair('@include\s*(', '', ')', 'bWr') ||
+ \ searchpair('{!!', '', '!!}', 'bWr') ||
+ \ searchpair('{{', '', '}}', 'bWr') ||
+ \ searchpair('<?', '', '?>', 'bWr')
+ execute 'let hindent = ' . s:phpindent
else
- let hindent = HtmlIndent()
+ execute 'let hindent = ' . s:htmlindent
endif
if hindent > -1
let indent = hindent
@@ -47,10 +60,13 @@ function! GetBladeIndent()
let indent = cindent <= indent ? -1 : increase
endif
- if line =~# '@\%(section\)\%(.*\s*@end\)\@!' && line !~# '@\%(section\)\s*([^,]*)'
+ if line =~# '@\%(section\)\%(.*@end\)\@!' && line !~# '@\%(section\)\s*([^,]*)'
return indent
- elseif line =~# '@\%(if\|elseif\|else\|unless\|foreach\|forelse\|for\|while\|empty\|push\|section\|can\)\%(.*\s*@end\)\@!'
+ elseif line =~# '@\%(if\|elseif\|else\|unless\|foreach\|forelse\|for\|while\|empty\|push\|section\|can\|hasSection\)\%(.*@end\|.*@stop\)\@!' ||
+ \ line =~# '{{\%(.*}}\)\@!' || line =~# '{!!\%(.*!!}\)\@!'
return increase
+ elseif line =~# '<?\%(.*?>\)\@!'
+ return indent(lnum-1) == -1 ? increase : indent(lnum) + increase
else
return indent
endif
diff --git a/indent/go.vim b/indent/go.vim
index 102d3495..fd973e45 100644
--- a/indent/go.vim
+++ b/indent/go.vim
@@ -11,7 +11,7 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'go') == -1
" - general line splits (line ends in an operator)
if exists("b:did_indent")
- finish
+ finish
endif
let b:did_indent = 1
@@ -23,60 +23,60 @@ setlocal indentexpr=GoIndent(v:lnum)
setlocal indentkeys+=<:>,0=},0=)
if exists("*GoIndent")
- finish
+ finish
endif
" use shiftwidth function only if it's available
if exists('*shiftwidth')
- func s:sw()
- return shiftwidth()
- endfunc
+ func s:sw()
+ return shiftwidth()
+ endfunc
else
- func s:sw()
- return &sw
- endfunc
+ func s:sw()
+ return &sw
+ endfunc
endif
function! GoIndent(lnum)
- let prevlnum = prevnonblank(a:lnum-1)
- if prevlnum == 0
- " top of file
- return 0
- endif
+ let prevlnum = prevnonblank(a:lnum-1)
+ if prevlnum == 0
+ " top of file
+ return 0
+ endif
- " grab the previous and current line, stripping comments.
- let prevl = substitute(getline(prevlnum), '//.*$', '', '')
- let thisl = substitute(getline(a:lnum), '//.*$', '', '')
- let previ = indent(prevlnum)
+ " grab the previous and current line, stripping comments.
+ let prevl = substitute(getline(prevlnum), '//.*$', '', '')
+ let thisl = substitute(getline(a:lnum), '//.*$', '', '')
+ let previ = indent(prevlnum)
- let ind = previ
+ let ind = previ
- if prevl =~ '[({]\s*$'
- " previous line opened a block
- let ind += s:sw()
- endif
- if prevl =~# '^\s*\(case .*\|default\):$'
- " previous line is part of a switch statement
- let ind += s:sw()
- endif
- " TODO: handle if the previous line is a label.
+ if prevl =~ '[({]\s*$'
+ " previous line opened a block
+ let ind += s:sw()
+ endif
+ if prevl =~# '^\s*\(case .*\|default\):$'
+ " previous line is part of a switch statement
+ let ind += s:sw()
+ endif
+ " TODO: handle if the previous line is a label.
- if thisl =~ '^\s*[)}]'
- " this line closed a block
- let ind -= s:sw()
- endif
+ if thisl =~ '^\s*[)}]'
+ " this line closed a block
+ let ind -= s:sw()
+ endif
- " Colons are tricky.
- " We want to outdent if it's part of a switch ("case foo:" or "default:").
- " We ignore trying to deal with jump labels because (a) they're rare, and
- " (b) they're hard to disambiguate from a composite literal key.
- if thisl =~# '^\s*\(case .*\|default\):$'
- let ind -= s:sw()
- endif
+ " Colons are tricky.
+ " We want to outdent if it's part of a switch ("case foo:" or "default:").
+ " We ignore trying to deal with jump labels because (a) they're rare, and
+ " (b) they're hard to disambiguate from a composite literal key.
+ if thisl =~# '^\s*\(case .*\|default\):$'
+ let ind -= s:sw()
+ endif
- return ind
+ return ind
endfunction
-" vim:ts=4:sw=4:et
+" vim: sw=2 ts=2 et
endif
diff --git a/indent/gohtmltmpl.vim b/indent/gohtmltmpl.vim
index e1708552..898e36b0 100644
--- a/indent/gohtmltmpl.vim
+++ b/indent/gohtmltmpl.vim
@@ -45,4 +45,6 @@ function! GetGoHTMLTmplIndent(lnum)
return ind
endfunction
+" vim: sw=2 ts=2 et
+
endif
diff --git a/indent/javascript.vim b/indent/javascript.vim
index 24f394c1..99ad0d44 100644
--- a/indent/javascript.vim
+++ b/indent/javascript.vim
@@ -19,7 +19,7 @@ setlocal nosmartindent
setlocal indentexpr=GetJavascriptIndent()
setlocal formatexpr=Fixedgq(v:lnum,v:count)
setlocal indentkeys=0{,0},0),0],0\,*<Return>,:,!^F,o,O,e
-setlocal cinoptions+=j1,J1
+setlocal cinoptions+=j1,J1,c1
" Only define the function once.
if exists("*GetJavascriptIndent")
@@ -45,7 +45,7 @@ endif
let s:line_pre = '^\s*\%(\/\*.*\*\/\s*\)*'
let s:js_keywords = s:line_pre . '\%(break\|import\|export\|catch\|const\|continue\|debugger\|delete\|do\|else\|finally\|for\|function\|if\|in\|instanceof\|let\|new\|return\|switch\|this\|throw\|try\|typeof\|var\|void\|while\|with\)\>\C'
-let s:expr_case = s:line_pre . '\%(case\s\+[^\:]*\|default\)\s*:\s*\C'
+let s:expr_case = s:line_pre . '\%(\%(case\>.*\)\|default\)\s*:\C'
" Regex of syntax group names that are or delimit string or are comments.
let s:syng_strcom = '\%(string\|regex\|special\|doc\|comment\|template\)\c'
@@ -79,7 +79,7 @@ function s:Onescope(lnum)
end
let mypos = col('.')
call cursor(a:lnum, 1)
- if search('\<\%(while\|for\|if\)\>\s*(\C', 'ce', a:lnum) > 0 &&
+ if search('.*\zs\<\%(while\|for\|if\)\>\s*(\C', 'ce', a:lnum) > 0 &&
\ s:lookForParens('(', ')', 'W', a:lnum) > 0 &&
\ col('.') == strlen(s:RemoveTrailingComments(getline(a:lnum)))
call cursor(a:lnum, mypos)
@@ -142,7 +142,7 @@ function s:GetMSL(lnum, in_one_line_scope)
" Start on the line we're at and use its indent.
let msl = a:lnum
let lnum = s:PrevNonBlankNonString(a:lnum - 1)
- while lnum > 0
+ while lnum > 0 && !s:Match(msl,s:line_pre . '[])}]')
" If we have a continuation line, or we're in a string, use line as MSL.
" Otherwise, terminate search as we have found our MSL already.
let line = getline(lnum)
@@ -314,6 +314,7 @@ function GetJavascriptIndent()
" 3.1. Setup {{{1
" ----------
" Set up variables for restoring position in file. Could use v:lnum here.
+ " Avoid use of line('.')/col('.') type functions as the curpos can change
let vcol = col('.')
" 3.2. Work on the current line {{{1
@@ -336,21 +337,25 @@ function GetJavascriptIndent()
if line !~ '^\%(\/\*\|\s*\/\/\)' && s:IsInComment(v:lnum, 1)
return cindent(v:lnum)
endif
-
+
" single opening bracket will assume you want a c style of indenting
- if s:Match(v:lnum, s:line_pre . '{' . s:line_term) && !s:Match(lnum,s:block_regex) &&
+ if line =~ s:line_pre . '{' && !s:Match(lnum,s:block_regex) &&
\ !s:Match(lnum,s:comma_last)
return cindent(v:lnum)
endif
" cindent each line which has a switch label
if (line =~ s:expr_case)
- return cindent(v:lnum)
+ let s:cpo_switch = &cpo
+ set cpo+=%
+ let ind = cindent(v:lnum)
+ let &cpo = s:cpo_switch
+ return ind
endif
" If we got a closing bracket on an empty line, find its match and indent
" according to it.
- let col = s:Match(v:lnum, s:line_pre . '[]})]')
+ let col = line =~ s:line_pre . '[]})]'
if col > 0
let parlnum = v:lnum
while col
@@ -361,8 +366,8 @@ function GetJavascriptIndent()
continue
end
if parlnum > 0
- let ind = s:InMultiVarStatement(parlnum, 0, 0)|| s:LineHasOpeningBrackets(parlnum) !~ '2'
- \ ? indent(parlnum) : indent(s:GetMSL(parlnum, 0))
+ let ind = s:InMultiVarStatement(parlnum, 0, 0)|| s:LineHasOpeningBrackets(parlnum) !~ '2' ?
+ \ indent(parlnum) : indent(s:GetMSL(parlnum, 0))
endif
endwhile
return ind
@@ -371,7 +376,8 @@ function GetJavascriptIndent()
" If line starts with an operator...
if (line =~ s:operator_first)
- if (s:Match(lnum, s:operator_first) || s:Match(lnum, s:line_pre . '[])}]'))
+ if (s:Match(lnum, s:operator_first) || (s:Match(lnum, s:line_pre . '[])}]') &&
+ \ !(s:Match(v:lnum,s:line_pre . '\.') && s:Match(lnum, ')' . s:line_term))))
" and so does previous line, don't indent
return indent(lnum)
end
@@ -391,13 +397,15 @@ function GetJavascriptIndent()
end
" If previous line starts with an operator...
- elseif (s:Match(lnum, s:operator_first) && !s:Match(lnum,s:continuation_regex))||getline(lnum) =~ ');\=' . s:line_term
+ elseif (s:Match(lnum, s:operator_first) && !s:Match(lnum,s:continuation_regex)) ||
+ \ getline(lnum) =~ '[]})];\=' . s:line_term
let counts = s:LineHasOpeningBrackets(lnum)
- if counts[0] == '2' && !s:Match(lnum, s:operator_first)
+ if counts =~ '2' && !s:Match(lnum, s:operator_first)
call cursor(lnum, 1)
" Search for the opening tag
- let mnum = s:lookForParens('(', ')', 'nbW', 0)
- if mnum > 0 && s:Match(mnum, s:operator_first)
+ let mnum = s:lookForParens('(\|{\|\[', ')\|}\|\]', 'nbW', 0)
+ if mnum > 0 && (s:Match(mnum, s:operator_first) ||
+ \ (s:Onescope(s:PrevNonBlankNonString(mnum - 1))) && !s:Match(mnum, s:line_pre . '{'))
return indent(mnum) - s:sw()
end
elseif s:Match(lnum, s:operator_first)
@@ -413,7 +421,7 @@ function GetJavascriptIndent()
" If the line is empty and the previous nonblank line was a multi-line
" comment, use that comment's indent. Deduct one char to account for the
" space in ' */'.
- if line =~ '^\s*$' && getline(prevline) !~ '\%(\%(^\s*\/\/\|\/\*\).*\)\@<!\*\/' &&
+ if line =~ '^\s*$' && getline(prevline) =~ '\%(\%(^\s*\/\/\|\/\*\).*\)\@<!\*\/' &&
\ s:IsInComment(prevline, 1)
return indent(prevline) - 1
endif
@@ -430,16 +438,6 @@ function GetJavascriptIndent()
return 0
endif
-" foo('foo',
-" bar('bar', function() {
-" hi();
-" })
-" );
-
-" function (a, b, c, d,
-" e, f, g) {
-" console.log('inner');
-" }
" If the previous line ended with a block opening, add a level of indent.
if s:Match(lnum, s:block_regex)
return s:InMultiVarStatement(lnum, 0, 0) || s:LineHasOpeningBrackets(lnum) !~ '2' ?
@@ -451,15 +449,16 @@ function GetJavascriptIndent()
let ind = indent(lnum)
" If the previous line contained an opening bracket, and we are still in it,
" add indent depending on the bracket type.
- if s:Match(lnum, '\%([[({]\)\|\%([^\t \])}][})\]]\)')
+ if s:Match(lnum, '[[({})\]]')
let counts = s:LineHasOpeningBrackets(lnum)
if counts =~ '2'
- call cursor(lnum,matchend(s:RemoveTrailingComments(line), '.\+\zs[])}]'))
+ call cursor(lnum,matchend(s:RemoveTrailingComments(line), '.*\zs[])}]'))
while s:lookForParens('(\|{\|\[', ')\|}\|\]', 'bW', 0) == lnum
call cursor(lnum, matchend(s:RemoveTrailingComments(strpart(line,0,col('.'))), '.*\zs[])}]'))
endwhile
- if line('.') < lnum && !s:InMultiVarStatement(line('.'),0,0)
- return indent(s:GetMSL(line('.'), 0))
+ let cur = line('.')
+ if cur < lnum && !s:InMultiVarStatement(cur,0,0)
+ return indent(s:GetMSL(cur, 0))
end
elseif counts =~ '1' || s:Onescope(lnum)
return ind + s:sw()
@@ -502,64 +501,64 @@ let &cpo = s:cpo_save
unlet s:cpo_save
" gq{{{2
function! Fixedgq(lnum, count)
- let l:tw = &tw ? &tw : 80;
+ let l:tw = &tw ? &tw : 80;
- let l:count = a:count
- let l:first_char = indent(a:lnum) + 1
+ let l:count = a:count
+ let l:first_char = indent(a:lnum) + 1
- if mode() == 'i' " gq was not pressed, but tw was set
- return 1
- endif
+ if mode() == 'i' " gq was not pressed, but tw was set
+ return 1
+ endif
- " This gq is only meant to do code with strings, not comments
- if s:IsInComment(a:lnum, l:first_char)
- return 1
- endif
+ " This gq is only meant to do code with strings, not comments
+ if s:IsInComment(a:lnum, l:first_char)
+ return 1
+ endif
- if len(getline(a:lnum)) < l:tw && l:count == 1 " No need for gq
- return 1
- endif
+ if len(getline(a:lnum)) < l:tw && l:count == 1 " No need for gq
+ return 1
+ endif
- " Put all the lines on one line and do normal spliting after that
- if l:count > 1
- while l:count > 1
- let l:count -= 1
- normal J
- endwhile
- endif
+ " Put all the lines on one line and do normal spliting after that
+ if l:count > 1
+ while l:count > 1
+ let l:count -= 1
+ normal J
+ endwhile
+ endif
- let l:winview = winsaveview()
+ let l:winview = winsaveview()
- call cursor(a:lnum, l:tw + 1)
- let orig_breakpoint = searchpairpos(' ', '', '\.', 'bcW', '', a:lnum)
- call cursor(a:lnum, l:tw + 1)
- let breakpoint = searchpairpos(' ', '', '\.', 'bcW', s:skip_expr, a:lnum)
+ call cursor(a:lnum, l:tw + 1)
+ let orig_breakpoint = searchpairpos(' ', '', '\.', 'bcW', '', a:lnum)
+ call cursor(a:lnum, l:tw + 1)
+ let breakpoint = searchpairpos(' ', '', '\.', 'bcW', s:skip_expr, a:lnum)
- " No need for special treatment, normal gq handles edgecases better
- if breakpoint[1] == orig_breakpoint[1]
- call winrestview(l:winview)
- return 1
- endif
+ " No need for special treatment, normal gq handles edgecases better
+ if breakpoint[1] == orig_breakpoint[1]
+ call winrestview(l:winview)
+ return 1
+ endif
- " Try breaking after string
- if breakpoint[1] <= indent(a:lnum)
- call cursor(a:lnum, l:tw + 1)
- let breakpoint = searchpairpos('\.', '', ' ', 'cW', s:skip_expr, a:lnum)
- endif
+ " Try breaking after string
+ if breakpoint[1] <= indent(a:lnum)
+ call cursor(a:lnum, l:tw + 1)
+ let breakpoint = searchpairpos('\.', '', ' ', 'cW', s:skip_expr, a:lnum)
+ endif
- if breakpoint[1] != 0
- call feedkeys("r\<CR>")
- else
- let l:count = l:count - 1
- endif
+ if breakpoint[1] != 0
+ call feedkeys("r\<CR>")
+ else
+ let l:count = l:count - 1
+ endif
- " run gq on new lines
- if l:count == 1
- call feedkeys("gqq")
- endif
+ " run gq on new lines
+ if l:count == 1
+ call feedkeys("gqq")
+ endif
- return 0
+ return 0
endfunction
"}}}
" vim: foldmethod=marker:foldlevel=1
diff --git a/indent/proto.vim b/indent/proto.vim
new file mode 100644
index 00000000..bf558e76
--- /dev/null
+++ b/indent/proto.vim
@@ -0,0 +1,21 @@
+if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'protobuf') == -1
+
+" Vim indent file
+" Language: Protobuf
+" Maintainer: Johannes Zellner <johannes@zellner.org>
+" Last Change: Fri, 15 Mar 2002 07:53:54 CET
+
+" Only load this indent file when no other was loaded.
+if exists("b:did_indent")
+ finish
+endif
+let b:did_indent = 1
+
+" Protobuf is like indenting C
+setlocal cindent
+setlocal expandtab
+setlocal shiftwidth=2
+
+let b:undo_indent = "setl cin<"
+
+endif