annotate runtime/indent/rapid.vim @ 34696:b52f4f56979f

Added tag v9.1.0228 for changeset 5569220366ee7c21b56ee688a098ff5c0b842c8e
author Christian Brabandt <cb@256bit.org>
date Fri, 29 Mar 2024 10:30:05 +0100
parents d6dde6229b36
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32721
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " ABB Rapid Command indent file for Vim
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2 " Language: ABB Rapid Command
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 " Maintainer: Patrick Meiser-Knosowski <knosowski@graeffrobotics.de>
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 " Version: 2.2.7
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 " Last Change: 12. May 2023
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 " Credits: Based on indent/vim.vim
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 "
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 " Suggestions of improvement are very welcome. Please email me!
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 "
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 " Known bugs: ../doc/rapid.txt
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 "
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 " TODO
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 " * indent wrapped lines which do not end with an ; or special key word,
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 " maybe this is a better idea, but then () and [] has to be changed as
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 " well
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 "
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 if exists("g:rapidNoSpaceIndent")
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 if !exists("g:rapidSpaceIndent")
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 let g:rapidSpaceIndent = !g:rapidNoSpaceIndent
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 endif
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 unlet g:rapidNoSpaceIndent
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 endif
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 " Only load this indent file when no other was loaded.
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 if exists("b:did_indent") || get(g:,'rapidNoIndent',0)
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27 finish
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28 endif
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 let b:did_indent = 1
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 setlocal nolisp
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 setlocal nosmartindent
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33 setlocal autoindent
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 setlocal indentexpr=GetRapidIndent()
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35 if get(g:,'rapidNewStyleIndent',0)
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36 setlocal indentkeys=!^F,o,O,0=~endmodule,0=~error,0=~undo,0=~backward,0=~endproc,0=~endrecord,0=~endtrap,0=~endfunc,0=~else,0=~endif,0=~endtest,0=~endfor,0=~endwhile,:,<[>,<]>,<(>,<)>
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37 else
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38 setlocal indentkeys=!^F,o,O,0=~endmodule,0=~error,0=~undo,0=~backward,0=~endproc,0=~endrecord,0=~endtrap,0=~endfunc,0=~else,0=~endif,0=~endtest,0=~endfor,0=~endwhile,:
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39 endif
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40 let b:undo_indent="setlocal lisp< si< ai< inde< indk<"
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42 if get(g:,'rapidSpaceIndent',1)
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43 " Use spaces for indention, 2 is enough.
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 " More or even tabs wastes space on the teach pendant.
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 setlocal softtabstop=2
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46 setlocal shiftwidth=2
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47 setlocal expandtab
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48 setlocal shiftround
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49 let b:undo_indent = b:undo_indent." sts< sw< et< sr<"
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 endif
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
52 " Only define the function once.
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
53 if exists("*GetRapidIndent")
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54 finish
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55 endif
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
56
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
57 let s:keepcpo= &cpo
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
58 set cpo&vim
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
59
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
60 function GetRapidIndent()
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
61 let ignorecase_save = &ignorecase
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
62 try
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
63 let &ignorecase = 0
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
64 return s:GetRapidIndentIntern()
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
65 finally
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
66 let &ignorecase = ignorecase_save
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
67 endtry
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
68 endfunction
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
69
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
70 function s:GetRapidIndentIntern() abort
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
71
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
72 let l:currentLineNum = v:lnum
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
73 let l:currentLine = getline(l:currentLineNum)
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
74
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
75 if l:currentLine =~ '^!' && !get(g:,'rapidCommentIndent',0)
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
76 " If current line is ! line comment, do not change indent
33577
d6dde6229b36 runtime: Fix more typos (#13354)
Christian Brabandt <cb@256bit.org>
parents: 32974
diff changeset
77 " This may be useful if code is commented out at the first column.
32721
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
78 return 0
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
79 endif
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
80
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
81 " Find a non-blank line above the current line.
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
82 let l:preNoneBlankLineNum = s:RapidPreNoneBlank(v:lnum - 1)
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
83 if l:preNoneBlankLineNum == 0
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
84 " At the start of the file use zero indent.
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
85 return 0
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
86 endif
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
87
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
88 let l:preNoneBlankLine = getline(l:preNoneBlankLineNum)
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
89 let l:ind = indent(l:preNoneBlankLineNum)
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
90
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
91 " Define add a 'shiftwidth' pattern
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
92 let l:addShiftwidthPattern = '\c\v^\s*('
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
93 let l:addShiftwidthPattern .= '((local|task)\s+)?(module|record|proc|func|trap)\s+\k'
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
94 let l:addShiftwidthPattern .= '|(backward|error|undo)>'
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
95 let l:addShiftwidthPattern .= ')'
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
96 "
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
97 " Define Subtract 'shiftwidth' pattern
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
98 let l:subtractShiftwidthPattern = '\c\v^\s*('
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
99 let l:subtractShiftwidthPattern .= 'end(module|record|proc|func|trap)>'
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
100 let l:subtractShiftwidthPattern .= '|(backward|error|undo)>'
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
101 let l:subtractShiftwidthPattern .= ')'
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
102
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
103 " Add shiftwidth
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
104 if l:preNoneBlankLine =~ l:addShiftwidthPattern
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
105 \|| s:RapidLenTilStr(l:preNoneBlankLineNum, "then", 0)>=0
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
106 \|| s:RapidLenTilStr(l:preNoneBlankLineNum, "else", 0)>=0
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
107 \|| s:RapidLenTilStr(l:preNoneBlankLineNum, "do", 0)>=0
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
108 \|| s:RapidLenTilStr(l:preNoneBlankLineNum, "case", 0)>=0
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
109 \|| s:RapidLenTilStr(l:preNoneBlankLineNum, "default", 0)>=0
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
110 let l:ind += &sw
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
111 endif
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
112
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
113 " Subtract shiftwidth
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
114 if l:currentLine =~ l:subtractShiftwidthPattern
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
115 \|| s:RapidLenTilStr(l:currentLineNum, "endif", 0)>=0
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
116 \|| s:RapidLenTilStr(l:currentLineNum, "endfor", 0)>=0
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
117 \|| s:RapidLenTilStr(l:currentLineNum, "endwhile", 0)>=0
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
118 \|| s:RapidLenTilStr(l:currentLineNum, "endtest", 0)>=0
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
119 \|| s:RapidLenTilStr(l:currentLineNum, "else", 0)>=0
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
120 \|| s:RapidLenTilStr(l:currentLineNum, "elseif", 0)>=0
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
121 \|| s:RapidLenTilStr(l:currentLineNum, "case", 0)>=0
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
122 \|| s:RapidLenTilStr(l:currentLineNum, "default", 0)>=0
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
123 let l:ind = l:ind - &sw
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
124 endif
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
125
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
126 " First case (or default) after a test gets the indent of the test.
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
127 if (s:RapidLenTilStr(l:currentLineNum, "case", 0)>=0 || s:RapidLenTilStr(l:currentLineNum, "default", 0)>=0) && s:RapidLenTilStr(l:preNoneBlankLineNum, "test", 0)>=0
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
128 let l:ind += &sw
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
129 endif
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
130
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
131 " continued lines with () or []
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
132 let l:OpenSum = s:RapidLoneParen(l:preNoneBlankLineNum,"(") + s:RapidLoneParen(l:preNoneBlankLineNum,"[")
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
133 if get(g:,'rapidNewStyleIndent',0)
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
134 let l:CloseSum = s:RapidLoneParen(l:preNoneBlankLineNum,")") + s:RapidLoneParen(l:currentLineNum,"]")
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
135 else
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
136 let l:CloseSum = s:RapidLoneParen(l:preNoneBlankLineNum,")") + s:RapidLoneParen(l:preNoneBlankLineNum,"]")
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
137 endif
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
138 if l:OpenSum > l:CloseSum
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
139 let l:ind += (l:OpenSum * 4 * &sw)
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
140 elseif l:OpenSum < l:CloseSum
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
141 let l:ind -= (l:CloseSum * 4 * &sw)
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
142 endif
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
143
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
144 return l:ind
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
145 endfunction
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
146
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
147 " Returns the length of the line until a:str occur outside a string or
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
148 " comment. Search starts at string index a:startIdx.
32974
d46f974fd69e runtime: Fix typos in various files
Christian Brabandt <cb@256bit.org>
parents: 32721
diff changeset
149 " If a:str is a word also add word boundaries and case insensitivity.
32721
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
150 " Note: rapidTodoComment and rapidDebugComment are not taken into account.
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
151 function s:RapidLenTilStr(lnum, str, startIdx) abort
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
152
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
153 let l:line = getline(a:lnum)
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
154 let l:len = strlen(l:line)
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
155 let l:idx = a:startIdx
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
156 let l:str = a:str
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
157 if l:str =~ '^\k\+$'
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
158 let l:str = '\c\<' . l:str . '\>'
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
159 endif
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
160
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
161 while l:len > l:idx
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
162 let l:idx = match(l:line, l:str, l:idx)
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
163 if l:idx < 0
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
164 " a:str not found
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
165 return -1
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
166 endif
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
167 let l:synName = synIDattr(synID(a:lnum,l:idx+1,0),"name")
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
168 if l:synName != "rapidString"
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
169 \&& l:synName != "rapidConcealableString"
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
170 \&& (l:synName != "rapidComment" || l:str =~ '^!')
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
171 " a:str found outside string or line comment
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
172 return l:idx
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
173 endif
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
174 " a:str is part of string or line comment
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
175 let l:idx += 1 " continue search for a:str
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
176 endwhile
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
177
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
178 " a:str not found or l:len <= a:startIdx
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
179 return -1
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
180 endfunction
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
181
32974
d46f974fd69e runtime: Fix typos in various files
Christian Brabandt <cb@256bit.org>
parents: 32721
diff changeset
182 " a:lchar should be one of (, ), [, ], { or }
d46f974fd69e runtime: Fix typos in various files
Christian Brabandt <cb@256bit.org>
parents: 32721
diff changeset
183 " returns the number of opening/closing parentheses which have no
32721
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
184 " closing/opening match in getline(a:lnum)
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
185 function s:RapidLoneParen(lnum,lchar) abort
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
186 if a:lchar == "(" || a:lchar == ")"
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
187 let l:opnParChar = "("
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
188 let l:clsParChar = ")"
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
189 elseif a:lchar == "[" || a:lchar == "]"
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
190 let l:opnParChar = "["
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
191 let l:clsParChar = "]"
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
192 elseif a:lchar == "{" || a:lchar == "}"
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
193 let l:opnParChar = "{"
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
194 let l:clsParChar = "}"
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
195 else
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
196 return 0
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
197 endif
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
198
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
199 let l:line = getline(a:lnum)
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
200
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
201 " look for the first ! which is not part of a string
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
202 let l:len = s:RapidLenTilStr(a:lnum,"!",0)
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
203 if l:len == 0
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
204 return 0 " first char is !; ignored
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
205 endif
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
206
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
207 let l:opnParen = 0
32974
d46f974fd69e runtime: Fix typos in various files
Christian Brabandt <cb@256bit.org>
parents: 32721
diff changeset
208 " count opening brackets
32721
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
209 let l:i = 0
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
210 while l:i >= 0
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
211 let l:i = s:RapidLenTilStr(a:lnum, l:opnParChar, l:i)
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
212 if l:i >= 0
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
213 let l:opnParen += 1
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
214 let l:i += 1
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
215 endif
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
216 endwhile
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
217
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
218 let l:clsParen = 0
32974
d46f974fd69e runtime: Fix typos in various files
Christian Brabandt <cb@256bit.org>
parents: 32721
diff changeset
219 " count closing brackets
32721
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
220 let l:i = 0
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
221 while l:i >= 0
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
222 let l:i = s:RapidLenTilStr(a:lnum, l:clsParChar, l:i)
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
223 if l:i >= 0
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
224 let l:clsParen += 1
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
225 let l:i += 1
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
226 endif
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
227 endwhile
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
228
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
229 if (a:lchar == "(" || a:lchar == "[" || a:lchar == "{") && l:opnParen>l:clsParen
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
230 return (l:opnParen-l:clsParen)
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
231 elseif (a:lchar == ")" || a:lchar == "]" || a:lchar == "}") && l:clsParen>l:opnParen
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
232 return (l:clsParen-l:opnParen)
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
233 endif
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
234
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
235 return 0
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
236 endfunction
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
237
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
238 " This function works almost like prevnonblank() but handles %%%-headers and
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
239 " comments like blank lines
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
240 function s:RapidPreNoneBlank(lnum) abort
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
241
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
242 let nPreNoneBlank = prevnonblank(a:lnum)
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
243
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
244 while nPreNoneBlank>0 && getline(nPreNoneBlank) =~ '\v\c^\s*(\%\%\%|!)'
32974
d46f974fd69e runtime: Fix typos in various files
Christian Brabandt <cb@256bit.org>
parents: 32721
diff changeset
245 " Previous none blank line irrelevant. Look further aback.
32721
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
246 let nPreNoneBlank = prevnonblank(nPreNoneBlank - 1)
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
247 endwhile
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
248
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
249 return nPreNoneBlank
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
250 endfunction
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
251
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
252 let &cpo = s:keepcpo
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
253 unlet s:keepcpo
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
254
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
255 " vim:sw=2 sts=2 et