robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
327e3fab9e
master
1" Vim indent file 2" Language: NSIS script 3" Maintainer: Ken Takata 4" URL: https://github.com/k-takata/vim-nsis 5" Last Change: 2021-10-18 6" Filenames: *.nsi 7" License: VIM License 8 9if exists ( "b:did_indent" ) 10finish 11endif 12let b: did_indent = 1 13 14setlocal nosmartindent 15setlocal noautoindent 16setlocal indentexpr = GetNsisIndent (v:lnum) 17setlocal indentkeys = !^F,o,O 18setlocal indentkeys += =~${Else,=~${EndIf,=~${EndUnless,=~${AndIf,=~${AndUnless,=~${OrIf,=~${OrUnless,=~${Case,=~${Default,=~${EndSelect,=~${EndSwitch,=~${Loop,=~${Next,=~${MementoSectionEnd,=~FunctionEnd,=~SectionEnd,=~SectionGroupEnd,=~PageExEnd,0=~!macroend,0=~!if,0=~!else,0=~!endif 19 20let b: undo_indent = "setl ai< inde< indk< si<" 21 22if exists ( "*GetNsisIndent" ) 23finish 24endif 25 26function ! GetNsisIndent ( lnum ) 27" If this line is explicitly joined: If the previous line was also joined, 28" line it up with that one, otherwise add two 'shiftwidth' 29if getline ( a: lnum - 1 ) =~ '\\$' 30if a: lnum > 1 && getline ( a: lnum - 2 ) =~ '\\$' 31return indent ( a: lnum - 1 ) 32endif 33return indent ( a: lnum - 1 ) + shiftwidth () * 2 34endif 35 36" Grab the current line, stripping comments. 37let l: thisl = substitute ( getline ( a: lnum ), '[;#].*$' , '' , '' ) 38" Check if this line is a conditional preprocessor line. 39let l: preproc = l: thisl =~? '^\s*!\%(if\|else\|endif\)' 40 41" Grab the previous line, stripping comments. 42" Skip preprocessor lines and continued lines. 43let l: prevlnum = a: lnum 44while 1 45let l: prevlnum = prevnonblank ( l: prevlnum - 1 ) 46if l: prevlnum == 0 47" top of file 48return 0 49endif 50let l: prevl = substitute ( getline ( l: prevlnum ), '[;#].*$' , '' , '' ) 51let l: prevpreproc = l: prevl =~? '^\s*!\%(if\|else\|endif\)' 52if l: preproc == l: prevpreproc && getline ( l: prevlnum - 1 ) !~? '\\$' 53break 54endif 55endwhile 56let l: previ = indent ( l: prevlnum ) 57let l: ind = l: previ 58 59if l: preproc 60" conditional preprocessor 61if l: prevl =~? '^\s*!\%(if\%(\%(macro\)\?n\?def\)\?\|else\)\>' 62let l: ind += shiftwidth () 63endif 64if l: thisl =~? '^\s*!\%(else\|endif\)\?\>' 65let l: ind -= shiftwidth () 66endif 67return l: ind 68endif 69 70if l: prevl =~? '^\s*\%(\${\%(If\|IfNot\|Unless\|ElseIf\|ElseIfNot\|ElseUnless\|Else\|AndIf\|AndIfNot\|AndUnless\|OrIf\|OrIfNot\|OrUnless\|Select\|Case\|Case[2-5]\|CaseElse\|Default\|Switch\|Do\|DoWhile\|DoUntil\|For\|ForEach\|MementoSection\)}\|Function\>\|Section\>\|SectionGroup\|PageEx\>\|!macro\>\)' 71" previous line opened a block 72let l: ind += shiftwidth () 73endif 74if l: thisl =~? '^\s*\%(\${\%(ElseIf\|ElseIfNot\|ElseUnless\|Else\|EndIf\|EndUnless\|AndIf\|AndIfNot\|AndUnless\|OrIf\|OrIfNot\|OrUnless\|Loop\|LoopWhile\|LoopUntil\|Next\|MementoSectionEnd\)\>}\?\|FunctionEnd\>\|SectionEnd\>\|SectionGroupEnd\|PageExEnd\>\|!macroend\>\)' 75" this line closed a block 76let l: ind -= shiftwidth () 77elseif l: thisl =~? '^\s*\${\%(Case\|Case[2-5]\|CaseElse\|Default\)\>}\?' 78if l: prevl !~? '^\s*\${\%(Select\|Switch\)}' 79let l: ind -= shiftwidth () 80endif 81elseif l: thisl =~? '^\s*\${\%(EndSelect\|EndSwitch\)\>}\?' 82" this line closed a block 83if l: prevl =~? '^\s*\${\%(Select\|Switch\)}' 84let l: ind -= shiftwidth () 85else 86let l: ind -= shiftwidth () * 2 87endif 88endif 89 90return l: ind 91endfunction 92 93" vim: ts=8 sw=2 sts=2