annotate runtime/indent/rapid.vim @ 32721:94f4a488412e v9.0.1683

Updated runtime files Commit: https://github.com/vim/vim/commit/6efb1980336ff324e9c57a4e282530b952fca816 Author: Christian Brabandt <cb@256bit.org> Date: Thu Aug 10 05:44:25 2023 +0200 Updated runtime files This is a collection of various PRs from github that all require a minor patch number: 1) https://github.com/vim/vim/pull/12612 Do not conflate dictionary key with end of block 2) https://github.com/vim/vim/pull/12729: When saving and restoring 'undolevels', the constructs `&undolevels` and `:set undolevels` are problematic. The construct `&undolevels` reads an unpredictable value; it will be the local option value (if one has been set), or the global option value (otherwise), making it unsuitable for saving a value for later restoration. Similarly, if a local option value has been set for 'undolevels', temporarily modifying the option via `:set undolevels` changes the local value as well as the global value, requiring extra work to restore both values. Saving and restoring the option value in one step via the construct `:let &undolevels = &undolevels` appears to make no changes to the 'undolevels' option, but if a local option has been set to a different value than the global option, it has the unintended effect of changing the global 'undolevels' value to the local value. Update the documentation to explain these issues and recommend explicit use of global and local option values when saving and restoring. Update some unit tests to use `g:undolevels`. 3) https://github.com/vim/vim/pull/12702: Problem: Pip requirements files are not recognized. Solution: Add a pattern to match pip requirements files. 4) https://github.com/vim/vim/pull/12688: Add indent file and tests for ABB Rapid 5) https://github.com/vim/vim/pull/12668: Use Lua 5.1 numeric escapes in tests and add to CI Only Lua 5.2+ and LuaJIT understand hexadecimal escapes in strings. Lua 5.1 only supports decimal escapes: > A character in a string can also be specified by its numerical value > using the escape sequence \ddd, where ddd is a sequence of up to three > decimal digits. (Note that if a numerical escape is to be followed by a > digit, it must be expressed using exactly three digits.) Strings in Lua > can contain any 8-bit value, including embedded zeros, which can be > specified as '\0'. To make sure this works with Lua 5.4 and Lua 5.1 change the Vim CI to run with Lua 5.1 as well as Lua 5.4 6) https://github.com/vim/vim/pull/12631: Add hurl filetype detection 7) https://github.com/vim/vim/pull/12573: Problem: Files for haskell persistent library are not recognized Solution: Add pattern persistentmodels for haskell persistent library closes: #12612 closes: #12729 closes: #12702 closes: #12688 closes: #12668 closes: #12631 closes: #12573 Co-authored-by: lacygoill <lacygoill@lacygoill.me> Co-authored-by: Michael Henry <drmikehenry@drmikehenry.com> Co-authored-by: ObserverOfTime <chronobserver@disroot.org> Co-authored-by: KnoP-01 <knosowski@graeffrobotics.de> Co-authored-by: James McCoy <jamessan@jamessan.com> Co-authored-by: Jacob Pfeifer <jacob@pfeifer.dev> Co-authored-by: Borys Lykah <lykahb@fastmail.com>
author Christian Brabandt <cb@256bit.org>
date Thu, 10 Aug 2023 06:30:06 +0200
parents
children d46f974fd69e
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
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
77 " This may be usefull if code is commented out at the first column.
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.
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
149 " If a:str is a word also add word bounderies and case insesitivity.
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
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
182 " a:lchar shoud be one of (, ), [, ], { or }
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
183 " returns the number of opening/closing parenthesise which have no
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
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
208 " count opening brakets
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
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
219 " count closing brakets
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*(\%\%\%|!)'
94f4a488412e Updated runtime files
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
245 " Previouse none blank line irrelevant. Look further aback.
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