Add support for :winpos
[MacVim.git] / runtime / indent / vb.vim
blob85021bd7d9942ad24b2a51a638aa330ae74429a1
1 " Vim indent file
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")
7     finish
8 endif
9 let b:did_indent = 1
11 setlocal autoindent
12 setlocal indentexpr=VbGetIndent(v:lnum)
13 setlocal indentkeys&
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")
20     finish
21 endif
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
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
42     " Hit the start of the file, use zero indent.
43     if lnum == 0
44         return 0
45     endif
47     let ind = indent(lnum)
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
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
74     return ind
75 endfun