3 " Maintainer: Michael Piefel <entwurf@piefel.de>
4 " Last Change: 10 December 2011
6 " Shamelessly stolen from the Vim-Script indent file
8 " Only load this indent file when no other was loaded.
9 if exists("b:did_indent")
14 setlocal indentexpr=GetSDLIndent()
15 setlocal indentkeys+==~end,=~state,*<Return>
17 " Only define the function once.
18 if exists("*GetSDLIndent")
25 function! GetSDLIndent()
26 " Find a non-blank line above the current line.
27 let lnum = prevnonblank(v:lnum - 1)
29 " At the start of the file use zero indent.
34 let ind = indent(lnum)
35 let virtuality = '^\s*\(\(virtual\|redefined\|finalized\)\s\+\)\=\s*'
37 " Add a single space to comments which use asterisks
38 if getline(lnum) =~ '^\s*\*'
41 if getline(v:lnum) =~ '^\s*\*'
45 " Add a 'shiftwidth' after states, different blocks, decision (and alternatives), inputs
46 if (getline(lnum) =~? '^\s*\(start\|state\|system\|package\|connection\|channel\|alternative\|macro\|operator\|newtype\|select\|substructure\|decision\|generator\|refinement\|service\|method\|exceptionhandler\|asntype\|syntype\|value\|(.*):\|\(priority\s\+\)\=input\|provided\)'
47 \ || getline(lnum) =~? virtuality . '\(process\|procedure\|block\|object\)')
48 \ && getline(lnum) !~? 'end[[:alpha:]]\+;$'
52 " Subtract a 'shiftwidth' after states
53 if getline(lnum) =~? '^\s*\(stop\|return\>\|nextstate\)'
57 " Subtract a 'shiftwidth' on on end (uncompleted line)
58 if getline(v:lnum) =~? '^\s*end\>'
62 " Put each alternatives where the corresponding decision was
63 if getline(v:lnum) =~? '^\s*\((.*)\|else\):'
65 let ind = indent(searchpair('^\s*decision', '', '^\s*enddecision', 'bW',
66 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "sdlString"'))
69 " Put each state where the preceding state was
70 if getline(v:lnum) =~? '^\s*state\>'
71 let ind = indent(search('^\s*start', 'bW'))
74 " Systems and packages are always in column 0
75 if getline(v:lnum) =~? '^\s*\(\(end\)\=system\|\(end\)\=package\)'
79 " Put each end* where the corresponding begin was
80 if getline(v:lnum) =~? '^\s*end[[:alpha:]]'
82 let partner=matchstr(getline(v:lnum), '\(' . virtuality . 'end\)\@<=[[:alpha:]]\+')
83 let ind = indent(searchpair(virtuality . partner, '', '^\s*end' . partner, 'bW',
84 \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "sdlString"'))