annotate runtime/indent/cdl.vim @ 26404:1bbb884c8561 v8.2.3733

patch 8.2.3733: Vim9: using "legacy" before range does not work Commit: https://github.com/vim/vim/commit/b579f6ebbfa826d228abec1e1b24c05894517c27 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Dec 4 11:57:00 2021 +0000 patch 8.2.3733: Vim9: using "legacy" before range does not work Problem: Vim9: using "legacy" before range does not work. Solution: Skip over range before parsing command. (closes https://github.com/vim/vim/issues/9270)
author Bram Moolenaar <Bram@vim.org>
date Sat, 04 Dec 2021 13:00:05 +0100
parents 9c221ad9634a
children 6dd88e45d47d
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 " Description: Comshare Dimension Definition Language (CDL)
25880
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
2 " Maintainer: Raul Segura Acevedo <raulseguraaceved@netscape.net> (Invalid email address)
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
3 " Doug Kearns <dougkearns@gmail.com>
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 " Last Change: Fri Nov 30 13:35:48 2001 CST
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
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 setlocal indentexpr=CdlGetIndent(v:lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 setlocal indentkeys&
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 setlocal indentkeys+==~else,=~endif,=~then,;,),=
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 " Only define the function once.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 if exists("*CdlGetIndent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 "finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19
25773
11b656e74444 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 24278
diff changeset
20 " find out if an "...=..." expression is an assignment (or a conditional)
11b656e74444 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 24278
diff changeset
21 " it scans 'line' first, and then the previous lines
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 fun! CdlAsignment(lnum, line)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 let f = -1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 let lnum = a:lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 let line = a:line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 while lnum > 0 && f == -1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 " line without members [a] of [b]:[c]...
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 let inicio = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 while 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 " keywords that help to decide
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 let inicio = matchend(line, '\c\<\(expr\|\a*if\|and\|or\|not\|else\|then\|memberis\|\k\+of\)\>\|[<>;]', inicio)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 if inicio < 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 break
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 " it's formula if there's a ';', 'elsE', 'theN', 'enDif' or 'expr'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 " conditional if there's a '<', '>', 'elseif', 'if', 'and', 'or', 'not',
25773
11b656e74444 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 24278
diff changeset
37 " 'memberis', 'childrenof' and other \k\+of functions
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 let f = line[inicio-1] =~? '[en;]' || strpart(line, inicio-4, 4) =~? 'ndif\|expr'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 endw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 let lnum = prevnonblank(lnum-1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 let line = substitute(getline(lnum), '\c\(\[[^]]*]\(\s*of\s*\|:\)*\)\+', ' ', 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 endw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 " if we hit the start of the file then f = -1, return 1 (formula)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 return f != 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 endf
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 fun! CdlGetIndent(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 let thisline = getline(a:lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 if match(thisline, '^\s*\(\k\+\|\[[^]]*]\)\s*\(,\|;\s*$\)') >= 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 " it's an attributes line
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 10228
diff changeset
51 return shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 elseif match(thisline, '^\c\s*\([{}]\|\/[*/]\|dimension\|schedule\|group\|hierarchy\|class\)') >= 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 " it's a header or '{' or '}' or a comment
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 let lnum = prevnonblank(a:lnum-1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 " Hit the start of the file, use zero indent.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 if lnum == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 " PREVIOUS LINE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 let ind = indent(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 let line = getline(lnum)
24278
4ab4ef0c48b1 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
66
4ab4ef0c48b1 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
67 " Whether a '=' is a conditional or an assignment. -1 means we don't know
4ab4ef0c48b1 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
68 " yet.
4ab4ef0c48b1 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
69 " One 'closing' element at the beginning of the line has already reduced the
4ab4ef0c48b1 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
70 " indent, but 'else', 'elseif' & 'then' increment it for the next line.
4ab4ef0c48b1 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
71 " '=' at the beginning already has the right indent (increased for
4ab4ef0c48b1 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
72 " asignments).
4ab4ef0c48b1 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
73 let f = -1
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 let inicio = matchend(line, '^\c\s*\(else\a*\|then\|endif\|/[*/]\|[);={]\)')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 if inicio > 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 let c = line[inicio-1]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 " ')' and '=' don't change indent and are useless to set 'f'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 if c == '{'
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 10228
diff changeset
79 return shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 elseif c != ')' && c != '='
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81 let f = 1 " all but 'elseif' are followed by a formula
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 if c ==? 'n' || c ==? 'e' " 'then', 'else'
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 10228
diff changeset
83 let ind = ind + shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 elseif strpart(line, inicio-6, 6) ==? 'elseif' " elseif, set f to conditional
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 10228
diff changeset
85 let ind = ind + shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 let f = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 " remove members [a] of [b]:[c]... (inicio remainds valid)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 let line = substitute(line, '\c\(\[[^]]*]\(\s*of\s*\|:\)*\)\+', ' ', 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 while 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 " search for the next interesting element
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 let inicio=matchend(line, '\c\<if\|endif\|[()=;]', inicio)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 if inicio < 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 break
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100 let c = line[inicio-1]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 " 'expr(...)' containing the formula
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 if strpart(line, inicio-5, 5) ==? 'expr('
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 let ind = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 let f = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105 elseif c == ')' || c== ';' || strpart(line, inicio-5, 5) ==? 'endif'
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 10228
diff changeset
106 let ind = ind - shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 elseif c == '(' || c ==? 'f' " '(' or 'if'
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 10228
diff changeset
108 let ind = ind + shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 else " c == '='
25773
11b656e74444 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 24278
diff changeset
110 " if it is an assignment increase indent
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111 if f == -1 " we don't know yet, find out
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 let f = CdlAsignment(lnum, strpart(line, 0, inicio))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 if f == 1 " formula increase it
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 10228
diff changeset
115 let ind = ind + shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117 end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 endw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 " CURRENT LINE, if it starts with a closing element, decrease indent
25773
11b656e74444 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 24278
diff changeset
121 " or if it starts with '=' (assignment), increase indent
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 if match(thisline, '^\c\s*\(else\|then\|endif\|[);]\)') >= 0
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 10228
diff changeset
123 let ind = ind - shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 elseif match(thisline, '^\s*=') >= 0
25773
11b656e74444 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 24278
diff changeset
125 if f == -1 " we don't know yet if is an assignment, find out
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 let f = CdlAsignment(lnum, "")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 if f == 1 " formula increase it
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 10228
diff changeset
129 let ind = ind + shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 return ind
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 endfun