3 " Maintainer: Mario Schweigler <ms44@kent.ac.uk>
4 " Last Change: 23 April 2003
6 " Only load this indent file when no other was loaded.
7 if exists("b:did_indent")
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=:
19 " Only define the function once
20 if exists("*GetOccamIndent")
24 "{{{ Indent definitions
25 " Define carriage return indent
26 let s:FirstLevelIndent = '^\C\s*\(IF\|ALT\|PRI\s\+ALT\|PAR\|SEQ\|PRI\s\+PAR\|WHILE\|VALOF\|CLAIM\|FORKING\)\>\|\(--.*\)\@<!\(\<PROC\>\|??\|\<CASE\>\s*\(--.*\)\=\_$\)'
27 let s:FirstLevelNonColonEndIndent = '^\C\s*PROTOCOL\>\|\(--.*\)\@<!\<\(\(CHAN\|DATA\)\s\+TYPE\|FUNCTION\)\>'
28 let s:SecondLevelIndent = '^\C\s*\(IF\|ALT\|PRI\s\+ALT\)\>\|\(--.*\)\@<!?\s*\<CASE\>\s*\(--.*\)\=\_$'
29 let s:SecondLevelNonColonEndIndent = '\(--.*\)\@<!\<\(CHAN\|DATA\)\s\+TYPE\>'
32 let s:ColonIndent = '\(--.*\)\@<!\<PROC\>'
33 let s:ColonNonColonEndIndent = '^\C\s*PROTOCOL\>\|\(--.*\)\@<!\<\(\(CHAN\|DATA\)\s\+TYPE\|FUNCTION\)\>'
35 let s:ColonEnd = '\(--.*\)\@<!:\s*\(--.*\)\=$'
36 let s:ColonStart = '^\s*:\s*\(--.*\)\=$'
39 let s:CommentLine = '^\s*--'
42 "{{{ function GetOccamIndent()
43 " Auxiliary function to get the correct indent for a line of occam code
44 function GetOccamIndent()
47 let save_magic = &magic
50 " Get reference line number
51 let linenum = prevnonblank(v:lnum - 1)
52 while linenum > 0 && getline(linenum) =~ s:CommentLine
53 let linenum = prevnonblank(linenum - 1)
57 let curindent = indent(linenum)
60 let line = getline(linenum)
62 " Get previous line number
63 let prevlinenum = prevnonblank(linenum - 1)
64 while prevlinenum > 0 && getline(prevlinenum) =~ s:CommentLine
65 let prevlinenum = prevnonblank(prevlinenum - 1)
69 let prevline = getline(prevlinenum)
72 if getline(v:lnum) =~ s:ColonStart
78 if line =~ s:ColonStart
80 elseif line =~ s:ColonIndent || (line =~ s:ColonNonColonEndIndent && line !~ s:ColonEnd)
85 let linenum = prevnonblank(linenum - 1)
87 let line = getline(linenum)
96 let curindent = indent(linenum)
98 let colonline = getline(v:lnum)
100 while strlen(tabstr) < &tabstop
101 let tabstr = ' ' . tabstr
103 let colonline = substitute(colonline, '\t', tabstr, 'g')
104 let curindent = match(colonline, ':')
108 if !save_magic|setlocal nomagic|endif
113 if getline(v:lnum) =~ '^\s*:'
114 let colonline = getline(v:lnum)
116 while strlen(tabstr) < &tabstop
117 let tabstr = ' ' . tabstr
119 let colonline = substitute(colonline, '\t', tabstr, 'g')
120 let curindent = match(colonline, ':')
123 if !save_magic|setlocal nomagic|endif
128 " Carriage return indenat
129 if line =~ s:FirstLevelIndent || (line =~ s:FirstLevelNonColonEndIndent && line !~ s:ColonEnd)
130 \ || (line !~ s:ColonStart && (prevline =~ s:SecondLevelIndent
131 \ || (prevline =~ s:SecondLevelNonColonEndIndent && prevline !~ s:ColonEnd)))
132 let curindent = curindent + &shiftwidth
135 if !save_magic|setlocal nomagic|endif
141 if getline(prevnonblank(v:lnum - 1)) =~ s:CommentLine
144 if !save_magic|setlocal nomagic|endif
146 return indent(prevnonblank(v:lnum - 1))
149 " Look for previous second level IF / ALT / PRI ALT
154 if indent(prevlinenum) == curindent - &shiftwidth
159 let prevlinenum = prevnonblank(prevlinenum - 1)
160 while prevlinenum > 0 && getline(prevlinenum) =~ s:CommentLine
161 let prevlinenum = prevnonblank(prevlinenum - 1)
171 if getline(prevlinenum) =~ s:SecondLevelIndent
172 let curindent = curindent + &shiftwidth
177 if !save_magic|setlocal nomagic|endif