Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " Vim indent file |
| 2 | " Language: SDL |
Bram Moolenaar | b6b046b | 2011-12-30 13:11:27 +0100 | [diff] [blame] | 3 | " Maintainer: Michael Piefel <entwurf@piefel.de> |
| 4 | " Last Change: 10 December 2011 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | b6b046b | 2011-12-30 13:11:27 +0100 | [diff] [blame] | 22 | let s:cpo_save = &cpo |
| 23 | set cpo&vim |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 24 | |
| 25 | function! 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 |
| 88 | endfunction |
| 89 | |
Bram Moolenaar | b6b046b | 2011-12-30 13:11:27 +0100 | [diff] [blame] | 90 | let &cpo = s:cpo_save |
| 91 | unlet s:cpo_save |
| 92 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 93 | " vim:sw=2 |