blob: 37317812012608a9f2b3dca6003aa48e640dc709 [file] [log] [blame]
Bram Moolenaar40962ec2018-01-28 22:47:25 +01001" Vim indent file
2" Language: NSIS script
3" Maintainer: Ken Takata
4" URL: https://github.com/k-takata/vim-nsis
Bram Moolenaar079ba762021-10-23 12:08:41 +01005" Last Change: 2021-10-18
Bram Moolenaar40962ec2018-01-28 22:47:25 +01006" 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
Viktor Szépe3fc7a7e2023-08-23 21:20:00 +020018setlocal 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
Bram Moolenaar40962ec2018-01-28 22:47:25 +010019
Bram Moolenaar079ba762021-10-23 12:08:41 +010020let b:undo_indent = "setl ai< inde< indk< si<"
21
Bram Moolenaar40962ec2018-01-28 22:47:25 +010022if exists("*GetNsisIndent")
23 finish
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'
29 if getline(a:lnum - 1) =~ '\\$'
30 if a:lnum > 1 && getline(a:lnum - 2) =~ '\\$'
31 return indent(a:lnum - 1)
32 endif
33 return indent(a:lnum - 1) + shiftwidth() * 2
34 endif
35
36 " Grab the current line, stripping comments.
37 let l:thisl = substitute(getline(a:lnum), '[;#].*$', '', '')
38 " Check if this line is a conditional preprocessor line.
39 let l:preproc = l:thisl =~? '^\s*!\%(if\|else\|endif\)'
40
41 " Grab the previous line, stripping comments.
42 " Skip preprocessor lines and continued lines.
43 let l:prevlnum = a:lnum
44 while 1
45 let l:prevlnum = prevnonblank(l:prevlnum - 1)
46 if l:prevlnum == 0
47 " top of file
48 return 0
49 endif
50 let l:prevl = substitute(getline(l:prevlnum), '[;#].*$', '', '')
51 let l:prevpreproc = l:prevl =~? '^\s*!\%(if\|else\|endif\)'
52 if l:preproc == l:prevpreproc && getline(l:prevlnum - 1) !~? '\\$'
53 break
54 endif
55 endwhile
56 let l:previ = indent(l:prevlnum)
57 let l:ind = l:previ
58
59 if l:preproc
60 " conditional preprocessor
61 if l:prevl =~? '^\s*!\%(if\%(\%(macro\)\?n\?def\)\?\|else\)\>'
62 let l:ind += shiftwidth()
63 endif
64 if l:thisl =~? '^\s*!\%(else\|endif\)\?\>'
65 let l:ind -= shiftwidth()
66 endif
67 return l:ind
68 endif
69
70 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\>\)'
71 " previous line opened a block
72 let l:ind += shiftwidth()
73 endif
74 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\>\)'
75 " this line closed a block
76 let l:ind -= shiftwidth()
77 elseif l:thisl =~? '^\s*\${\%(Case\|Case[2-5]\|CaseElse\|Default\)\>}\?'
78 if l:prevl !~? '^\s*\${\%(Select\|Switch\)}'
79 let l:ind -= shiftwidth()
80 endif
81 elseif l:thisl =~? '^\s*\${\%(EndSelect\|EndSwitch\)\>}\?'
82 " this line closed a block
83 if l:prevl =~? '^\s*\${\%(Select\|Switch\)}'
84 let l:ind -= shiftwidth()
85 else
86 let l:ind -= shiftwidth() * 2
87 endif
88 endif
89
90 return l:ind
91endfunction
92
93" vim: ts=8 sw=2 sts=2