]> git.r.bdr.sh - rbdr/dotfiles/blame_incremental - vim/syntax_checkers/ocaml.vim
Update the stuff
[rbdr/dotfiles] / vim / syntax_checkers / ocaml.vim
... / ...
CommitLineData
1"============================================================================
2"File: ocaml.vim
3"Description: Syntax checking plugin for syntastic.vim
4"Maintainer: Török Edwin <edwintorok at gmail dot com>
5"License: This program is free software. It comes without any warranty,
6" to the extent permitted by applicable law. You can redistribute
7" it and/or modify it under the terms of the Do What The Fuck You
8" Want To Public License, Version 2, as published by Sam Hocevar.
9" See http://sam.zoy.org/wtfpl/COPYING for more details.
10"
11"============================================================================
12"
13" By default the camlp4o preprocessor is used to check the syntax of .ml, and .mli files,
14" ocamllex is used to check .mll files and menhir is used to check .mly files.
15" The output is all redirected to /dev/null, nothing is written to the disk.
16"
17" If your source code needs camlp4r then you can define this in your .vimrc:
18"
19" let g:syntastic_ocaml_camlp4r = 1
20"
21" If you used some syntax extensions, or you want to also typecheck the source
22" code, then you can define this:
23"
24" let g:syntastic_ocaml_use_ocamlbuild = 1
25"
26" This will run ocamlbuild <name>.inferred.mli, so it will write to your _build
27" directory (and possibly rebuild your myocamlbuild.ml plugin), only enable this
28" if you are ok with that.
29"
30" If you are using syntax extensions / external libraries and have a properly
31" set up _tags (and myocamlbuild.ml file) then it should just work
32" to enable this flag and get syntax / type checks through syntastic.
33"
34" For best results your current directory should be the project root
35" (same situation if you want useful output from :make).
36
37if exists("loaded_ocaml_syntax_checker")
38 finish
39endif
40let loaded_ocaml_syntax_checker = 1
41
42if exists('g:syntastic_ocaml_camlp4r') &&
43 \ g:syntastic_ocaml_camlp4r != 0
44 let s:ocamlpp="camlp4r"
45else
46 let s:ocamlpp="camlp4o"
47endif
48
49"bail if the user doesnt have the preprocessor
50if !executable(s:ocamlpp)
51 finish
52endif
53
54function! SyntaxCheckers_ocaml_GetLocList()
55 if exists('g:syntastic_ocaml_use_ocamlbuild') &&
56 \ g:syntastic_ocaml_use_ocamlbuild != 0 &&
57 \ executable("ocamlbuild") &&
58 \ isdirectory('_build')
59 let makeprg = "ocamlbuild -quiet -no-log -tag annot,". s:ocamlpp. " -no-links -no-hygiene -no-sanitize ".
60 \ shellescape(expand('%:r')).".cmi"
61 else
62 let extension = expand('%:e')
63 if match(extension, 'mly') >= 0
64 " ocamlyacc output can't be redirected, so use menhir
65 if !executable("menhir")
66 return []
67 endif
68 let makeprg = "menhir --only-preprocess ".shellescape(expand('%')) . " >/dev/null"
69 elseif match(extension,'mll') >= 0
70 if !executable("ocamllex")
71 return []
72 endif
73 let makeprg = "ocamllex -q -o /dev/null ".shellescape(expand('%'))
74 else
75 let makeprg = "camlp4o -o /dev/null ".shellescape(expand('%'))
76 endif
77 endif
78 let errorformat = '%AFile "%f"\, line %l\, characters %c-%*\d:,'.
79 \ '%AFile "%f"\, line %l\, characters %c-%*\d (end at line %*\d\, character %*\d):,'.
80 \ '%AFile "%f"\, line %l\, character %c:,'.
81 \ '%AFile "%f"\, line %l\, character %c:%m,'.
82 \ '%-GPreprocessing error %.%#,'.
83 \ '%-GCommand exited %.%#,'.
84 \ '%C%tarning %n: %m,'.
85 \ '%C%m,'.
86 \ '%-G+%.%#'
87
88 return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat })
89endfunction