7
|
1 " Vim indent file
|
|
2 " Language: VisualBasic (ft=vb) / Basic (ft=basic) / SaxBasic (ft=vb)
|
|
3 " Author: Johannes Zellner <johannes@zellner.org>
|
9
|
4 " Last Change: Fri, 18 Jun 2004 07:22:42 CEST
|
7
|
5
|
|
6 if exists("b:did_indent")
|
|
7 finish
|
|
8 endif
|
|
9 let b:did_indent = 1
|
|
10
|
233
|
11 setlocal autoindent
|
7
|
12 setlocal indentexpr=VbGetIndent(v:lnum)
|
|
13 setlocal indentkeys&
|
9
|
14 setlocal indentkeys+==~else,=~elseif,=~end,=~wend,=~case,=~next,=~select,=~loop,<:>
|
7
|
15
|
233
|
16 let b:undo_indent = "set ai< indentexpr< indentkeys<"
|
|
17
|
7
|
18 " Only define the function once.
|
|
19 if exists("*VbGetIndent")
|
|
20 finish
|
|
21 endif
|
|
22
|
|
23 fun! VbGetIndent(lnum)
|
|
24 " labels and preprocessor get zero indent immediately
|
|
25 let this_line = getline(a:lnum)
|
|
26 let LABELS_OR_PREPROC = '^\s*\(\<\k\+\>:\s*$\|#.*\)'
|
|
27 if this_line =~? LABELS_OR_PREPROC
|
|
28 return 0
|
|
29 endif
|
|
30
|
|
31 " Find a non-blank line above the current line.
|
|
32 " Skip over labels and preprocessor directives.
|
|
33 let lnum = a:lnum
|
|
34 while lnum > 0
|
|
35 let lnum = prevnonblank(lnum - 1)
|
|
36 let previous_line = getline(lnum)
|
|
37 if previous_line !~? LABELS_OR_PREPROC
|
|
38 break
|
|
39 endif
|
|
40 endwhile
|
|
41
|
|
42 " Hit the start of the file, use zero indent.
|
|
43 if lnum == 0
|
|
44 return 0
|
|
45 endif
|
|
46
|
|
47 let ind = indent(lnum)
|
|
48
|
|
49 " Add
|
|
50 if previous_line =~? '^\s*\<\(begin\|\%(\%(private\|public\|friend\)\s\+\)\=\%(function\|sub\|property\)\|select\|case\|default\|if\>.\{-}\<then\>\s*$\|else\|elseif\|do\|for\|while\|enum\|with\)\>'
|
|
51 let ind = ind + &sw
|
|
52 endif
|
|
53
|
|
54 " Subtract
|
|
55 if this_line =~? '^\s*\<end\>\s\+\<select\>'
|
|
56 if previous_line !~? '^\s*\<select\>'
|
|
57 let ind = ind - 2 * &sw
|
|
58 else
|
|
59 " this case is for an empty 'select' -- 'end select'
|
|
60 " (w/o any case statements) like:
|
|
61 "
|
|
62 " select case readwrite
|
|
63 " end select
|
|
64 let ind = ind - &sw
|
|
65 endif
|
|
66 elseif this_line =~? '^\s*\<\(end\|else\|until\|loop\|next\|wend\)\>'
|
|
67 let ind = ind - &sw
|
|
68 elseif this_line =~? '^\s*\<\(case\|default\)\>'
|
|
69 if previous_line !~? '^\s*\<select\>'
|
|
70 let ind = ind - &sw
|
|
71 endif
|
|
72 endif
|
|
73
|
|
74 return ind
|
|
75 endfun
|