annotate runtime/indent/occam.vim @ 28379:6dd88e45d47d

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