2012-01-13 07:00:53 -05:00
|
|
|
"============================================================================
|
|
|
|
"File: ocaml.vim
|
|
|
|
"Description: Syntax checking plugin for syntastic.vim
|
|
|
|
"Maintainer: Török Edwin <edwintorok at gmail dot com>
|
|
|
|
"License: This program is free software. It comes without any warranty,
|
|
|
|
" to the extent permitted by applicable law. You can redistribute
|
|
|
|
" it and/or modify it under the terms of the Do What The Fuck You
|
|
|
|
" Want To Public License, Version 2, as published by Sam Hocevar.
|
|
|
|
" See http://sam.zoy.org/wtfpl/COPYING for more details.
|
|
|
|
"
|
|
|
|
"============================================================================
|
2012-01-13 08:48:25 -05:00
|
|
|
"
|
2012-08-23 12:13:30 -04:00
|
|
|
" The more reliable way to check for a single .ml file is to use ocamlc.
|
|
|
|
" You can do that setting this in your .vimrc:
|
|
|
|
"
|
|
|
|
" let g:syntastic_ocaml_use_ocamlc = 1
|
|
|
|
" It's possible to use ocamlc in conjuction with Jane Street's Core. In order
|
|
|
|
" to do that, you have to specify this in your .vimrc:
|
|
|
|
"
|
|
|
|
" let g:syntastic_ocaml_use_janestreet_core = 1
|
|
|
|
" let g:syntastic_ocaml_janestreet_core_dir = <path>
|
|
|
|
"
|
|
|
|
" Where path is the path to your core installation (usually a collection of
|
|
|
|
" .cmx and .cmxa files).
|
|
|
|
"
|
|
|
|
"
|
2012-01-13 08:48:25 -05:00
|
|
|
" By default the camlp4o preprocessor is used to check the syntax of .ml, and .mli files,
|
|
|
|
" ocamllex is used to check .mll files and menhir is used to check .mly files.
|
|
|
|
" The output is all redirected to /dev/null, nothing is written to the disk.
|
|
|
|
"
|
|
|
|
" If your source code needs camlp4r then you can define this in your .vimrc:
|
|
|
|
"
|
|
|
|
" let g:syntastic_ocaml_camlp4r = 1
|
|
|
|
"
|
|
|
|
" If you used some syntax extensions, or you want to also typecheck the source
|
|
|
|
" code, then you can define this:
|
|
|
|
"
|
|
|
|
" let g:syntastic_ocaml_use_ocamlbuild = 1
|
|
|
|
"
|
|
|
|
" This will run ocamlbuild <name>.inferred.mli, so it will write to your _build
|
|
|
|
" directory (and possibly rebuild your myocamlbuild.ml plugin), only enable this
|
|
|
|
" if you are ok with that.
|
|
|
|
"
|
|
|
|
" If you are using syntax extensions / external libraries and have a properly
|
|
|
|
" set up _tags (and myocamlbuild.ml file) then it should just work
|
|
|
|
" to enable this flag and get syntax / type checks through syntastic.
|
|
|
|
"
|
|
|
|
" For best results your current directory should be the project root
|
|
|
|
" (same situation if you want useful output from :make).
|
|
|
|
|
2013-02-21 10:50:41 -05:00
|
|
|
if exists("g:loaded_syntastic_ocaml_camlp4o_checker")
|
|
|
|
finish
|
|
|
|
endif
|
2014-01-03 04:29:08 -05:00
|
|
|
let g:loaded_syntastic_ocaml_camlp4o_checker = 1
|
2013-02-21 10:50:41 -05:00
|
|
|
|
2013-10-28 11:30:25 -04:00
|
|
|
if exists('g:syntastic_ocaml_camlp4r') && g:syntastic_ocaml_camlp4r != 0
|
2012-01-13 08:48:25 -05:00
|
|
|
let s:ocamlpp="camlp4r"
|
|
|
|
else
|
|
|
|
let s:ocamlpp="camlp4o"
|
|
|
|
endif
|
|
|
|
|
2014-01-03 04:29:08 -05:00
|
|
|
let s:save_cpo = &cpo
|
|
|
|
set cpo&vim
|
|
|
|
|
2013-10-28 11:30:25 -04:00
|
|
|
function! SyntaxCheckers_ocaml_camlp4o_IsAvailable() dict
|
2013-01-27 15:08:30 -05:00
|
|
|
return executable(s:ocamlpp)
|
|
|
|
endfunction
|
2012-01-13 07:00:53 -05:00
|
|
|
|
2012-08-31 16:18:57 -04:00
|
|
|
if !exists('g:syntastic_ocaml_use_ocamlc') || !executable('ocamlc')
|
|
|
|
let g:syntastic_ocaml_use_ocamlc = 0
|
|
|
|
endif
|
|
|
|
|
2012-09-02 14:18:58 -04:00
|
|
|
if !exists('g:syntastic_ocaml_use_janestreet_core')
|
2012-08-31 16:18:57 -04:00
|
|
|
let g:syntastic_ocaml_use_ocamlc = 0
|
|
|
|
endif
|
|
|
|
|
|
|
|
if !exists('g:syntastic_ocaml_use_ocamlbuild') || !executable("ocamlbuild")
|
|
|
|
let g:syntastic_ocaml_use_ocamlbuild = 0
|
|
|
|
endif
|
|
|
|
|
2013-10-28 07:53:33 -04:00
|
|
|
function! SyntaxCheckers_ocaml_camlp4o_GetLocList() dict
|
2012-08-31 16:18:57 -04:00
|
|
|
let makeprg = s:GetMakeprg()
|
|
|
|
if makeprg == ""
|
|
|
|
return []
|
2012-01-13 07:00:53 -05:00
|
|
|
endif
|
2012-08-31 16:18:57 -04:00
|
|
|
|
2013-05-14 12:36:20 -04:00
|
|
|
let errorformat =
|
|
|
|
\ '%AFile "%f"\, line %l\, characters %c-%*\d:,'.
|
|
|
|
\ '%AFile "%f"\, line %l\, characters %c-%*\d (end at line %*\d\, character %*\d):,'.
|
|
|
|
\ '%AFile "%f"\, line %l\, character %c:,'.
|
|
|
|
\ '%AFile "%f"\, line %l\, character %c:%m,'.
|
|
|
|
\ '%-GPreprocessing error %.%#,'.
|
|
|
|
\ '%-GCommand exited %.%#,'.
|
|
|
|
\ '%C%tarning %n: %m,'.
|
|
|
|
\ '%C%m,'.
|
|
|
|
\ '%-G+%.%#'
|
2012-01-13 07:00:53 -05:00
|
|
|
|
|
|
|
return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat })
|
|
|
|
endfunction
|
2012-08-31 16:18:57 -04:00
|
|
|
|
2013-11-01 05:51:04 -04:00
|
|
|
function! s:GetMakeprg()
|
2012-08-31 16:18:57 -04:00
|
|
|
if g:syntastic_ocaml_use_ocamlc
|
|
|
|
return s:GetOcamlcMakeprg()
|
|
|
|
endif
|
|
|
|
|
|
|
|
if g:syntastic_ocaml_use_ocamlbuild && isdirectory('_build')
|
|
|
|
return s:GetOcamlBuildMakeprg()
|
|
|
|
endif
|
|
|
|
|
|
|
|
return s:GetOtherMakeprg()
|
|
|
|
endfunction
|
|
|
|
|
2013-11-01 05:51:04 -04:00
|
|
|
function! s:GetOcamlcMakeprg()
|
2012-08-31 16:18:57 -04:00
|
|
|
if g:syntastic_ocaml_use_janestreet_core
|
2012-09-02 14:20:12 -04:00
|
|
|
let build_cmd = "ocamlc -I "
|
|
|
|
let build_cmd .= expand(g:syntastic_ocaml_janestreet_core_dir)
|
2013-07-10 04:20:54 -04:00
|
|
|
let build_cmd .= " -c " . syntastic#util#shexpand('%')
|
2012-09-02 14:20:12 -04:00
|
|
|
return build_cmd
|
2012-08-31 16:18:57 -04:00
|
|
|
else
|
2013-07-10 04:20:54 -04:00
|
|
|
return "ocamlc -c " . syntastic#util#shexpand('%')
|
2012-08-31 16:18:57 -04:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2013-11-01 05:51:04 -04:00
|
|
|
function! s:GetOcamlBuildMakeprg()
|
2013-06-07 14:18:29 -04:00
|
|
|
return "ocamlbuild -quiet -no-log -tag annot," . s:ocamlpp . " -no-links -no-hygiene -no-sanitize " .
|
2013-07-04 14:30:52 -04:00
|
|
|
\ syntastic#util#shexpand('%:r') . ".cmi"
|
2012-08-31 16:18:57 -04:00
|
|
|
endfunction
|
|
|
|
|
2013-11-01 05:51:04 -04:00
|
|
|
function! s:GetOtherMakeprg()
|
2012-08-31 16:18:57 -04:00
|
|
|
"TODO: give this function a better name?
|
|
|
|
"
|
|
|
|
"TODO: should use throw/catch instead of returning an empty makeprg
|
|
|
|
|
|
|
|
let extension = expand('%:e')
|
|
|
|
let makeprg = ""
|
|
|
|
|
2013-11-26 16:19:01 -05:00
|
|
|
if stridx(extension, 'mly') >= 0 && executable("menhir")
|
2012-08-31 16:18:57 -04:00
|
|
|
" ocamlyacc output can't be redirected, so use menhir
|
2013-07-04 14:30:52 -04:00
|
|
|
let makeprg = "menhir --only-preprocess " . syntastic#util#shexpand('%') . " >" . syntastic#util#DevNull()
|
2013-11-26 16:19:01 -05:00
|
|
|
elseif stridx(extension,'mll') >= 0 && executable("ocamllex")
|
2013-07-04 14:30:52 -04:00
|
|
|
let makeprg = "ocamllex -q " . syntastic#c#NullOutput() . " " . syntastic#util#shexpand('%')
|
2012-08-31 16:18:57 -04:00
|
|
|
else
|
2013-07-04 14:30:52 -04:00
|
|
|
let makeprg = "camlp4o " . syntastic#c#NullOutput() . " " . syntastic#util#shexpand('%')
|
2012-08-31 16:18:57 -04:00
|
|
|
endif
|
|
|
|
|
|
|
|
return makeprg
|
|
|
|
endfunction
|
2013-01-27 15:08:30 -05:00
|
|
|
|
|
|
|
call g:SyntasticRegistry.CreateAndRegisterChecker({
|
|
|
|
\ 'filetype': 'ocaml',
|
|
|
|
\ 'name': 'camlp4o'})
|
2014-01-03 04:29:08 -05:00
|
|
|
|
|
|
|
let &cpo = s:save_cpo
|
|
|
|
unlet s:save_cpo
|
|
|
|
|
|
|
|
" vim: set et sts=4 sw=4:
|