annotate runtime/indent/occam.vim @ 3848:a2fe24ec6a0d v7.3.681

updated for version 7.3.681 Problem: List of distributed files picks up backup files. Solution: Make tutor patterns more specific.
author Bram Moolenaar <bram@vim.org>
date Wed, 03 Oct 2012 21:48:43 +0200
parents dd6c2497c997
children 63b0b7b79b25
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
3526
dd6c2497c997 Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents: 7
diff changeset
23 let s:keepcpo= &cpo
dd6c2497c997 Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents: 7
diff changeset
24 set cpo&vim
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 "{{{ Indent definitions
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 " Define carriage return indent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 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
29 let s:FirstLevelNonColonEndIndent = '^\C\s*PROTOCOL\>\|\(--.*\)\@<!\<\(\(CHAN\|DATA\)\s\+TYPE\|FUNCTION\)\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 let s:SecondLevelIndent = '^\C\s*\(IF\|ALT\|PRI\s\+ALT\)\>\|\(--.*\)\@<!?\s*\<CASE\>\s*\(--.*\)\=\_$'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 let s:SecondLevelNonColonEndIndent = '\(--.*\)\@<!\<\(CHAN\|DATA\)\s\+TYPE\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 " Define colon indent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 let s:ColonIndent = '\(--.*\)\@<!\<PROC\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 let s:ColonNonColonEndIndent = '^\C\s*PROTOCOL\>\|\(--.*\)\@<!\<\(\(CHAN\|DATA\)\s\+TYPE\|FUNCTION\)\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 let s:ColonEnd = '\(--.*\)\@<!:\s*\(--.*\)\=$'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 let s:ColonStart = '^\s*:\s*\(--.*\)\=$'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 " Define comment
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 let s:CommentLine = '^\s*--'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 "}}}
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 "{{{ function GetOccamIndent()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 " Auxiliary function to get the correct indent for a line of occam code
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 function GetOccamIndent()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 " Ensure magic is on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 let save_magic = &magic
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 setlocal magic
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 " Get reference line number
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 let linenum = prevnonblank(v:lnum - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 while linenum > 0 && getline(linenum) =~ s:CommentLine
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 let linenum = prevnonblank(linenum - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 " Get current indent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 let curindent = indent(linenum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 " Get current line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 let line = getline(linenum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 " Get previous line number
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 let prevlinenum = prevnonblank(linenum - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 while prevlinenum > 0 && getline(prevlinenum) =~ s:CommentLine
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 let prevlinenum = prevnonblank(prevlinenum - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 " Get previous line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 let prevline = getline(prevlinenum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 " Colon indent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 if getline(v:lnum) =~ s:ColonStart
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 let found = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 while found < 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 if line =~ s:ColonStart
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 elseif line =~ s:ColonIndent || (line =~ s:ColonNonColonEndIndent && line !~ s:ColonEnd)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 let found = found + 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 if found < 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 let linenum = prevnonblank(linenum - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 if linenum > 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 let line = getline(linenum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 let found = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 if linenum > 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 let curindent = indent(linenum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100 let colonline = getline(v:lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 let tabstr = ''
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 while strlen(tabstr) < &tabstop
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 let tabstr = ' ' . tabstr
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105 let colonline = substitute(colonline, '\t', tabstr, 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 let curindent = match(colonline, ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 " Restore magic
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 if !save_magic|setlocal nomagic|endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 return curindent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 if getline(v:lnum) =~ '^\s*:'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 let colonline = getline(v:lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117 let tabstr = ''
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 while strlen(tabstr) < &tabstop
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119 let tabstr = ' ' . tabstr
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121 let colonline = substitute(colonline, '\t', tabstr, 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 let curindent = match(colonline, ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 " Restore magic
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 if !save_magic|setlocal nomagic|endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 return curindent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 " Carriage return indenat
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 if line =~ s:FirstLevelIndent || (line =~ s:FirstLevelNonColonEndIndent && line !~ s:ColonEnd)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 \ || (line !~ s:ColonStart && (prevline =~ s:SecondLevelIndent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 \ || (prevline =~ s:SecondLevelNonColonEndIndent && prevline !~ s:ColonEnd)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 let curindent = curindent + &shiftwidth
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136 " Restore magic
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 if !save_magic|setlocal nomagic|endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 return curindent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 " Commented line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143 if getline(prevnonblank(v:lnum - 1)) =~ s:CommentLine
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145 " Restore magic
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 if !save_magic|setlocal nomagic|endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148 return indent(prevnonblank(v:lnum - 1))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151 " Look for previous second level IF / ALT / PRI ALT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152 let found = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154 while !found
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156 if indent(prevlinenum) == curindent - &shiftwidth
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157 let found = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160 if !found
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 while prevlinenum > 0 && getline(prevlinenum) =~ s:CommentLine
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163 let prevlinenum = prevnonblank(prevlinenum - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 if prevlinenum == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166 let found = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 if prevlinenum > 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173 if getline(prevlinenum) =~ s:SecondLevelIndent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174 let curindent = curindent + &shiftwidth
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178 " Restore magic
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179 if !save_magic|setlocal nomagic|endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181 return curindent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184 "}}}
3526
dd6c2497c997 Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents: 7
diff changeset
185
dd6c2497c997 Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents: 7
diff changeset
186 let &cpo = s:keepcpo
dd6c2497c997 Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents: 7
diff changeset
187 unlet s:keepcpo