annotate runtime/indent/occam.vim @ 1977:f018c759e4ed v7.2.274

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