vim

Fork of vim, an acceptable text editor
git clone git://git.laack.co/vim.git
Log | Files | Refs | README | LICENSE

nsis.vim (3306B)


      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 
      9 if exists("b:did_indent")
     10   finish
     11 endif
     12 let b:did_indent = 1
     13 
     14 setlocal nosmartindent
     15 setlocal noautoindent
     16 setlocal indentexpr=GetNsisIndent(v:lnum)
     17 setlocal indentkeys=!^F,o,O
     18 setlocal 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 
     20 let b:undo_indent = "setl ai< inde< indk< si<"
     21 
     22 if exists("*GetNsisIndent")
     23   finish
     24 endif
     25 
     26 function! 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
     91 endfunction
     92 
     93 " vim: ts=8 sw=2 sts=2