2 " Language: VisualBasic (ft=vb) / Basic (ft=basic) / SaxBasic (ft=vb)
3 " Author: Johannes Zellner <johannes@zellner.org>
4 " Last Change: Fri, 18 Jun 2004 07:22:42 CEST
6 if exists("b:did_indent")
12 setlocal indentexpr=VbGetIndent(v:lnum)
14 setlocal indentkeys+==~else,=~elseif,=~end,=~wend,=~case,=~next,=~select,=~loop,<:>
16 let b:undo_indent = "set ai< indentexpr< indentkeys<"
18 " Only define the function once.
19 if exists("*VbGetIndent")
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
31 " Find a non-blank line above the current line.
32 " Skip over labels and preprocessor directives.
35 let lnum = prevnonblank(lnum - 1)
36 let previous_line = getline(lnum)
37 if previous_line !~? LABELS_OR_PREPROC
42 " Hit the start of the file, use zero indent.
47 let ind = indent(lnum)
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\)\>'
55 if this_line =~? '^\s*\<end\>\s\+\<select\>'
56 if previous_line !~? '^\s*\<select\>'
57 let ind = ind - 2 * &sw
59 " this case is for an empty 'select' -- 'end select'
60 " (w/o any case statements) like:
62 " select case readwrite
66 elseif this_line =~? '^\s*\<\(end\|else\|until\|loop\|next\|wend\)\>'
68 elseif this_line =~? '^\s*\<\(case\|default\)\>'
69 if previous_line !~? '^\s*\<select\>'