annotate runtime/indent/erlang.vim @ 2639:73dd10c18ec4 v7.3.060

updated for version 7.3.060 Problem: Netbeans: crash when socket is disconnected unexpectedly. Solution: Don't cleanup when a read fails, put a message in the queue and disconnect later. (Xavier de Gaye)
author Bram Moolenaar <bram@vim.org>
date Tue, 16 Nov 2010 15:49:02 +0100
parents 73fe8baea242
children af1e8a1714c2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1620
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
1 " Vim indent file
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
2 " Language: Erlang
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
3 " Maintainer: Csaba Hoch <csaba.hoch@gmail.com>
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
4 " Contributor: Edwin Fine <efine145_nospam01 at usa dot net>
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
5 " Last Change: 2008 Mar 12
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
6
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
7 " Only load this indent file when no other was loaded.
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
8 if exists("b:did_indent")
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
9 finish
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
10 endif
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
11 let b:did_indent = 1
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
12
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
13 setlocal indentexpr=ErlangIndent()
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
14 setlocal indentkeys+==after,=end,=catch,=),=],=}
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
15
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
16 " Only define the functions once.
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
17 if exists("*ErlangIndent")
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
18 finish
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
19 endif
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
20
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
21 " The function go through the whole line, analyses it and sets the indentation
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
22 " (ind variable).
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
23 " l: the number of the line to be examined.
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
24 function s:ErlangIndentAtferLine(l)
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
25 let i = 0 " the index of the current character in the line
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
26 let length = strlen(a:l) " the length of the line
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
27 let ind = 0 " how much should be the difference between the indentation of
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
28 " the current line and the indentation of the next line?
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
29 " e.g. +1: the indentation of the next line should be equal to
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
30 " the indentation of the current line plus one shiftwidth
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
31 let lastFun = 0 " the last token was a 'fun'
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
32 let lastReceive = 0 " the last token was a 'receive'; needed for 'after'
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
33 let lastHashMark = 0 " the last token was a 'hashmark'
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
34
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
35 while 0<= i && i < length
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
36
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
37 " m: the next value of the i
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
38 if a:l[i] == '%'
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
39 break
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
40 elseif a:l[i] == '"'
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
41 let m = matchend(a:l,'"\%([^"\\]\|\\.\)*"',i)
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
42 let lastReceive = 0
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
43 elseif a:l[i] == "'"
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
44 let m = matchend(a:l,"'[^']*'",i)
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
45 let lastReceive = 0
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
46 elseif a:l[i] =~# "[a-z]"
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
47 let m = matchend(a:l,".[[:alnum:]_]*",i)
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
48 if lastFun
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
49 let ind = ind - 1
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
50 let lastFun = 0
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
51 let lastReceive = 0
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
52 elseif a:l[(i):(m-1)] =~# '^\%(case\|if\|try\)$'
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
53 let ind = ind + 1
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
54 elseif a:l[(i):(m-1)] =~# '^receive$'
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
55 let ind = ind + 1
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
56 let lastReceive = 1
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
57 elseif a:l[(i):(m-1)] =~# '^begin$'
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
58 let ind = ind + 2
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
59 let lastReceive = 0
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
60 elseif a:l[(i):(m-1)] =~# '^end$'
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
61 let ind = ind - 2
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
62 let lastReceive = 0
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
63 elseif a:l[(i):(m-1)] =~# '^after$'
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
64 if lastReceive == 0
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
65 let ind = ind - 1
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
66 else
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
67 let ind = ind + 0
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
68 end
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
69 let lastReceive = 0
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
70 elseif a:l[(i):(m-1)] =~# '^fun$'
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
71 let ind = ind + 1
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
72 let lastFun = 1
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
73 let lastReceive = 0
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
74 endif
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
75 elseif a:l[i] =~# "[A-Z_]"
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
76 let m = matchend(a:l,".[[:alnum:]_]*",i)
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
77 let lastReceive = 0
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
78 elseif a:l[i] == '$'
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
79 let m = i+2
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
80 let lastReceive = 0
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
81 elseif a:l[i] == "." && (i+1>=length || a:l[i+1]!~ "[0-9]")
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
82 let m = i+1
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
83 if lastHashMark
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
84 let lastHashMark = 0
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
85 else
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
86 let ind = ind - 1
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
87 end
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
88 let lastReceive = 0
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
89 elseif a:l[i] == '-' && (i+1<length && a:l[i+1]=='>')
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
90 let m = i+2
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
91 let ind = ind + 1
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
92 let lastReceive = 0
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
93 elseif a:l[i] == ';'
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
94 let m = i+1
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
95 let ind = ind - 1
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
96 let lastReceive = 0
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
97 elseif a:l[i] == '#'
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
98 let m = i+1
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
99 let lastHashMark = 1
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
100 elseif a:l[i] =~# '[({[]'
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
101 let m = i+1
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
102 let ind = ind + 1
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
103 let lastFun = 0
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
104 let lastReceive = 0
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
105 let lastHashMark = 0
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
106 elseif a:l[i] =~# '[)}\]]'
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
107 let m = i+1
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
108 let ind = ind - 1
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
109 let lastReceive = 0
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
110 else
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
111 let m = i+1
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
112 endif
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
113
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
114 let i = m
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
115
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
116 endwhile
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
117
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
118 return ind
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
119
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
120 endfunction
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
121
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
122 function s:FindPrevNonBlankNonComment(lnum)
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
123 let lnum = prevnonblank(a:lnum)
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
124 let line = getline(lnum)
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
125 " continue to search above if the current line begins with a '%'
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
126 while line =~# '^\s*%.*$'
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
127 let lnum = prevnonblank(lnum - 1)
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
128 if 0 == lnum
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
129 return 0
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
130 endif
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
131 let line = getline(lnum)
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
132 endwhile
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
133 return lnum
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
134 endfunction
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
135
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
136 function ErlangIndent()
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
137
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
138 " Find a non-blank line above the current line.
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
139 let lnum = prevnonblank(v:lnum - 1)
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
140
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
141 " Hit the start of the file, use zero indent.
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
142 if lnum == 0
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
143 return 0
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
144 endif
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
145
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
146 let prevline = getline(lnum)
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
147 let currline = getline(v:lnum)
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
148
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
149 let ind = indent(lnum) + &sw * s:ErlangIndentAtferLine(prevline)
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
150
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
151 " special cases:
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
152 if prevline =~# '^\s*\%(after\|end\)\>'
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
153 let ind = ind + 2*&sw
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
154 endif
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
155 if currline =~# '^\s*end\>'
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
156 let ind = ind - 2*&sw
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
157 endif
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
158 if currline =~# '^\s*after\>'
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
159 let plnum = s:FindPrevNonBlankNonComment(v:lnum-1)
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
160 if getline(plnum) =~# '^[^%]*\<receive\>\s*\%(%.*\)\=$'
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
161 let ind = ind - 1*&sw
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
162 " If the 'receive' is not in the same line as the 'after'
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
163 else
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
164 let ind = ind - 2*&sw
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
165 endif
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
166 endif
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
167 if prevline =~# '^\s*[)}\]]'
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
168 let ind = ind + 1*&sw
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
169 endif
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
170 if currline =~# '^\s*[)}\]]'
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
171 let ind = ind - 1*&sw
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
172 endif
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
173 if prevline =~# '^\s*\%(catch\)\s*\%(%\|$\)'
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
174 let ind = ind + 1*&sw
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
175 endif
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
176 if currline =~# '^\s*\%(catch\)\s*\%(%\|$\)'
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
177 let ind = ind - 1*&sw
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
178 endif
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
179
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
180 if ind<0
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
181 let ind = 0
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
182 endif
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
183 return ind
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
184
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
185 endfunction
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
186
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
187 " TODO:
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
188 "
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
189 " f() ->
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
190 " x("foo
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
191 " bar")
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
192 " ,
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
193 " bad_indent.
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
194 "
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
195 " fun
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
196 " init/0,
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
197 " bad_indent
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
198 "
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
199 " #rec
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
200 " .field,
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
201 " bad_indent
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
202 "
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
203 " case X of
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
204 " 1 when A; B ->
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
205 " bad_indent
73fe8baea242 updated for version 7.2a
vimboss
parents:
diff changeset
206