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> |
Bram Moolenaar | 6e64922 | 2021-10-04 21:32:54 +0100 | [diff] [blame] | 4 | " Last Change: 2021 Oct 03 |
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 | |
Bram Moolenaar | 6e64922 | 2021-10-04 21:32:54 +0100 | [diff] [blame] | 17 | let b:undo_indent = "setl inde< indk<" |
| 18 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 19 | " Only define the function once. |
| 20 | if exists("*GetSDLIndent") |
| 21 | " finish |
| 22 | endif |
| 23 | |
Bram Moolenaar | b6b046b | 2011-12-30 13:11:27 +0100 | [diff] [blame] | 24 | let s:cpo_save = &cpo |
| 25 | set cpo&vim |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 26 | |
| 27 | function! GetSDLIndent() |
| 28 | " Find a non-blank line above the current line. |
| 29 | let lnum = prevnonblank(v:lnum - 1) |
| 30 | |
| 31 | " At the start of the file use zero indent. |
| 32 | if lnum == 0 |
| 33 | return 0 |
| 34 | endif |
| 35 | |
| 36 | let ind = indent(lnum) |
| 37 | let virtuality = '^\s*\(\(virtual\|redefined\|finalized\)\s\+\)\=\s*' |
| 38 | |
| 39 | " Add a single space to comments which use asterisks |
| 40 | if getline(lnum) =~ '^\s*\*' |
| 41 | let ind = ind - 1 |
| 42 | endif |
| 43 | if getline(v:lnum) =~ '^\s*\*' |
| 44 | let ind = ind + 1 |
| 45 | endif |
| 46 | |
| 47 | " Add a 'shiftwidth' after states, different blocks, decision (and alternatives), inputs |
| 48 | 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\)' |
| 49 | \ || getline(lnum) =~? virtuality . '\(process\|procedure\|block\|object\)') |
| 50 | \ && getline(lnum) !~? 'end[[:alpha:]]\+;$' |
Bram Moolenaar | 3ec574f | 2017-06-13 18:12:01 +0200 | [diff] [blame] | 51 | let ind = ind + shiftwidth() |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 52 | endif |
| 53 | |
| 54 | " Subtract a 'shiftwidth' after states |
| 55 | if getline(lnum) =~? '^\s*\(stop\|return\>\|nextstate\)' |
Bram Moolenaar | 3ec574f | 2017-06-13 18:12:01 +0200 | [diff] [blame] | 56 | let ind = ind - shiftwidth() |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 57 | endif |
| 58 | |
| 59 | " Subtract a 'shiftwidth' on on end (uncompleted line) |
| 60 | if getline(v:lnum) =~? '^\s*end\>' |
Bram Moolenaar | 3ec574f | 2017-06-13 18:12:01 +0200 | [diff] [blame] | 61 | let ind = ind - shiftwidth() |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 62 | endif |
| 63 | |
| 64 | " Put each alternatives where the corresponding decision was |
| 65 | if getline(v:lnum) =~? '^\s*\((.*)\|else\):' |
| 66 | normal k |
| 67 | let ind = indent(searchpair('^\s*decision', '', '^\s*enddecision', 'bW', |
| 68 | \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "sdlString"')) |
| 69 | endif |
| 70 | |
| 71 | " Put each state where the preceding state was |
| 72 | if getline(v:lnum) =~? '^\s*state\>' |
| 73 | let ind = indent(search('^\s*start', 'bW')) |
| 74 | endif |
| 75 | |
| 76 | " Systems and packages are always in column 0 |
| 77 | if getline(v:lnum) =~? '^\s*\(\(end\)\=system\|\(end\)\=package\)' |
Bram Moolenaar | 34700a6 | 2013-03-07 13:20:54 +0100 | [diff] [blame] | 78 | return 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 79 | endif |
| 80 | |
| 81 | " Put each end* where the corresponding begin was |
| 82 | if getline(v:lnum) =~? '^\s*end[[:alpha:]]' |
| 83 | normal k |
| 84 | let partner=matchstr(getline(v:lnum), '\(' . virtuality . 'end\)\@<=[[:alpha:]]\+') |
| 85 | let ind = indent(searchpair(virtuality . partner, '', '^\s*end' . partner, 'bW', |
| 86 | \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "sdlString"')) |
| 87 | endif |
| 88 | |
| 89 | return ind |
| 90 | endfunction |
| 91 | |
Bram Moolenaar | b6b046b | 2011-12-30 13:11:27 +0100 | [diff] [blame] | 92 | let &cpo = s:cpo_save |
| 93 | unlet s:cpo_save |
| 94 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 95 | " vim:sw=2 |