annotate runtime/indent/vb.vim @ 1420:b63fe7400eb3 v7.1.135

updated for version 7.1-135
author vimboss
date Wed, 03 Oct 2007 12:31:33 +0000
parents fca8a9b65afa
children c0e675a3e363
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 " Vim indent file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 " Language: VisualBasic (ft=vb) / Basic (ft=basic) / SaxBasic (ft=vb)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 " Author: Johannes Zellner <johannes@zellner.org>
9
4102fb4ea781 updated for version 7.0002
vimboss
parents: 7
diff changeset
4 " Last Change: Fri, 18 Jun 2004 07:22:42 CEST
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 if exists("b:did_indent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 let b:did_indent = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10
233
fca8a9b65afa updated for version 7.0065
vimboss
parents: 9
diff changeset
11 setlocal autoindent
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 setlocal indentexpr=VbGetIndent(v:lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 setlocal indentkeys&
9
4102fb4ea781 updated for version 7.0002
vimboss
parents: 7
diff changeset
14 setlocal indentkeys+==~else,=~elseif,=~end,=~wend,=~case,=~next,=~select,=~loop,<:>
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15
233
fca8a9b65afa updated for version 7.0065
vimboss
parents: 9
diff changeset
16 let b:undo_indent = "set ai< indentexpr< indentkeys<"
fca8a9b65afa updated for version 7.0065
vimboss
parents: 9
diff changeset
17
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 " Only define the function once.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 if exists("*VbGetIndent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 fun! VbGetIndent(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 " labels and preprocessor get zero indent immediately
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 let this_line = getline(a:lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 let LABELS_OR_PREPROC = '^\s*\(\<\k\+\>:\s*$\|#.*\)'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 if this_line =~? LABELS_OR_PREPROC
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 " Find a non-blank line above the current line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 " Skip over labels and preprocessor directives.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 let lnum = a:lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 while lnum > 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 let lnum = prevnonblank(lnum - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 let previous_line = getline(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 if previous_line !~? LABELS_OR_PREPROC
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 break
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 " Hit the start of the file, use zero indent.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 if lnum == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 let ind = indent(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 " Add
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
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\)\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 let ind = ind + &sw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 " Subtract
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 if this_line =~? '^\s*\<end\>\s\+\<select\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 if previous_line !~? '^\s*\<select\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 let ind = ind - 2 * &sw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 " this case is for an empty 'select' -- 'end select'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 " (w/o any case statements) like:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 " select case readwrite
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 " end select
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 let ind = ind - &sw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 elseif this_line =~? '^\s*\<\(end\|else\|until\|loop\|next\|wend\)\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 let ind = ind - &sw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 elseif this_line =~? '^\s*\<\(case\|default\)\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 if previous_line !~? '^\s*\<select\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 let ind = ind - &sw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 return ind
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 endfun