2016-09-11 07:24:17 -04:00
|
|
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'plantuml') == -1
|
|
|
|
|
2017-05-17 05:07:28 -04:00
|
|
|
if exists('b:did_indent')
|
2016-09-11 07:24:17 -04:00
|
|
|
finish
|
|
|
|
endif
|
|
|
|
let b:did_indent = 1
|
|
|
|
|
|
|
|
setlocal indentexpr=GetPlantUMLIndent()
|
|
|
|
setlocal indentkeys=o,O,<CR>,<:>,!^F,0end,0else,}
|
|
|
|
|
|
|
|
" only define the indent code once
|
2017-05-17 05:07:28 -04:00
|
|
|
if exists('*GetPlantUMLIndent')
|
2016-09-11 07:24:17 -04:00
|
|
|
finish
|
|
|
|
endif
|
|
|
|
|
|
|
|
let s:incIndent =
|
2016-12-20 14:57:20 -05:00
|
|
|
\ '^\s*\%(loop\|alt\|opt\|group\|critical\|else\|legend\|box\|if\|while\)\>\|' .
|
|
|
|
\ '^\s*ref\>[^:]*$\|' .
|
|
|
|
\ '^\s*[hr]\?note\>\%(\%("[^"]*" \<as\>\)\@![^:]\)*$\|' .
|
|
|
|
\ '^\s*title\s*$\|' .
|
|
|
|
\ '^\s*skinparam\>.*{\s*$\|' .
|
2017-09-27 13:57:29 -04:00
|
|
|
\ '^\s*\%(state\|class\|partition\|rectangle\|enum\|interface\|namespace\|object\)\>.*{'
|
2016-09-11 07:24:17 -04:00
|
|
|
|
2016-12-20 14:57:20 -05:00
|
|
|
let s:decIndent = '^\s*\%(end\|else\|}\)'
|
2016-09-11 07:24:17 -04:00
|
|
|
|
|
|
|
function! GetPlantUMLIndent(...) abort
|
2016-12-20 14:57:20 -05:00
|
|
|
"for current line, use arg if given or v:lnum otherwise
|
|
|
|
let clnum = a:0 ? a:1 : v:lnum
|
|
|
|
|
|
|
|
if !s:insidePlantUMLTags(clnum)
|
|
|
|
return indent(clnum)
|
|
|
|
endif
|
|
|
|
|
|
|
|
let pnum = prevnonblank(clnum-1)
|
|
|
|
let pindent = indent(pnum)
|
|
|
|
let pline = getline(pnum)
|
|
|
|
let cline = getline(clnum)
|
|
|
|
|
|
|
|
if cline =~ s:decIndent
|
|
|
|
if pline =~ s:incIndent
|
|
|
|
return pindent
|
|
|
|
else
|
|
|
|
return pindent - shiftwidth()
|
2016-09-11 07:24:17 -04:00
|
|
|
endif
|
|
|
|
|
2016-12-20 14:57:20 -05:00
|
|
|
elseif pline =~ s:incIndent
|
|
|
|
return pindent + shiftwidth()
|
|
|
|
endif
|
2016-09-11 07:24:17 -04:00
|
|
|
|
2016-12-20 14:57:20 -05:00
|
|
|
return pindent
|
2016-09-11 07:24:17 -04:00
|
|
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:insidePlantUMLTags(lnum) abort
|
2016-12-20 14:57:20 -05:00
|
|
|
call cursor(a:lnum, 1)
|
|
|
|
return search('@startuml', 'Wbn') && search('@enduml', 'Wn')
|
2016-09-11 07:24:17 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
endif
|