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
5 " Small update 2010 Jul 28 by Maxim Kim
7 if exists("b:did_indent")
13 setlocal indentexpr=VbGetIndent(v:lnum)
15 setlocal indentkeys+==~else,=~elseif,=~end,=~wend,=~case,=~next,=~select,=~loop,<:>
17 let b:undo_indent = "set ai< indentexpr< indentkeys<"
19 " Only define the function once.
20 if exists("*VbGetIndent")
24 fun! VbGetIndent(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 if this_line =~? LABELS_OR_PREPROC
32 " Find a non-blank line above the current line.
33 " Skip over labels and preprocessor directives.
36 let lnum = prevnonblank(lnum - 1)
37 let previous_line = getline(lnum)
38 if previous_line !~? LABELS_OR_PREPROC
43 " Hit the start of the file, use zero indent.
48 let ind = indent(lnum)
51 if previous_line =~? '^\s*\<\(begin\|\%(\%(private\|public\|friend\)\s\+\)\=\%(function\|sub\|property\)\|select\|case\|default\|if\|else\|elseif\|do\|for\|while\|enum\|with\)\>'
56 if this_line =~? '^\s*\<end\>\s\+\<select\>'
57 if previous_line !~? '^\s*\<select\>'
58 let ind = ind - 2 * &sw
60 " this case is for an empty 'select' -- 'end select'
61 " (w/o any case statements) like:
63 " select case readwrite
67 elseif this_line =~? '^\s*\<\(end\|else\|elseif\|until\|loop\|next\|wend\)\>'
69 elseif this_line =~? '^\s*\<\(case\|default\)\>'
70 if previous_line !~? '^\s*\<select\>'