blob: 531244b81908286dcebfb3df1766d3b0713afe64 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Description: InstallShield indenter
2" Author: Johannes Zellner <johannes@zellner.org>
3" Last Change: Tue, 27 Apr 2004 14:54:59 CEST
4
5" Only load this indent file when no other was loaded.
6if exists("b:did_indent")
7 finish
8endif
9let b:did_indent = 1
10
Bram Moolenaarb982ca52005-03-28 21:02:15 +000011setlocal autoindent
Bram Moolenaar071d4272004-06-13 20:20:40 +000012setlocal indentexpr=GetIshdIndent(v:lnum)
13setlocal indentkeys&
14setlocal indentkeys+==else,=elseif,=endif,=end,=begin,<:>
15" setlocal indentkeys-=0#
16
Bram Moolenaarb982ca52005-03-28 21:02:15 +000017let b:undo_indent = "setl ai< indentexpr< indentkeys<"
18
Bram Moolenaar071d4272004-06-13 20:20:40 +000019" Only define the function once.
20if exists("*GetIshdIndent")
21 finish
22endif
23
24fun! GetIshdIndent(lnum)
25 " labels and preprocessor get zero indent immediately
26 let this_line = getline(a:lnum)
27 let LABELS_OR_PREPROC = '^\s*\(\<\k\+\>:\s*$\|#.*\)'
28 let LABELS_OR_PREPROC_EXCEPT = '^\s*\<default\+\>:'
29 if this_line =~ LABELS_OR_PREPROC && this_line !~ LABELS_OR_PREPROC_EXCEPT
30 return 0
31 endif
32
33 " Find a non-blank line above the current line.
34 " Skip over labels and preprocessor directives.
35 let lnum = a:lnum
36 while lnum > 0
37 let lnum = prevnonblank(lnum - 1)
38 let previous_line = getline(lnum)
39 if previous_line !~ LABELS_OR_PREPROC || previous_line =~ LABELS_OR_PREPROC_EXCEPT
40 break
41 endif
42 endwhile
43
44 " Hit the start of the file, use zero indent.
45 if lnum == 0
46 return 0
47 endif
48
49 let ind = indent(lnum)
50
51 " Add
52 if previous_line =~ '^\s*\<\(function\|begin\|switch\|case\|default\|if.\{-}then\|else\|elseif\|while\|repeat\)\>'
Bram Moolenaar3ec574f2017-06-13 18:12:01 +020053 let ind = ind + shiftwidth()
Bram Moolenaar071d4272004-06-13 20:20:40 +000054 endif
55
56 " Subtract
57 if this_line =~ '^\s*\<endswitch\>'
Bram Moolenaar3ec574f2017-06-13 18:12:01 +020058 let ind = ind - 2 * shiftwidth()
Bram Moolenaar071d4272004-06-13 20:20:40 +000059 elseif this_line =~ '^\s*\<\(begin\|end\|endif\|endwhile\|else\|elseif\|until\)\>'
Bram Moolenaar3ec574f2017-06-13 18:12:01 +020060 let ind = ind - shiftwidth()
Bram Moolenaar071d4272004-06-13 20:20:40 +000061 elseif this_line =~ '^\s*\<\(case\|default\)\>'
62 if previous_line !~ '^\s*\<switch\>'
Bram Moolenaar3ec574f2017-06-13 18:12:01 +020063 let ind = ind - shiftwidth()
Bram Moolenaar071d4272004-06-13 20:20:40 +000064 endif
65 endif
66
67 return ind
68endfun