vim-polyglot/indent/dart.vim

40 lines
824 B
VimL
Raw Normal View History

if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'dart') != -1
finish
endif
2015-12-06 05:38:02 -05:00
if exists('b:did_indent')
finish
endif
let b:did_indent = 1
setlocal cindent
2018-10-08 13:00:59 -04:00
setlocal cinoptions+=j1,J1,(2s,u2s,U1,m1,+2s
2015-12-06 05:38:02 -05:00
2016-12-20 14:57:20 -05:00
setlocal indentexpr=DartIndent()
2015-12-06 05:38:02 -05:00
let b:undo_indent = 'setl cin< cino<'
2016-12-20 14:57:20 -05:00
if exists("*DartIndent")
finish
endif
function! DartIndent()
" Default to cindent in most cases
let indentTo = cindent(v:lnum)
let previousLine = getline(prevnonblank(v:lnum - 1))
let currentLine = getline(v:lnum)
" Don't indent after an annotation
if previousLine =~# '^\s*@.*$'
let indentTo = indent(v:lnum - 1)
endif
" Indent after opening List literal
if previousLine =~# '\[$' && !(currentLine =~# '^\s*\]')
let indentTo = indent(v:lnum - 1) + &shiftwidth
endif
return indentTo
endfunction