annotate runtime/indent/cdl.vim @ 30359:6391b3ca26b7 v9.0.0515

patch 9.0.0515: virtual text highlight starts too early when 'number' is set Commit: https://github.com/vim/vim/commit/2fdc9b541918237168ca05ac09eb4bb245e5c6c5 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Sep 20 15:59:22 2022 +0100 patch 9.0.0515: virtual text highlight starts too early when 'number' is set Problem: Virtual text highlight starts too early when 'number' is set. Solution: Set column offset when wrapping. (issue https://github.com/vim/vim/issues/11138)
author Bram Moolenaar <Bram@vim.org>
date Tue, 20 Sep 2022 17:00:05 +0200
parents 6dd88e45d47d
children d6dde6229b36
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>
28379
6dd88e45d47d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25880
diff changeset
4 " Last Change: 2022 Apr 06
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 if exists("b:did_indent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 "finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 let b:did_indent = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10
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
28379
6dd88e45d47d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25880
diff changeset
15 let b:undo_indent = "setl inde< indk<"
6dd88e45d47d Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25880
diff changeset
16
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 " Only define the function once.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 if exists("*CdlGetIndent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 "finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21
25773
11b656e74444 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 24278
diff changeset
22 " find out if an "...=..." expression is an assignment (or a conditional)
11b656e74444 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 24278
diff changeset
23 " it scans 'line' first, and then the previous lines
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 fun! CdlAsignment(lnum, line)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 let f = -1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 let lnum = a:lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 let line = a:line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 while lnum > 0 && f == -1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 " line without members [a] of [b]:[c]...
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 let inicio = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 while 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 " keywords that help to decide
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 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
34 if inicio < 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 break
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 " it's formula if there's a ';', 'elsE', 'theN', 'enDif' or 'expr'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 " conditional if there's a '<', '>', 'elseif', 'if', 'and', 'or', 'not',
25773
11b656e74444 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 24278
diff changeset
39 " 'memberis', 'childrenof' and other \k\+of functions
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 let f = line[inicio-1] =~? '[en;]' || strpart(line, inicio-4, 4) =~? 'ndif\|expr'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 endw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 let lnum = prevnonblank(lnum-1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 let line = substitute(getline(lnum), '\c\(\[[^]]*]\(\s*of\s*\|:\)*\)\+', ' ', 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 endw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 " if we hit the start of the file then f = -1, return 1 (formula)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 return f != 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 endf
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 fun! CdlGetIndent(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 let thisline = getline(a:lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 if match(thisline, '^\s*\(\k\+\|\[[^]]*]\)\s*\(,\|;\s*$\)') >= 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 " it's an attributes line
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 10228
diff changeset
53 return shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 elseif match(thisline, '^\c\s*\([{}]\|\/[*/]\|dimension\|schedule\|group\|hierarchy\|class\)') >= 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 " it's a header or '{' or '}' or a comment
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 let lnum = prevnonblank(a:lnum-1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 " Hit the start of the file, use zero indent.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 if lnum == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 " PREVIOUS LINE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 let ind = indent(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 let line = getline(lnum)
24278
4ab4ef0c48b1 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
68
4ab4ef0c48b1 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
69 " 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
70 " yet.
4ab4ef0c48b1 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
71 " 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
72 " indent, but 'else', 'elseif' & 'then' increment it for the next line.
4ab4ef0c48b1 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
73 " '=' at the beginning already has the right indent (increased for
4ab4ef0c48b1 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
74 " asignments).
4ab4ef0c48b1 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
75 let f = -1
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 let inicio = matchend(line, '^\c\s*\(else\a*\|then\|endif\|/[*/]\|[);={]\)')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 if inicio > 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 let c = line[inicio-1]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 " ')' and '=' don't change indent and are useless to set 'f'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 if c == '{'
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 10228
diff changeset
81 return shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 elseif c != ')' && c != '='
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 let f = 1 " all but 'elseif' are followed by a formula
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 if c ==? 'n' || c ==? 'e' " 'then', 'else'
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 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
87 let ind = ind + shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 let f = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 " remove members [a] of [b]:[c]... (inicio remainds valid)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 let line = substitute(line, '\c\(\[[^]]*]\(\s*of\s*\|:\)*\)\+', ' ', 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 while 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 " search for the next interesting element
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 let inicio=matchend(line, '\c\<if\|endif\|[()=;]', inicio)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 if inicio < 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 break
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100 end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 let c = line[inicio-1]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 " 'expr(...)' containing the formula
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 if strpart(line, inicio-5, 5) ==? 'expr('
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105 let ind = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 let f = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 elseif c == ')' || c== ';' || strpart(line, inicio-5, 5) ==? 'endif'
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 elseif c == '(' || c ==? 'f' " '(' or 'if'
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 10228
diff changeset
110 let ind = ind + shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111 else " c == '='
25773
11b656e74444 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 24278
diff changeset
112 " if it is an assignment increase indent
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 if f == -1 " we don't know yet, find out
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 let f = CdlAsignment(lnum, strpart(line, 0, inicio))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 if f == 1 " formula increase it
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 10228
diff changeset
117 let ind = ind + shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119 end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 endw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 " 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
123 " or if it starts with '=' (assignment), increase indent
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 if match(thisline, '^\c\s*\(else\|then\|endif\|[);]\)') >= 0
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 10228
diff changeset
125 let ind = ind - shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 elseif match(thisline, '^\s*=') >= 0
25773
11b656e74444 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 24278
diff changeset
127 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
128 let f = CdlAsignment(lnum, "")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 if f == 1 " formula increase it
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 10228
diff changeset
131 let ind = ind + shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 return ind
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136 endfun