diff options
author | Adam Stankiewicz <sheerun@sher.pl> | 2016-09-11 13:24:17 +0200 |
---|---|---|
committer | Adam Stankiewicz <sheerun@sher.pl> | 2016-09-11 13:24:17 +0200 |
commit | 0244e228faf6ee71750cbca3bdcd18411a927d22 (patch) | |
tree | a72e5c9839ea593f6edc23f7f0e637e0a4a89413 /indent/plantuml.vim | |
parent | ab61d2ac8eafc9c10097577736602da48ec568ca (diff) | |
download | vim-polyglot-0244e228faf6ee71750cbca3bdcd18411a927d22.tar.gz vim-polyglot-0244e228faf6ee71750cbca3bdcd18411a927d22.zip |
Update
Diffstat (limited to '')
-rw-r--r-- | indent/plantuml.vim | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/indent/plantuml.vim b/indent/plantuml.vim new file mode 100644 index 00000000..3e0f455d --- /dev/null +++ b/indent/plantuml.vim @@ -0,0 +1,58 @@ +if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'plantuml') == -1 + +if exists("b:did_indent") + finish +endif +let b:did_indent = 1 + +setlocal indentexpr=GetPlantUMLIndent() +setlocal indentkeys=o,O,<CR>,<:>,!^F,0end,0else,} + +" only define the indent code once +if exists("*GetPlantUMLIndent") + finish +endif + +let s:incIndent = + \ '^\s*\(loop\|alt\|opt\|group\|critical\|else\|legend\|box\)\>\|' . + \ '^\s*\([hr]\?note\|ref\)\>[^:]*$\|' . + \ '^\s*title\s*$\|' . + \ '^\s*skinparam\>.*{\s*$\|' . + \ '^\s*state\>.*{' + +let s:decIndent = '^\s*\(end\|else\|}\)' + +function! GetPlantUMLIndent(...) abort + "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() + endif + + elseif pline =~ s:incIndent + return pindent + shiftwidth() + endif + + return pindent + +endfunction + +function! s:insidePlantUMLTags(lnum) abort + call cursor(a:lnum, 1) + return search('@startuml', 'Wbn') && search('@enduml', 'Wn') +endfunction + +endif |