2019-03-04 03:28:35 -05:00
|
|
|
if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'plantuml') != -1
|
|
|
|
finish
|
|
|
|
endif
|
|
|
|
|
2019-06-08 06:44:15 -04:00
|
|
|
scriptencoding utf-8
|
|
|
|
" Vim indent file
|
|
|
|
" Language: PlantUML
|
|
|
|
" Maintainer: Anders Thøgersen <first name at bladre dot dk>
|
|
|
|
" License: VIM LICENSE
|
|
|
|
|
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
|
|
|
|
|
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)
|
|
|
|
|
2019-06-08 06:44:15 -04:00
|
|
|
let s:incIndent = s:getIncIndent()
|
|
|
|
|
2016-12-20 14:57:20 -05:00
|
|
|
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
|
2019-06-08 06:44:15 -04:00
|
|
|
|
|
|
|
function! s:listSyntax(syntaxKeyword) abort
|
|
|
|
" Get a list of words assigned to a syntax keyword
|
|
|
|
" The 'syntax list <syntax keyword>' command returns
|
|
|
|
" a string with the keyword itself, followed by xxx,
|
|
|
|
" on which we can split to extract the keywords string.
|
|
|
|
" This string must then be split on whitespace
|
|
|
|
let syntaxWords = split(
|
|
|
|
\ execute('syntax list ' . a:syntaxKeyword),
|
|
|
|
\ a:syntaxKeyword . ' xxx ')[-1]
|
|
|
|
return split(syntaxWords)
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:typeKeywordIncPattern() abort
|
|
|
|
" Extract keywords for plantumlTypeKeyword, returning the inc pattern
|
|
|
|
let syntaxWords = join(s:listSyntax('plantumlTypeKeyword'), '\\\|')
|
|
|
|
return '^\s*\%(' . syntaxWords . '\)\>.*{'
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:getIncIndent() abort
|
|
|
|
" Function to determine the s:incIndent pattern
|
|
|
|
return
|
|
|
|
\ '^\s*\%(class\|object\|interface\|partition\|rectangle\|enum\|namespace\)\>.*{\s*$\|' .
|
|
|
|
\ '^\s*\%(loop\|alt\|opt\|group\|critical\|else\|legend\|box\|if\|while\|fork\|split\)\>\|' .
|
|
|
|
\ '^\s*ref\>[^:]*$\|' .
|
|
|
|
\ '^\s*[hr]\?note\>\%(\%("[^"]*" \<as\>\)\@![^:]\)*$\|' .
|
|
|
|
\ '^\s*title\s*$\|' .
|
|
|
|
\ '^\s*skinparam\>.*{\s*$\|' .
|
|
|
|
\ s:typeKeywordIncPattern()
|
|
|
|
endfunction
|