xref: /vim-8.2.3635/runtime/indent/nsis.vim (revision 94688b8a)
1" Vim indent file
2" Language:		NSIS script
3" Maintainer:		Ken Takata
4" URL:			https://github.com/k-takata/vim-nsis
5" Last Change:		2018-01-21
6" Filenames:		*.nsi
7" License:		VIM License
8
9if exists("b:did_indent")
10  finish
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,=~${EndSwith,=~${Loop,=~${Next,=~${MementoSectionEnd,=~FunctionEnd,=~SectionEnd,=~SectionGroupEnd,=~PageExEnd,0=~!macroend,0=~!if,0=~!else,0=~!endif
19
20if exists("*GetNsisIndent")
21  finish
22endif
23
24function! GetNsisIndent(lnum)
25  " If this line is explicitly joined: If the previous line was also joined,
26  " line it up with that one, otherwise add two 'shiftwidth'
27  if getline(a:lnum - 1) =~ '\\$'
28    if a:lnum > 1 && getline(a:lnum - 2) =~ '\\$'
29      return indent(a:lnum - 1)
30    endif
31    return indent(a:lnum - 1) + shiftwidth() * 2
32  endif
33
34  " Grab the current line, stripping comments.
35  let l:thisl = substitute(getline(a:lnum), '[;#].*$', '', '')
36  " Check if this line is a conditional preprocessor line.
37  let l:preproc = l:thisl =~? '^\s*!\%(if\|else\|endif\)'
38
39  " Grab the previous line, stripping comments.
40  " Skip preprocessor lines and continued lines.
41  let l:prevlnum = a:lnum
42  while 1
43    let l:prevlnum = prevnonblank(l:prevlnum - 1)
44    if l:prevlnum == 0
45      " top of file
46      return 0
47    endif
48    let l:prevl = substitute(getline(l:prevlnum), '[;#].*$', '', '')
49    let l:prevpreproc = l:prevl =~? '^\s*!\%(if\|else\|endif\)'
50    if l:preproc == l:prevpreproc && getline(l:prevlnum - 1) !~? '\\$'
51      break
52    endif
53  endwhile
54  let l:previ = indent(l:prevlnum)
55  let l:ind = l:previ
56
57  if l:preproc
58    " conditional preprocessor
59    if l:prevl =~? '^\s*!\%(if\%(\%(macro\)\?n\?def\)\?\|else\)\>'
60      let l:ind += shiftwidth()
61    endif
62    if l:thisl =~? '^\s*!\%(else\|endif\)\?\>'
63      let l:ind -= shiftwidth()
64    endif
65    return l:ind
66  endif
67
68  if 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\>\)'
69    " previous line opened a block
70    let l:ind += shiftwidth()
71  endif
72  if 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\>\)'
73    " this line closed a block
74    let l:ind -= shiftwidth()
75  elseif l:thisl =~? '^\s*\${\%(Case\|Case[2-5]\|CaseElse\|Default\)\>}\?'
76    if l:prevl !~? '^\s*\${\%(Select\|Switch\)}'
77      let l:ind -= shiftwidth()
78    endif
79  elseif l:thisl =~? '^\s*\${\%(EndSelect\|EndSwitch\)\>}\?'
80    " this line closed a block
81    if l:prevl =~? '^\s*\${\%(Select\|Switch\)}'
82      let l:ind -= shiftwidth()
83    else
84      let l:ind -= shiftwidth() * 2
85    endif
86  endif
87
88  return l:ind
89endfunction
90
91" vim: ts=8 sw=2 sts=2
92