blob: 6ce30b67978e0e961c7ec67e208d4402441ad3c6 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim indent file
2" Language: SDL
Bram Moolenaarb6b046b2011-12-30 13:11:27 +01003" Maintainer: Michael Piefel <entwurf@piefel.de>
4" Last Change: 10 December 2011
Bram Moolenaar071d4272004-06-13 20:20:40 +00005
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
Bram Moolenaarb6b046b2011-12-30 13:11:27 +010022let s:cpo_save = &cpo
23set cpo&vim
Bram Moolenaar071d4272004-06-13 20:20:40 +000024
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:]]\+;$'
Bram Moolenaar3ec574f2017-06-13 18:12:01 +020049 let ind = ind + shiftwidth()
Bram Moolenaar071d4272004-06-13 20:20:40 +000050 endif
51
52 " Subtract a 'shiftwidth' after states
53 if getline(lnum) =~? '^\s*\(stop\|return\>\|nextstate\)'
Bram Moolenaar3ec574f2017-06-13 18:12:01 +020054 let ind = ind - shiftwidth()
Bram Moolenaar071d4272004-06-13 20:20:40 +000055 endif
56
57 " Subtract a 'shiftwidth' on on end (uncompleted line)
58 if getline(v:lnum) =~? '^\s*end\>'
Bram Moolenaar3ec574f2017-06-13 18:12:01 +020059 let ind = ind - shiftwidth()
Bram Moolenaar071d4272004-06-13 20:20:40 +000060 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\)'
Bram Moolenaar34700a62013-03-07 13:20:54 +010076 return 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000077 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
Bram Moolenaarb6b046b2011-12-30 13:11:27 +010090let &cpo = s:cpo_save
91unlet s:cpo_save
92
Bram Moolenaar071d4272004-06-13 20:20:40 +000093" vim:sw=2