annotate runtime/indent/vb.vim @ 32011:b4d89bd4b517 v9.0.1337

patch 9.0.1337: yuck files are not recognized Commit: https://github.com/vim/vim/commit/cfce5cf542db20c7beba5b4211c0ae3305a64a43 Author: Amaan Qureshi <amaanq12@gmail.com> Date: Tue Feb 21 15:18:50 2023 +0000 patch 9.0.1337: yuck files are not recognized Problem: Yuck files are not recognized. Solution: Add a filetype pattern for yuck files. (Amaan Qureshi, closes #12033)
author Bram Moolenaar <Bram@vim.org>
date Tue, 21 Feb 2023 16:30:04 +0100
parents 7d68a90cbf5c
children f8e7e00787b5
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>
31579
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
4 " Maintainer: Michael Soyka (mssr953@gmail.com)
9
4102fb4ea781 updated for version 7.0002
vimboss
parents: 7
diff changeset
5 " Last Change: Fri, 18 Jun 2004 07:22:42 CEST
2421
c0e675a3e363 Minor runtime file updates.
Bram Moolenaar <bram@vim.org>
parents: 233
diff changeset
6 " Small update 2010 Jul 28 by Maxim Kim
31579
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
7 " 2022/12/15: add support for multiline statements.
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
8 " 2022/12/21: move VbGetIndent from global to script-local scope
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
9 " 2022/12/26: recognize "Type" keyword
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 if exists("b:did_indent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 let b:did_indent = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15
233
fca8a9b65afa updated for version 7.0065
vimboss
parents: 9
diff changeset
16 setlocal autoindent
31579
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
17 setlocal indentexpr=s:VbGetIndent(v:lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 setlocal indentkeys&
31579
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
19 setlocal indentkeys+==~else,=~elseif,=~end,=~wend,=~case,=~next,=~select,=~loop
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20
233
fca8a9b65afa updated for version 7.0065
vimboss
parents: 9
diff changeset
21 let b:undo_indent = "set ai< indentexpr< indentkeys<"
fca8a9b65afa updated for version 7.0065
vimboss
parents: 9
diff changeset
22
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 " Only define the function once.
31579
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
24 if exists("*s:VbGetIndent")
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27
31579
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
28 function s:VbGetIndent(lnum)
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
29 let this_lnum = a:lnum
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
30 let this_line = getline(this_lnum)
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
31
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 " labels and preprocessor get zero indent immediately
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 let LABELS_OR_PREPROC = '^\s*\(\<\k\+\>:\s*$\|#.*\)'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 if this_line =~? LABELS_OR_PREPROC
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 endif
31579
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
37
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
38 " Get the current value of "shiftwidth"
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
39 let bShiftwidth = shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 " Find a non-blank line above the current line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 " Skip over labels and preprocessor directives.
31579
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
43 let lnum = this_lnum
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 while lnum > 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 let lnum = prevnonblank(lnum - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 let previous_line = getline(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 if previous_line !~? LABELS_OR_PREPROC
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 break
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 " Hit the start of the file, use zero indent.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 if lnum == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56
31579
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
57 " Variable "previous_line" now contains the text in buffer line "lnum".
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
58
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
59 " Multi-line statements have the underscore character at end-of-line:
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
60 "
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
61 " object.method(arguments, _
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
62 " arguments, _
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
63 " arguments)
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
64 "
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
65 " and require extra logic to determine the correct indentation.
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
66 "
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
67 " Case 1: Line "lnum" is the first line of a multiline statement.
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
68 " Line "lnum" will have a trailing underscore character
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
69 " but the preceding non-blank line does not.
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
70 " Line "this_lnum" will be indented relative to "lnum".
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
71 "
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
72 " Case 2: Line "lnum" is the last line of a multiline statement.
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
73 " Line "lnum" will not have a trailing underscore character
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
74 " but the preceding non-blank line will.
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
75 " Line "this_lnum" will have the same indentation as the starting
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
76 " line of the multiline statement.
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
77 "
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
78 " Case 3: Line "lnum" is neither the first nor last line.
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
79 " Lines "lnum" and "lnum-1" will have a trailing underscore
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
80 " character.
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
81 " Line "this_lnum" will have the same indentation as the preceding
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
82 " line.
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
83 "
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
84 " No matter which case it is, the starting line of the statement must be
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
85 " found. It will be assumed that multiline statements cannot have
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
86 " intermingled comments, statement labels, preprocessor directives or
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
87 " blank lines.
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
88 "
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
89 let lnum_is_continued = (previous_line =~ '_$')
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
90 if lnum > 1
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
91 let before_lnum = prevnonblank(lnum-1)
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
92 let before_previous_line = getline(before_lnum)
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
93 else
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
94 let before_lnum = 0
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
95 let before_previous_line = ""
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
96 endif
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
97
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
98 if before_previous_line !~ '_$'
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
99 " Variable "previous_line" contains the start of a statement.
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
100 "
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
101 let ind = indent(lnum)
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
102 if lnum_is_continued
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
103 let ind += bShiftwidth
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
104 endif
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
105 elseif ! lnum_is_continued
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
106 " Line "lnum" contains the last line of a multiline statement.
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
107 " Need to find where this multiline statement begins
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
108 "
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
109 while before_lnum > 0
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
110 let before_lnum -= 1
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
111 if getline(before_lnum) !~ '_$'
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
112 let before_lnum += 1
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
113 break
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
114 endif
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
115 endwhile
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
116 if before_lnum == 0
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
117 let before_lnum = 1
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
118 endif
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
119 let previous_line = getline(before_lnum)
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
120 let ind = indent(before_lnum)
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
121 else
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
122 " Line "lnum" is not the first or last line of a multiline statement.
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
123 "
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
124 let ind = indent(lnum)
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
125 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 " Add
31579
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
128 if previous_line =~? '^\s*\<\(begin\|\%(\%(private\|public\|friend\)\s\+\)\=\%(function\|sub\|property\|enum\|type\)\|select\|case\|default\|if\|else\|elseif\|do\|for\|while\|with\)\>'
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
129 let ind = ind + bShiftwidth
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 " Subtract
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 if this_line =~? '^\s*\<end\>\s\+\<select\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 if previous_line !~? '^\s*\<select\>'
31579
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
135 let ind = ind - 2 * bShiftwidth
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 " this case is for an empty 'select' -- 'end select'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 " (w/o any case statements) like:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 " select case readwrite
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141 " end select
31579
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
142 let ind = ind - bShiftwidth
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143 endif
2421
c0e675a3e363 Minor runtime file updates.
Bram Moolenaar <bram@vim.org>
parents: 233
diff changeset
144 elseif this_line =~? '^\s*\<\(end\|else\|elseif\|until\|loop\|next\|wend\)\>'
31579
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
145 let ind = ind - bShiftwidth
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 elseif this_line =~? '^\s*\<\(case\|default\)\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147 if previous_line !~? '^\s*\<select\>'
31579
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
148 let ind = ind - bShiftwidth
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152 return ind
31579
7d68a90cbf5c Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
153 endfunction
2421
c0e675a3e363 Minor runtime file updates.
Bram Moolenaar <bram@vim.org>
parents: 233
diff changeset
154
c0e675a3e363 Minor runtime file updates.
Bram Moolenaar <bram@vim.org>
parents: 233
diff changeset
155 " vim:sw=4