]> git.pld-linux.org Git - packages/vim.git/blame - vim-ocaml.patch
- detect apache2 configs; rel 2
[packages/vim.git] / vim-ocaml.patch
CommitLineData
91bee7ef
MM
1diff -Naur vim61.old/runtime/indent/ocaml.vim vim61/runtime/indent/ocaml.vim
2--- vim61.old/runtime/indent/ocaml.vim Wed Oct 30 22:10:31 2002
3+++ vim61/runtime/indent/ocaml.vim Wed Oct 30 22:12:09 2002
4@@ -1,11 +1,12 @@
5 " Vim indent file
6 " Language: OCaml
7-" Maintainers: Mike Leary <leary@nwlink.com>
8-" Markus Mottl <markus@oefai.at>
9-" URL: http://www.ai.univie.ac.at/~markus/vim/indent/ocaml.vim
10-" Last Change: 2001 Oct 03 - minor addition (MM)
11-" 2001 Sep 02 - set option 'expandtab' (MM)
12-" 2001 Aug 29 - revised all rules (MM)
13+" Maintainers: Jean-Francois Yuen <jfyuen@ifrance.com>
14+" Mike Leary <leary@nwlink.com>
15+" Markus Mottl <markus@oefai.at>
16+" URL: http://www.oefai.at/~markus/vim/indent/ocaml.vim
17+" Last Change: 2002 Oct 28 - Fixed bug with indentation of ']' (MM)
18+" 2002 Oct 22 - Major rewrite (JY)
19+" 2002 Sep 08 - improved ';;' handling (JY)
20
21 " Only load this indent file when no other was loaded.
22 if exists("b:did_indent")
23@@ -15,16 +16,68 @@
24
25 setlocal expandtab
26 setlocal indentexpr=GetOCamlIndent()
27-setlocal indentkeys+=0=done,0=end,0=if,0=then,0=else,0=and,0=in,0=with,0=>],0=\|],0},0],0)
28+setlocal indentkeys+=0=and,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)
29 setlocal nolisp
30 setlocal nosmartindent
31 setlocal textwidth=80
32
33+" Comment formatting
34+if (has("comments"))
35+ set comments=sr:(*,mb:*,ex:*)
36+ set fo=cqort
37+endif
38+
39 " Only define the function once.
40 if exists("*GetOCamlIndent")
41 finish
42 endif
43
44+" Define some patterns:
45+let s:beflet = '^\s*\(try\|method\)\|\(\<\(begin\|do\|else\|in\|then\|try\)\|->\|;\)\s*$'
46+let s:letpat = '^\s*\(let\|type\|module\|class\|open\|exception\|val\|include\|external\)\>'
47+let s:letlim = '\(\<\(sig\|struct\)\|;;\)\s*$'
48+let s:lim = '^\s*\(exception\|external\|include\|let\|module\|open\|type\|val\)\>'
49+let s:module = '\<\%(begin\|sig\|struct\|object\)\>'
50+let s:obj = '^\s*\(constraint\|inherit\|initializer\|method\|val\)\>\|\<\(object\|object\s*(.*)\)\s*$'
51+let s:type = '^\s*\%(let\|type\)\>.*='
52+let s:val = '^\s*\(val\|external\)\>.*:'
53+
54+" Skipping pattern, for comments
55+function s:SkipPattern(lnum, pat)
56+ let def = prevnonblank(a:lnum - 1)
57+ while def > 0 && getline(def) =~ a:pat
58+ let def = prevnonblank(def - 1)
59+ endwhile
60+ return def
61+endfunction
62+
63+" Indent for ';;' to match multiple 'let'
64+function s:GetInd(lnum, pat, lim)
65+ let llet = search(a:pat, 'bW')
66+ let old = indent(a:lnum)
67+ while llet > 0
68+ let old = indent(llet)
69+ let nb = s:SkipPattern(llet, '^\s*(\*.*\*)\s*$')
70+ if getline(nb) =~ a:lim
71+ return old
72+ endif
73+ let llet = search(a:pat, 'bW')
74+ endwhile
75+ return old
76+endfunction
77+
78+" Indent pairs
79+function s:FindPair(pstart, pmid, pend)
80+ call search(a:pend, 'bW')
81+ return indent(searchpair(a:pstart, a:pmid, a:pend, 'bWn', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment"'))
82+endfunction
83+
84+" Indent 'let'
85+function s:FindLet(pstart, pmid, pend)
86+ call search(a:pend, 'bW')
87+ 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*let\\>.*=\\s*$\\|" . s:beflet'))
88+endfunction
89+
90 function GetOCamlIndent()
91 " Find a non-blank line above the current line.
92 let lnum = prevnonblank(v:lnum - 1)
93@@ -34,8 +87,8 @@
94 return 0
95 endif
96
97- let ind=indent(lnum)
98- let lline=getline(lnum)
99+ let ind = indent(lnum)
100+ let lline = getline(lnum)
101
102 " Return double 'shiftwidth' after lines matching:
103 if lline =~ '^\s*|.*->\s*$'
104@@ -43,17 +96,118 @@
105 endif
106
107 " Add a 'shiftwidth' after lines ending with:
108- if lline =~ '\(:\|=\|->\|<-\|(\|[\|{\|[|\|[<\|(\*\|\<\(begin\|struct\|sig\|functor\|object\|try\|do\|if\|then\|else\|fun\|function\|parser\)\>\)\s*$'
109+ if lline =~ '\(:\|=\|->\|<-\|(\|[\|{\|[|\|[<\|\<\(begin\|struct\|sig\|functor\|object\|try\|do\|if\|then\|else\|fun\|function\|parser\)\|\<object\s*(.*)\)\s*$'
110 let ind = ind + &sw
111+
112+ " Back to normal indent after lines ending with ';;':
113+ elseif lline =~ ';;\s*$' && lline !~ '^\s*;;'
114+ let ind = s:GetInd(v:lnum, s:letpat, s:letlim)
115+
116+ " Back to normal indent after lines ending with 'end':
117+ elseif lline =~ '\<end\s*$' && lline !~ '^\s*end\>'
118+ let ind = s:FindPair(s:module, '','\<end\>')
119+
120+ " Back to normal indent after lines ending with 'in':
121+ elseif lline =~ '\<in\s*$' && lline !~ '^\s*in\>'
122+ let ind = s:FindPair('\<let\>', '', '\<in\>')
123+
124+ " Back to normal indent after lines ending with 'done':
125+ elseif lline =~ '\<done\s*$' && lline !~ '^\s*done\>'
126+ let ind = s:FindPair('\<do\>', '','\<done\>')
127+
128+ " Back to normal indent after lines ending with '}':
129+ elseif lline =~ '}\s*$' && lline !~ '^\s*}'
130+ let ind = s:FindPair('{', '','}')
131+
132+ " Back to normal indent after lines ending with '>]':
133+ elseif lline =~ '>\]\s*$' && lline !~ '^\s*>\]'
134+ let ind = s:FindPair('\[<', '','>\]')
135+
136+ " Back to normal indent after lines ending with '|]':
137+ elseif lline =~ '|\]\s*$' && lline !~ '^\s*|\]'
138+ let ind = s:FindPair('\[|', '','|\]')
139+
140+ " Back to normal indent after lines ending with ']':
141+ elseif lline =~ '\]\s*$' && lline !~ '^\s*\]'
142+ let ind = s:FindPair('\[', '','\]')
143+
144+ " Back to normal indent after comments:
145+ elseif lline =~ '\*)\s*$' && lline !~ '^\s*\*)'
146+ call search('\*)', 'bW')
147+ let ind = indent(searchpair('(\*', '', '\*)', 'bWn', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"'))
148+
149+ " Back to normal indent after lines ending with ')':
150+ elseif lline =~ ')\s*$' && lline !~ '^\s*)'
151+ let ind = s:FindPair('(', '',')')
152+
153+ endif
154+
155+ " Subtract a 'shiftwidth' after lines matching 'match ... with parser':
156+ if lline =~ '^\s*match\>.*\<with\>\s*\<parser\s*$'
157+ let ind = ind - &sw
158 endif
159
160- let line=getline(v:lnum)
161+ let line = getline(v:lnum)
162
163- " Subtract a 'shiftwidth' if current line begins with:
164- if line =~ '^\s*\(\(done\|end\)\>\|>]\||]\|}\|]\|)\)'
165- return ind - &sw
166+ " Indent if current line begins with 'end'
167+ " for 'sig', 'struct', 'object' and 'begin':
168+ if line =~ '^\s*end\>'
169+ return s:FindPair(s:module, '','\<end\>')
170+
171+ " Indent if current line begins with 'done' for 'do':
172+ elseif line =~ '^\s*done\>'
173+ return s:FindPair('\<do\>', '','\<done\>')
174+
175+ " Indent if current line begins with '}':
176+ elseif line =~ '^\s*}'
177+ return s:FindPair('{', '','}')
178+
179+ " Indent if current line begins with '>]':
180+ elseif line =~ '^\s*>\]'
181+ return s:FindPair('\[<', '','>\]')
182+
183+ " Indent if current line begins with '|]':
184+ elseif line =~ '^\s*|\]'
185+ return s:FindPair('\[|', '','|\]')
186+
187+ " Indent if current line begins with ']':
188+ elseif line =~ '^\s*\]'
189+ return s:FindPair('\[', '','\]')
190+
191+ " Indent if current line begins with ')':
192+ elseif line =~ '^\s*)'
193+ return s:FindPair('(', '',')')
194+
195+ " Indent if current line begins with 'let'
196+ " and last line does not begin with 'let' or end with 'in' or ';;':
197+ elseif line =~ '^\s*let\>'
198+ if lline !~ s:lim . '\|' . s:letlim . '\|' . s:beflet
199+ return s:FindLet(s:type, '','\<let\s*$')
200+ else return ind
201+ endif
202
203- " Subtract a 'shiftwidth' if current line begins with 'if' and last
204+ " Indent if current line begins with 'type'
205+ " and last line does not end with 'and' or ';;':
206+ elseif line =~ '^\s*type\>'
207+ if lline !~ s:lim . '\|\<and\s*$\|' . s:letlim
208+ return s:FindLet(s:type, '','\<type\s*$')
209+ else return ind
210+ endif
211+
212+ " Indent for pattern matching:
213+ elseif line =~ '^\s*|'
214+ if lline !~ '^\s*\(|\|\(match\|with\|type\)\>\)\|\<\(function\|parser\|with\)\s*$'
215+ return s:FindPair('^\s*\(type\|match\)\>\|\<\(with\|function\|parser\)\s*$', '', '|')
216+ else return ind
217+ endif
218+
219+ " Indent if current line begins with ';;':
220+ elseif line =~ '^\s*;;'
221+ if lline !~ ';;\s*$'
222+ return s:GetInd(v:lnum, s:letpat, s:letlim)
223+ endif
224+
225+ " Subtract a 'shiftwidth' if current line begins with 'if' and previous
226 " line ends with 'else':
227 elseif line =~ '^\s*if\>'
228 if lline =~ '\<else\s*$'
229@@ -61,39 +215,114 @@
230 else return ind
231 endif
232
233- " Subtract a 'shiftwidth' if current line begins with 'in' and last
234+ " Indent if current line begins with 'in' and previous
235 " line does not start with 'let' or 'and':
236 elseif line =~ '^\s*in\>'
237 if lline !~ '^\s*\(let\|and\)\>'
238- return ind - &sw
239+ return s:FindPair('\<let\>', '', '\<in\>')
240 else return ind
241 endif
242
243- " Subtract a 'shiftwidth' if current line begins with 'else' or 'then'
244- " and previous line does not start with 'if', 'then' or 'else'
245- elseif line =~ '^\s*\(else\|then\)\>'
246+ " Indent if current line begins with 'else'
247+ " and previous line does not start with 'if', 'then' or 'else':
248+ elseif line =~ '^\s*else\>'
249 if lline !~ '^\s*\(if\|else\|then\)\>'
250- return ind - &sw
251+ return s:FindPair('\<if\>', '', '\<else\>')
252 else return ind
253 endif
254
255- " Subtract a 'shiftwidth' if current line begins with 'and' and previous
256- " line does not start with 'let', 'and' or 'type' or end with 'end'
257- " (for classes):
258+ " Indent if current line begins with 'then'
259+ " and previous line does not start with 'if', 'then' or 'else':
260+ elseif line =~ '^\s*then\>'
261+ if lline !~ '^\s*\(if\|else\|then\)\>'
262+ return s:FindPair('\<if\>', '', '\<then\>')
263+ else return ind
264+ endif
265+
266+ " Indent if current line begins with 'and' and previous
267+ " line does not start with 'let', 'and' or 'type':
268 elseif line =~ '^\s*and\>'
269- if lline !~ '^\s*\(let\|and\|type\)\>\|\<end\s*$'
270- return ind - &sw
271+ if lline !~ '^\s*\(and\|let\|type\)\>'
272+ return s:FindPair('^\s*\%(let\|type\|class\)\>', '', '\<and\>')
273 else return ind
274 endif
275
276- " Subtract a 'shiftwidth' if current line begins with 'with'
277+ " Indent if current line begins with 'with'
278 " and previous line does not start with 'match' or 'try':
279 elseif line =~ '^\s*with\>'
280 if lline !~ '^\s*\(match\|try\)\>'
281- return ind - &sw
282+ return s:FindPair('\<\%(match\|try\)\>', '','\<with\>')
283+ else return ind
284+ endif
285+
286+ " Indent if current line begins with 'exception':
287+ elseif line =~ '^\s*exception\>'
288+ if lline !~ s:lim . '\|' . s:letlim
289+ return indent(search(s:val . '\|^\s*\(external\|include\|open\|type\)\>'))
290+ else return ind
291+ endif
292+
293+ " Indent if current line begins with 'external':
294+ elseif line =~ '^\s*external\>'
295+ if lline !~ s:lim . '\|' . s:letlim
296+ return indent(search(s:val . '\|^\s*\(exception\|include\|open\|type\)\>'))
297+ else return ind
298+ endif
299+
300+ " Indent if current line begins with 'include':
301+ elseif line =~ '^\s*include\>'
302+ if lline !~ s:lim . '\|' . s:letlim
303+ return indent(search(s:val . '\|^\s*\(exception\|external\|open\|type\)\>'))
304+ else return ind
305+ endif
306+
307+ " Indent if current line begins with 'open':
308+ elseif line =~ '^\s*open\>'
309+ if lline !~ s:lim . '\|' . s:letlim
310+ return indent(search(s:val . '\|^\s*\(exception\|external\|include\|type\)\>'))
311+ else return ind
312+ endif
313+
314+ " Indent if current line begins with 'val':
315+ elseif line =~ '^\s*val\>'
316+ if lline !~ '^\s*\(exception\|external\|include\|open\)\>\|' . s:obj . '\|' . s:letlim
317+ return indent(search(s:val . '\|^\s*\(exception\|include\|initializer\|method\|open\|type\)\>', 'bW'))
318 else return ind
319 endif
320
321+ " Indent if current line begins with 'constraint':
322+ elseif line =~ '^\s*constraint\>'
323+ if lline !~ s:obj
324+ return indent(search('^\s*\(inherit\|initializer\|method\|val\)\>'))
325+ else return ind
326+ endif
327+
328+ " Indent if current line begins with 'inherit':
329+ elseif line =~ '^\s*inherit\>'
330+ if lline !~ s:obj
331+ return indent(search('^\s*\(constraint\|initializer\|method\|val\)\>'))
332+ else return ind
333+ endif
334+
335+ " Indent if current line begins with 'inherit':
336+ elseif line =~ '^\s*initializer\>'
337+ if lline !~ s:obj
338+ return indent(search('^\s*\(constraint\|inherit\|method\|val\)\>'))
339+ else return ind
340+ endif
341+
342+ " Indent if current line begins with 'method':
343+ elseif line =~ '^\s*method\>'
344+ if lline !~ s:obj
345+ return indent(search('^\s*\(constraint\|inherit\|initializer\|val\)\>'))
346+ else return ind
347+ endif
348+
349+ " Indent back to normal after comments:
350+ elseif line =~ '^\s*\*)'
351+ call search('\*)', 'bW')
352+ return indent(searchpair('(\*', '', '\*)', 'bWn', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"'))
353+
354 endif
355
356 return ind
357diff -Naur vim61.old/runtime/syntax/ocaml.vim vim61/runtime/syntax/ocaml.vim
358--- vim61.old/runtime/syntax/ocaml.vim Wed Oct 30 22:10:33 2002
359+++ vim61/runtime/syntax/ocaml.vim Wed Oct 30 22:11:41 2002
360@@ -3,12 +3,11 @@
361 " Filenames: *.ml *.mli *.mll *.mly
362 " Maintainers: Markus Mottl <markus@oefai.at>
363 " Karl-Heinz Sylla <Karl-Heinz.Sylla@gmd.de>
364-" URL: http://www.ai.univie.ac.at/~markus/vim/syntax/ocaml.vim
365-" Last Change: 2001 Nov 20 - Fixed small bug with modules (MM)
366-" 2001 Sep 01 - Fixed small bug with '\'' (MM)
367-" 2001 Aug 29 - Added rules for scripting directives (MM)
368-" 2001 Aug 28 - Upgraded URL & mail address (MM)
369-" 2001 Apr 26 - upgraded for new Vim version (MM)
370+" Issac Trotts <<ijtrotts@ucdavis.edu>
371+" URL: http://www.oefai.at/~markus/vim/syntax/ocaml.vim
372+" Last Change: 2002 Oct 30 - New variable "ocaml_revised" (MM)
373+" 2002 Oct 24 - Small fix for "module type" (MM)
374+" 2002 Jun 16 - Added "&&", "<" and ">" as operators (MM)
375
376 " For version 5.x: Clear all syntax items
377 " For version 6.x: Quit when a syntax file was already loaded
378@@ -42,7 +41,11 @@
379
380 syn match ocamlCountErr "\<downto\>"
381 syn match ocamlCountErr "\<to\>"
382-syn match ocamlDoErr "\<do\>"
383+
384+if !exists("ocaml_revised")
385+ syn match ocamlDoErr "\<do\>"
386+endif
387+
388 syn match ocamlDoneErr "\<done\>"
389 syn match ocamlThenErr "\<then\>"
390
391@@ -79,7 +82,9 @@
392
393
394 " Blocks
395-syn region ocamlEnd matchgroup=ocamlKeyword start="\<begin\>" matchgroup=ocamlKeyword end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr
396+if !exists("ocaml_revised")
397+ syn region ocamlEnd matchgroup=ocamlKeyword start="\<begin\>" matchgroup=ocamlKeyword end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr
398+endif
399
400
401 " "for"
402@@ -87,8 +92,9 @@
403
404
405 " "do"
406-syn region ocamlDo matchgroup=ocamlKeyword start="\<do\>" matchgroup=ocamlKeyword end="\<done\>" contains=ALLBUT,@ocamlContained,ocamlDoneErr
407-
408+if !exists("ocaml_revised")
409+ syn region ocamlDo matchgroup=ocamlKeyword start="\<do\>" matchgroup=ocamlKeyword end="\<done\>" contains=ALLBUT,@ocamlContained,ocamlDoneErr
410+endif
411
412 " "if"
413 syn region ocamlNone matchgroup=ocamlKeyword start="\<if\>" matchgroup=ocamlKeyword end="\<then\>" contains=ALLBUT,@ocamlContained,ocamlThenErr
414@@ -134,12 +140,13 @@
415 syn region ocamlWithRest start="[^)]" end=")"me=e-1 contained contains=ALLBUT,@ocamlContained
416
417 " "module type"
418-syn region ocamlKeyword start="\<module\s*type\>" matchgroup=ocamlModule end="\<\w\(\w\|'\)*\>" contains=ocamlComment skipwhite skipempty nextgroup=ocamlMTDef
419+syn region ocamlKeyword start="\<module\>\s*\<type\>" matchgroup=ocamlModule end="\<\w\(\w\|'\)*\>" contains=ocamlComment skipwhite skipempty nextgroup=ocamlMTDef
420 syn match ocamlMTDef "=\s*\w\(\w\|'\)*\>"hs=s+1,me=s
421
422 syn keyword ocamlKeyword and as assert class
423 syn keyword ocamlKeyword constraint else
424-syn keyword ocamlKeyword exception external fun function
425+syn keyword ocamlKeyword exception external fun
426+
427 syn keyword ocamlKeyword in inherit initializer
428 syn keyword ocamlKeyword land lazy let match
429 syn keyword ocamlKeyword method mutable new of
430@@ -147,12 +154,20 @@
431 syn keyword ocamlKeyword try type
432 syn keyword ocamlKeyword val virtual when while with
433
434+if exists("ocaml_revised")
435+ syn keyword ocamlKeyword do value
436+ syn keyword ocamlBoolean True False
437+else
438+ syn keyword ocamlKeyword function
439+ syn keyword ocamlBoolean true false
440+ syn match ocamlKeyChar "!"
441+endif
442+
443 syn keyword ocamlType array bool char exn float format int
444 syn keyword ocamlType list option string unit
445
446-syn keyword ocamlOperator asr lor lsl lsr lxor mod not or
447+syn keyword ocamlOperator asr lor lsl lsr lxor mod not
448
449-syn keyword ocamlBoolean true false
450 syn match ocamlConstructor "(\s*)"
451 syn match ocamlConstructor "\[\s*\]"
452 syn match ocamlConstructor "\[|\s*>|]"
453@@ -175,9 +190,11 @@
454 syn match ocamlTopStop ";;"
455 syn match ocamlOperator "\^"
456 syn match ocamlOperator "::"
457-syn match ocamlOperator "<-"
458+
459+syn match ocamlOperator "&&"
460+syn match ocamlOperator "<"
461+syn match ocamlOperator ">"
462 syn match ocamlAnyVar "\<_\>"
463-syn match ocamlKeyChar "!"
464 syn match ocamlKeyChar "|[^\]]"me=e-1
465 syn match ocamlKeyChar ";"
466 syn match ocamlKeyChar "\~"
467@@ -185,6 +202,12 @@
468 syn match ocamlKeyChar "\*"
469 syn match ocamlKeyChar "="
470
471+if exists("ocaml_revised")
472+ syn match ocamlErr "<-"
473+else
474+ syn match ocamlOperator "<-"
475+endif
476+
477 syn match ocamlNumber "\<-\=\d\+\>"
478 syn match ocamlNumber "\<-\=0[x|X]\x\+\>"
479 syn match ocamlNumber "\<-\=0[o|O]\o\+\>"
480@@ -201,9 +224,17 @@
481 syn sync minlines=50
482 syn sync maxlines=500
483
484-syn sync match ocamlDoSync grouphere ocamlDo "\<do\>"
485-syn sync match ocamlDoSync groupthere ocamlDo "\<done\>"
486-syn sync match ocamlEndSync grouphere ocamlEnd "\<\(begin\|object\)\>"
487+if !exists("ocaml_revised")
488+ syn sync match ocamlDoSync grouphere ocamlDo "\<do\>"
489+ syn sync match ocamlDoSync groupthere ocamlDo "\<done\>"
490+endif
491+
492+if exists("ocaml_revised")
493+ syn sync match ocamlEndSync grouphere ocamlEnd "\<\(object\)\>"
494+else
495+ syn sync match ocamlEndSync grouphere ocamlEnd "\<\(begin\|object\)\>"
496+endif
497+
498 syn sync match ocamlEndSync groupthere ocamlEnd "\<end\>"
499 syn sync match ocamlStructSync grouphere ocamlStruct "\<struct\>"
500 syn sync match ocamlStructSync groupthere ocamlStruct "\<end\>"
501@@ -236,6 +267,8 @@
502
503 HiLink ocamlCharErr Error
504
505+ HiLink ocamlErr Error
506+
507 HiLink ocamlComment Comment
508
509 HiLink ocamlModPath Include
This page took 0.086013 seconds and 4 git commands to generate.