annotate runtime/indent/ocaml.vim @ 1569:9fbb40a1228a v7.1.282

updated for version 7.1-282
author vimboss
date Sun, 16 Mar 2008 13:54:13 +0000
parents e63691e7c504
children b7811ab264bf
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
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
2 " Language: OCaml
856
8cd729851562 updated for version 7.0g
vimboss
parents: 551
diff changeset
3 " Maintainers: Jean-Francois Yuen <jfyuen@happycoders.org>
8cd729851562 updated for version 7.0g
vimboss
parents: 551
diff changeset
4 " Mike Leary <leary@nwlink.com>
8cd729851562 updated for version 7.0g
vimboss
parents: 551
diff changeset
5 " Markus Mottl <markus.mottl@gmail.com>
8cd729851562 updated for version 7.0g
vimboss
parents: 551
diff changeset
6 " URL: http://www.ocaml.info/vim/indent/ocaml.vim
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
7 " Last Change: 2005 Jun 25 - Fixed multiple bugs due to 'else\nreturn ind' working
856
8cd729851562 updated for version 7.0g
vimboss
parents: 551
diff changeset
8 " 2005 May 09 - Added an option to not indent OCaml-indents specially (MM)
8cd729851562 updated for version 7.0g
vimboss
parents: 551
diff changeset
9 " 2005 Apr 11 - Fixed an indentation bug concerning "let" (MM)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 " Only load this indent file when no other was loaded.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 if exists("b:did_indent")
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
13 finish
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 let b:did_indent = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 setlocal expandtab
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 setlocal indentexpr=GetOCamlIndent()
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
19 setlocal indentkeys+=0=and,0=class,0=constraint,0=done,0=else,0=end,0=exception,0=external,0=if,0=in,0=include,0=inherit,0=initializer,0=let,0=method,0=open,0=then,0=type,0=val,0=with,0;;,0>\],0\|\],0>},0\|,0},0\],0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 setlocal nolisp
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 setlocal nosmartindent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 setlocal textwidth=80
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 " Comment formatting
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
25 if !exists("no_ocaml_comments")
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
26 if (has("comments"))
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
27 setlocal comments=sr:(*,mb:*,ex:*)
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
28 setlocal fo=cqort
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
29 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 " Only define the function once.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 if exists("*GetOCamlIndent")
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
34 finish
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 " Define some patterns:
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
38 let s:beflet = '^\s*\(initializer\|method\|try\)\|\(\<\(begin\|do\|else\|in\|then\|try\)\|->\|<-\|=\|;\|(\)\s*$'
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 let s:letpat = '^\s*\(let\|type\|module\|class\|open\|exception\|val\|include\|external\)\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 let s:letlim = '\(\<\(sig\|struct\)\|;;\)\s*$'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 let s:lim = '^\s*\(exception\|external\|include\|let\|module\|open\|type\|val\)\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 let s:module = '\<\%(begin\|sig\|struct\|object\)\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 let s:obj = '^\s*\(constraint\|inherit\|initializer\|method\|val\)\>\|\<\(object\|object\s*(.*)\)\s*$'
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
44 let s:type = '^\s*\%(class\|let\|type\)\>.*='
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 " Skipping pattern, for comments
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
47 function s:GetLineWithoutFullComment(lnum)
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
48 let lnum = prevnonblank(a:lnum - 1)
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
49 let lline = substitute(getline(lnum), '(\*.*\*)\s*$', '', '')
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
50 while lline =~ '^\s*$' && lnum > 0
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
51 let lnum = prevnonblank(lnum - 1)
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
52 let lline = substitute(getline(lnum), '(\*.*\*)\s*$', '', '')
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
53 endwhile
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
54 return lnum
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 " Indent for ';;' to match multiple 'let'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 function s:GetInd(lnum, pat, lim)
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
59 let llet = search(a:pat, 'bW')
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
60 let old = indent(a:lnum)
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
61 while llet > 0
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
62 let old = indent(llet)
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
63 let nb = s:GetLineWithoutFullComment(llet)
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
64 if getline(nb) =~ a:lim
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
65 return old
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
66 endif
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
67 let llet = search(a:pat, 'bW')
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
68 endwhile
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
69 return old
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 " Indent pairs
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 function s:FindPair(pstart, pmid, pend)
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
74 call search(a:pend, 'bW')
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
75 return indent(searchpair(a:pstart, a:pmid, a:pend, 'bWn', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment"'))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 " Indent 'let'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 function s:FindLet(pstart, pmid, pend)
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
80 call search(a:pend, 'bW')
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
81 return indent(searchpair(a:pstart, a:pmid, a:pend, 'bWn', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment" || getline(".") =~ "^\\s*let\\>.*=.*\\<in\\s*$" || getline(prevnonblank(".") - 1) =~ s:beflet'))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 function GetOCamlIndent()
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
85 " Find a non-commented line above the current line.
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
86 let lnum = s:GetLineWithoutFullComment(v:lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
88 " At the start of the file use zero indent.
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
89 if lnum == 0
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
90 return 0
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
91 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
93 let ind = indent(lnum)
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
94 let lline = substitute(getline(lnum), '(\*.*\*)\s*$', '', '')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
96 " Return double 'shiftwidth' after lines matching:
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
97 if lline =~ '^\s*|.*->\s*$'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
98 return ind + &sw + &sw
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
99 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
101 let line = getline(v:lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
103 " Indent if current line begins with 'end':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
104 if line =~ '^\s*end\>'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
105 return s:FindPair(s:module, '','\<end\>')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
107 " Indent if current line begins with 'done' for 'do':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
108 elseif line =~ '^\s*done\>'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
109 return s:FindPair('\<do\>', '','\<done\>')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
111 " Indent if current line begins with '}' or '>}':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
112 elseif line =~ '^\s*\(\|>\)}'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
113 return s:FindPair('{', '','}')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
115 " Indent if current line begins with ']', '|]' or '>]':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
116 elseif line =~ '^\s*\(\||\|>\)\]'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
117 return s:FindPair('\[', '','\]')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
119 " Indent if current line begins with ')':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
120 elseif line =~ '^\s*)'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
121 return s:FindPair('(', '',')')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
123 " Indent if current line begins with 'let':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
124 elseif line =~ '^\s*let\>'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
125 if lline !~ s:lim . '\|' . s:letlim . '\|' . s:beflet
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
126 return s:FindLet(s:type, '','\<let\s*$')
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
127 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
129 " Indent if current line begins with 'class' or 'type':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
130 elseif line =~ '^\s*\(class\|type\)\>'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
131 if lline !~ s:lim . '\|\<and\s*$\|' . s:letlim
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
132 return s:FindLet(s:type, '','\<\(class\|type\)\s*$')
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
133 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
135 " Indent for pattern matching:
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
136 elseif line =~ '^\s*|'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
137 if lline !~ '^\s*\(|[^\]]\|\(match\|type\|with\)\>\)\|\<\(function\|parser\|private\|with\)\s*$'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
138 call search('|', 'bW')
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
139 return indent(searchpair('^\s*\(match\|type\)\>\|\<\(function\|parser\|private\|with\)\s*$', '', '^\s*|', 'bWn', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment" || getline(".") !~ "^\\s*|.*->"'))
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
140 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
142 " Indent if current line begins with ';;':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
143 elseif line =~ '^\s*;;'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
144 if lline !~ ';;\s*$'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
145 return s:GetInd(v:lnum, s:letpat, s:letlim)
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
146 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
148 " Indent if current line begins with 'in':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
149 elseif line =~ '^\s*in\>'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
150 if lline !~ '^\s*\(let\|and\)\>'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
151 return s:FindPair('\<let\>', '', '\<in\>')
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
152 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
154 " Indent if current line begins with 'else':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
155 elseif line =~ '^\s*else\>'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
156 if lline !~ '^\s*\(if\|then\)\>'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
157 return s:FindPair('\<if\>', '', '\<else\>')
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
158 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
160 " Indent if current line begins with 'then':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
161 elseif line =~ '^\s*then\>'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
162 if lline !~ '^\s*\(if\|else\)\>'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
163 return s:FindPair('\<if\>', '', '\<then\>')
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
164 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
166 " Indent if current line begins with 'and':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
167 elseif line =~ '^\s*and\>'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
168 if lline !~ '^\s*\(and\|let\|type\)\>\|\<end\s*$'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
169 return ind - &sw
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
170 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
172 " Indent if current line begins with 'with':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
173 elseif line =~ '^\s*with\>'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
174 if lline !~ '^\s*\(match\|try\)\>'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
175 return s:FindPair('\<\%(match\|try\)\>', '','\<with\>')
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
176 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
178 " Indent if current line begins with 'exception', 'external', 'include' or
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
179 " 'open':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
180 elseif line =~ '^\s*\(exception\|external\|include\|open\)\>'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
181 if lline !~ s:lim . '\|' . s:letlim
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
182 call search(line)
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
183 return indent(search('^\s*\(\(exception\|external\|include\|open\|type\)\>\|val\>.*:\)', 'bW'))
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
184 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
186 " Indent if current line begins with 'val':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
187 elseif line =~ '^\s*val\>'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
188 if lline !~ '^\s*\(exception\|external\|include\|open\)\>\|' . s:obj . '\|' . s:letlim
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
189 return indent(search('^\s*\(\(exception\|include\|initializer\|method\|open\|type\|val\)\>\|external\>.*:\)', 'bW'))
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
190 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
191
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
192 " Indent if current line begins with 'constraint', 'inherit', 'initializer'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
193 " or 'method':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
194 elseif line =~ '^\s*\(constraint\|inherit\|initializer\|method\)\>'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
195 if lline !~ s:obj
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
196 return indent(search('\<\(object\|object\s*(.*)\)\s*$', 'bW')) + &sw
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
197 endif
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
198
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
199 endif
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
200
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
201 " Add a 'shiftwidth' after lines ending with:
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
202 if lline =~ '\(:\|=\|->\|<-\|(\|\[\|{\|{<\|\[|\|\[<\|\<\(begin\|do\|else\|fun\|function\|functor\|if\|initializer\|object\|parser\|private\|sig\|struct\|then\|try\)\|\<object\s*(.*)\)\s*$'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
203 let ind = ind + &sw
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
204
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
205 " Back to normal indent after lines ending with ';;':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
206 elseif lline =~ ';;\s*$' && lline !~ '^\s*;;'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
207 let ind = s:GetInd(v:lnum, s:letpat, s:letlim)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
208
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
209 " Back to normal indent after lines ending with 'end':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
210 elseif lline =~ '\<end\s*$'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
211 let ind = s:FindPair(s:module, '','\<end\>')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
212
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
213 " Back to normal indent after lines ending with 'in':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
214 elseif lline =~ '\<in\s*$' && lline !~ '^\s*in\>'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
215 let ind = s:FindPair('\<let\>', '', '\<in\>')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
216
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
217 " Back to normal indent after lines ending with 'done':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
218 elseif lline =~ '\<done\s*$'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
219 let ind = s:FindPair('\<do\>', '','\<done\>')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
220
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
221 " Back to normal indent after lines ending with '}' or '>}':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
222 elseif lline =~ '\(\|>\)}\s*$'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
223 let ind = s:FindPair('{', '','}')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
224
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
225 " Back to normal indent after lines ending with ']', '|]' or '>]':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
226 elseif lline =~ '\(\||\|>\)\]\s*$'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
227 let ind = s:FindPair('\[', '','\]')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
229 " Back to normal indent after comments:
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
230 elseif lline =~ '\*)\s*$'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
231 call search('\*)', 'bW')
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
232 let ind = indent(searchpair('(\*', '', '\*)', 'bWn', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"'))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
233
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
234 " Back to normal indent after lines ending with ')':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
235 elseif lline =~ ')\s*$'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
236 let ind = s:FindPair('(', '',')')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
237
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
238 " If this is a multiline comment then align '*':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
239 elseif lline =~ '^\s*(\*' && line =~ '^\s*\*'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
240 let ind = ind + 1
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
241
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
242 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
243
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
244 " Subtract a 'shiftwidth' after lines matching 'match ... with parser':
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
245 if lline =~ '\<match\>.*\<with\>\s*\<parser\s*$'
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
246 let ind = ind - &sw
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
247 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248
551
7dfd6f1443a7 updated for version 7.0156
vimboss
parents: 20
diff changeset
249 return ind
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
251 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
253 " vim:sw=2