xref: /vim-8.2.3635/runtime/indent/sdl.vim (revision 2bf24176)
1" Vim indent file
2" Language:	SDL
3" Maintainer:	Michael Piefel <[email protected]>
4" Last Change:	10 December 2011
5
6" Shamelessly stolen from the Vim-Script indent file
7
8" Only load this indent file when no other was loaded.
9if exists("b:did_indent")
10  finish
11endif
12let b:did_indent = 1
13
14setlocal indentexpr=GetSDLIndent()
15setlocal indentkeys+==~end,=~state,*<Return>
16
17" Only define the function once.
18if exists("*GetSDLIndent")
19"  finish
20endif
21
22let s:cpo_save = &cpo
23set cpo&vim
24
25function! GetSDLIndent()
26  " Find a non-blank line above the current line.
27  let lnum = prevnonblank(v:lnum - 1)
28
29  " At the start of the file use zero indent.
30  if lnum == 0
31    return 0
32  endif
33
34  let ind = indent(lnum)
35  let virtuality = '^\s*\(\(virtual\|redefined\|finalized\)\s\+\)\=\s*'
36
37  " Add a single space to comments which use asterisks
38  if getline(lnum) =~ '^\s*\*'
39    let ind = ind - 1
40  endif
41  if getline(v:lnum) =~ '^\s*\*'
42    let ind = ind + 1
43  endif
44
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:]]\+;$'
49    let ind = ind + &sw
50  endif
51
52  " Subtract a 'shiftwidth' after states
53  if getline(lnum) =~? '^\s*\(stop\|return\>\|nextstate\)'
54    let ind = ind - &sw
55  endif
56
57  " Subtract a 'shiftwidth' on on end (uncompleted line)
58  if getline(v:lnum) =~? '^\s*end\>'
59    let ind = ind - &sw
60  endif
61
62  " Put each alternatives where the corresponding decision was
63  if getline(v:lnum) =~? '^\s*\((.*)\|else\):'
64    normal k
65    let ind = indent(searchpair('^\s*decision', '', '^\s*enddecision', 'bW',
66      \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "sdlString"'))
67  endif
68
69  " Put each state where the preceding state was
70  if getline(v:lnum) =~? '^\s*state\>'
71    let ind = indent(search('^\s*start', 'bW'))
72  endif
73
74  " Systems and packages are always in column 0
75  if getline(v:lnum) =~? '^\s*\(\(end\)\=system\|\(end\)\=package\)'
76    return 0
77  endif
78
79  " Put each end* where the corresponding begin was
80  if getline(v:lnum) =~? '^\s*end[[:alpha:]]'
81    normal k
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"'))
85  endif
86
87  return ind
88endfunction
89
90let &cpo = s:cpo_save
91unlet s:cpo_save
92
93" vim:sw=2
94