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