annotate runtime/indent/cdl.vim @ 1056:e6d25347de2c v7.0.182

updated for version 7.0-182
author vimboss
date Tue, 09 Jan 2007 19:23:12 +0000
parents 3fc0f57ecb91
children 8a1481e59d64
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)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 " Author: Raul Segura Acevedo <raulseguraaceved@netscape.net>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 " Last Change: Fri Nov 30 13:35:48 2001 CST
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 if exists("b:did_indent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 "finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 let b:did_indent = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 setlocal indentexpr=CdlGetIndent(v:lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 setlocal indentkeys&
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 setlocal indentkeys+==~else,=~endif,=~then,;,),=
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 " Only define the function once.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 if exists("*CdlGetIndent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 "finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 " find out if an "...=..." expresion its an asignment (or a conditional)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 " it scans 'line' first, and then the previos lines
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 fun! CdlAsignment(lnum, line)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 let f = -1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 let lnum = a:lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 let line = a:line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 while lnum > 0 && f == -1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 " line without members [a] of [b]:[c]...
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 let inicio = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 while 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 " keywords that help to decide
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 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
31 if inicio < 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 break
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 " it's formula if there's a ';', 'elsE', 'theN', 'enDif' or 'expr'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 " conditional if there's a '<', '>', 'elseif', 'if', 'and', 'or', 'not',
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 " 'memberis', 'childrenof' and other \k\+of funcions
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 let f = line[inicio-1] =~? '[en;]' || strpart(line, inicio-4, 4) =~? 'ndif\|expr'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 endw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 let lnum = prevnonblank(lnum-1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 let line = substitute(getline(lnum), '\c\(\[[^]]*]\(\s*of\s*\|:\)*\)\+', ' ', 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 endw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 " if we hit the start of the file then f = -1, return 1 (formula)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 return f != 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 endf
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 fun! CdlGetIndent(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 let thisline = getline(a:lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 if match(thisline, '^\s*\(\k\+\|\[[^]]*]\)\s*\(,\|;\s*$\)') >= 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 " it's an attributes line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 return &sw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 elseif match(thisline, '^\c\s*\([{}]\|\/[*/]\|dimension\|schedule\|group\|hierarchy\|class\)') >= 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 " it's a header or '{' or '}' or a comment
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 let lnum = prevnonblank(a:lnum-1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 " Hit the start of the file, use zero indent.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 if lnum == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 " PREVIOUS LINE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 let ind = indent(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 let line = getline(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 let f = -1 " wether a '=' is a conditional or a asignment, -1 means we don't know yet
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 " one 'closing' element at the beginning of the line has already reduced the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 " indent, but 'else', 'elseif' & 'then' increment it for the next line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 " '=' at the beginning has already de right indent (increased for asignments)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 let inicio = matchend(line, '^\c\s*\(else\a*\|then\|endif\|/[*/]\|[);={]\)')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 if inicio > 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 let c = line[inicio-1]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 " ')' and '=' don't change indent and are useless to set 'f'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 if c == '{'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 return &sw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 elseif c != ')' && c != '='
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 let f = 1 " all but 'elseif' are followed by a formula
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 if c ==? 'n' || c ==? 'e' " 'then', 'else'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 let ind = ind + &sw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 elseif strpart(line, inicio-6, 6) ==? 'elseif' " elseif, set f to conditional
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 let ind = ind + &sw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81 let f = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 " remove members [a] of [b]:[c]... (inicio remainds valid)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 let line = substitute(line, '\c\(\[[^]]*]\(\s*of\s*\|:\)*\)\+', ' ', 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 while 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 " search for the next interesting element
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 let inicio=matchend(line, '\c\<if\|endif\|[()=;]', inicio)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 if inicio < 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 break
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 let c = line[inicio-1]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 " 'expr(...)' containing the formula
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 if strpart(line, inicio-5, 5) ==? 'expr('
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 let ind = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 let f = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100 elseif c == ')' || c== ';' || strpart(line, inicio-5, 5) ==? 'endif'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 let ind = ind - &sw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 elseif c == '(' || c ==? 'f' " '(' or 'if'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 let ind = ind + &sw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 else " c == '='
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105 " if it is an asignment increase indent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 if f == -1 " we don't know yet, find out
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 let f = CdlAsignment(lnum, strpart(line, 0, inicio))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108 end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 if f == 1 " formula increase it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 let ind = ind + &sw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111 end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 endw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 " CURRENT LINE, if it starts with a closing element, decrease indent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 " or if it starts with '=' (asignment), increase indent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117 if match(thisline, '^\c\s*\(else\|then\|endif\|[);]\)') >= 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 let ind = ind - &sw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119 elseif match(thisline, '^\s*=') >= 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 if f == -1 " we don't know yet if is an asignment, find out
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121 let f = CdlAsignment(lnum, "")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123 if f == 1 " formula increase it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 let ind = ind + &sw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 return ind
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 endfun