0
|
1 " Vim indent file
|
|
2 " Language: occam
|
|
3 " Maintainer: Mario Schweigler <ms44@kent.ac.uk>
|
|
4 " Last Change: 23 April 2003
|
|
5
|
|
6 " Only load this indent file when no other was loaded.
|
|
7 if exists("b:did_indent")
|
|
8 finish
|
|
9 endif
|
|
10 let b:did_indent = 1
|
|
11
|
|
12 "{{{ Settings
|
|
13 " Set the occam indent function
|
|
14 setlocal indentexpr=GetOccamIndent()
|
|
15 " Indent after new line and after initial colon
|
|
16 setlocal indentkeys=o,O,0=:
|
|
17 "}}}
|
|
18
|
|
19 " Only define the function once
|
|
20 if exists("*GetOccamIndent")
|
|
21 finish
|
|
22 endif
|
48
|
23 let s:keepcpo= &cpo
|
|
24 set cpo&vim
|
0
|
25
|
|
26 "{{{ Indent definitions
|
|
27 " Define carriage return indent
|
|
28 let s:FirstLevelIndent = '^\C\s*\(IF\|ALT\|PRI\s\+ALT\|PAR\|SEQ\|PRI\s\+PAR\|WHILE\|VALOF\|CLAIM\|FORKING\)\>\|\(--.*\)\@<!\(\<PROC\>\|??\|\<CASE\>\s*\(--.*\)\=\_$\)'
|
|
29 let s:FirstLevelNonColonEndIndent = '^\C\s*PROTOCOL\>\|\(--.*\)\@<!\<\(\(CHAN\|DATA\)\s\+TYPE\|FUNCTION\)\>'
|
|
30 let s:SecondLevelIndent = '^\C\s*\(IF\|ALT\|PRI\s\+ALT\)\>\|\(--.*\)\@<!?\s*\<CASE\>\s*\(--.*\)\=\_$'
|
|
31 let s:SecondLevelNonColonEndIndent = '\(--.*\)\@<!\<\(CHAN\|DATA\)\s\+TYPE\>'
|
|
32
|
|
33 " Define colon indent
|
|
34 let s:ColonIndent = '\(--.*\)\@<!\<PROC\>'
|
|
35 let s:ColonNonColonEndIndent = '^\C\s*PROTOCOL\>\|\(--.*\)\@<!\<\(\(CHAN\|DATA\)\s\+TYPE\|FUNCTION\)\>'
|
|
36
|
|
37 let s:ColonEnd = '\(--.*\)\@<!:\s*\(--.*\)\=$'
|
|
38 let s:ColonStart = '^\s*:\s*\(--.*\)\=$'
|
|
39
|
|
40 " Define comment
|
|
41 let s:CommentLine = '^\s*--'
|
|
42 "}}}
|
|
43
|
|
44 "{{{ function GetOccamIndent()
|
|
45 " Auxiliary function to get the correct indent for a line of occam code
|
|
46 function GetOccamIndent()
|
|
47
|
|
48 " Ensure magic is on
|
|
49 let save_magic = &magic
|
|
50 setlocal magic
|
|
51
|
|
52 " Get reference line number
|
|
53 let linenum = prevnonblank(v:lnum - 1)
|
|
54 while linenum > 0 && getline(linenum) =~ s:CommentLine
|
|
55 let linenum = prevnonblank(linenum - 1)
|
|
56 endwhile
|
|
57
|
|
58 " Get current indent
|
|
59 let curindent = indent(linenum)
|
|
60
|
|
61 " Get current line
|
|
62 let line = getline(linenum)
|
|
63
|
|
64 " Get previous line number
|
|
65 let prevlinenum = prevnonblank(linenum - 1)
|
|
66 while prevlinenum > 0 && getline(prevlinenum) =~ s:CommentLine
|
|
67 let prevlinenum = prevnonblank(prevlinenum - 1)
|
|
68 endwhile
|
|
69
|
|
70 " Get previous line
|
|
71 let prevline = getline(prevlinenum)
|
|
72
|
|
73 " Colon indent
|
|
74 if getline(v:lnum) =~ s:ColonStart
|
|
75
|
|
76 let found = 0
|
|
77
|
|
78 while found < 1
|
|
79
|
|
80 if line =~ s:ColonStart
|
|
81 let found = found - 1
|
|
82 elseif line =~ s:ColonIndent || (line =~ s:ColonNonColonEndIndent && line !~ s:ColonEnd)
|
|
83 let found = found + 1
|
|
84 endif
|
|
85
|
|
86 if found < 1
|
|
87 let linenum = prevnonblank(linenum - 1)
|
|
88 if linenum > 0
|
|
89 let line = getline(linenum)
|
|
90 else
|
|
91 let found = 1
|
|
92 endif
|
|
93 endif
|
|
94
|
|
95 endwhile
|
|
96
|
|
97 if linenum > 0
|
|
98 let curindent = indent(linenum)
|
|
99 else
|
|
100 let colonline = getline(v:lnum)
|
|
101 let tabstr = ''
|
|
102 while strlen(tabstr) < &tabstop
|
|
103 let tabstr = ' ' . tabstr
|
|
104 endwhile
|
|
105 let colonline = substitute(colonline, '\t', tabstr, 'g')
|
|
106 let curindent = match(colonline, ':')
|
|
107 endif
|
|
108
|
|
109 " Restore magic
|
|
110 if !save_magic|setlocal nomagic|endif
|
|
111
|
|
112 return curindent
|
|
113 endif
|
|
114
|
|
115 if getline(v:lnum) =~ '^\s*:'
|
|
116 let colonline = getline(v:lnum)
|
|
117 let tabstr = ''
|
|
118 while strlen(tabstr) < &tabstop
|
|
119 let tabstr = ' ' . tabstr
|
|
120 endwhile
|
|
121 let colonline = substitute(colonline, '\t', tabstr, 'g')
|
|
122 let curindent = match(colonline, ':')
|
|
123
|
|
124 " Restore magic
|
|
125 if !save_magic|setlocal nomagic|endif
|
|
126
|
|
127 return curindent
|
|
128 endif
|
|
129
|
|
130 " Carriage return indenat
|
|
131 if line =~ s:FirstLevelIndent || (line =~ s:FirstLevelNonColonEndIndent && line !~ s:ColonEnd)
|
|
132 \ || (line !~ s:ColonStart && (prevline =~ s:SecondLevelIndent
|
|
133 \ || (prevline =~ s:SecondLevelNonColonEndIndent && prevline !~ s:ColonEnd)))
|
|
134 let curindent = curindent + &shiftwidth
|
|
135
|
|
136 " Restore magic
|
|
137 if !save_magic|setlocal nomagic|endif
|
|
138
|
|
139 return curindent
|
|
140 endif
|
|
141
|
|
142 " Commented line
|
|
143 if getline(prevnonblank(v:lnum - 1)) =~ s:CommentLine
|
|
144
|
|
145 " Restore magic
|
|
146 if !save_magic|setlocal nomagic|endif
|
|
147
|
|
148 return indent(prevnonblank(v:lnum - 1))
|
|
149 endif
|
|
150
|
|
151 " Look for previous second level IF / ALT / PRI ALT
|
|
152 let found = 0
|
|
153
|
|
154 while !found
|
|
155
|
|
156 if indent(prevlinenum) == curindent - &shiftwidth
|
|
157 let found = 1
|
|
158 endif
|
|
159
|
|
160 if !found
|
|
161 let prevlinenum = prevnonblank(prevlinenum - 1)
|
|
162 while prevlinenum > 0 && getline(prevlinenum) =~ s:CommentLine
|
|
163 let prevlinenum = prevnonblank(prevlinenum - 1)
|
|
164 endwhile
|
|
165 if prevlinenum == 0
|
|
166 let found = 1
|
|
167 endif
|
|
168 endif
|
|
169
|
|
170 endwhile
|
|
171
|
|
172 if prevlinenum > 0
|
|
173 if getline(prevlinenum) =~ s:SecondLevelIndent
|
|
174 let curindent = curindent + &shiftwidth
|
|
175 endif
|
|
176 endif
|
|
177
|
|
178 " Restore magic
|
|
179 if !save_magic|setlocal nomagic|endif
|
|
180
|
|
181 return curindent
|
|
182
|
|
183 endfunction
|
|
184 "}}}
|
48
|
185
|
|
186 let &cpo = s:keepcpo
|
|
187 unlet s:keepcpo
|