blob: 85021bd7d9942ad24b2a51a638aa330ae74429a1 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim indent file
2" Language: VisualBasic (ft=vb) / Basic (ft=basic) / SaxBasic (ft=vb)
3" Author: Johannes Zellner <johannes@zellner.org>
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00004" Last Change: Fri, 18 Jun 2004 07:22:42 CEST
Bram Moolenaar071d4272004-06-13 20:20:40 +00005
6if exists("b:did_indent")
7 finish
8endif
9let b:did_indent = 1
10
Bram Moolenaar582fd852005-03-28 20:58:01 +000011setlocal autoindent
Bram Moolenaar071d4272004-06-13 20:20:40 +000012setlocal indentexpr=VbGetIndent(v:lnum)
13setlocal indentkeys&
Bram Moolenaar69a7cb42004-06-20 12:51:53 +000014setlocal indentkeys+==~else,=~elseif,=~end,=~wend,=~case,=~next,=~select,=~loop,<:>
Bram Moolenaar071d4272004-06-13 20:20:40 +000015
Bram Moolenaar582fd852005-03-28 20:58:01 +000016let b:undo_indent = "set ai< indentexpr< indentkeys<"
17
Bram Moolenaar071d4272004-06-13 20:20:40 +000018" Only define the function once.
19if exists("*VbGetIndent")
20 finish
21endif
22
23fun! 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
75endfun