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