blob: 5f386f79109b211fe3f2154e8246a612e6dda42a [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 Moolenaar59c03952010-07-28 12:52:27 +02005" Small update 2010 Jul 28 by Maxim Kim
Bram Moolenaar071d4272004-06-13 20:20:40 +00006
7if exists("b:did_indent")
8 finish
9endif
10let b:did_indent = 1
11
Bram Moolenaar582fd852005-03-28 20:58:01 +000012setlocal autoindent
Bram Moolenaar071d4272004-06-13 20:20:40 +000013setlocal indentexpr=VbGetIndent(v:lnum)
14setlocal indentkeys&
Bram Moolenaar69a7cb42004-06-20 12:51:53 +000015setlocal indentkeys+==~else,=~elseif,=~end,=~wend,=~case,=~next,=~select,=~loop,<:>
Bram Moolenaar071d4272004-06-13 20:20:40 +000016
Bram Moolenaar582fd852005-03-28 20:58:01 +000017let b:undo_indent = "set ai< indentexpr< indentkeys<"
18
Bram Moolenaar071d4272004-06-13 20:20:40 +000019" Only define the function once.
20if exists("*VbGetIndent")
21 finish
22endif
23
24fun! 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
29 return 0
30 endif
31
32 " Find a non-blank line above the current line.
33 " Skip over labels and preprocessor directives.
34 let lnum = a:lnum
35 while lnum > 0
36 let lnum = prevnonblank(lnum - 1)
37 let previous_line = getline(lnum)
38 if previous_line !~? LABELS_OR_PREPROC
39 break
40 endif
41 endwhile
42
43 " Hit the start of the file, use zero indent.
44 if lnum == 0
45 return 0
46 endif
47
48 let ind = indent(lnum)
49
50 " Add
51 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\)\>'
52 let ind = ind + &sw
53 endif
54
55 " Subtract
56 if this_line =~? '^\s*\<end\>\s\+\<select\>'
57 if previous_line !~? '^\s*\<select\>'
58 let ind = ind - 2 * &sw
59 else
60 " this case is for an empty 'select' -- 'end select'
61 " (w/o any case statements) like:
62 "
63 " select case readwrite
64 " end select
65 let ind = ind - &sw
66 endif
Bram Moolenaar59c03952010-07-28 12:52:27 +020067 elseif this_line =~? '^\s*\<\(end\|else\|elseif\|until\|loop\|next\|wend\)\>'
Bram Moolenaar071d4272004-06-13 20:20:40 +000068 let ind = ind - &sw
69 elseif this_line =~? '^\s*\<\(case\|default\)\>'
70 if previous_line !~? '^\s*\<select\>'
71 let ind = ind - &sw
72 endif
73 endif
74
75 return ind
76endfun
Bram Moolenaar59c03952010-07-28 12:52:27 +020077
78" vim:sw=4