2014-02-08 05:05:16 -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.
|
|
|
|
"
|
|
|
|
"============================================================================
|
|
|
|
|
2015-07-13 06:22:46 -04:00
|
|
|
if exists('g:loaded_syntastic_ocaml_camlp4o_checker')
|
2014-02-08 05:05:16 -05:00
|
|
|
finish
|
|
|
|
endif
|
|
|
|
let g:loaded_syntastic_ocaml_camlp4o_checker = 1
|
|
|
|
|
|
|
|
let s:save_cpo = &cpo
|
|
|
|
set cpo&vim
|
|
|
|
|
2015-01-18 07:58:28 -05:00
|
|
|
" Checker options {{{1
|
2014-02-08 05:05:16 -05:00
|
|
|
|
|
|
|
if !exists('g:syntastic_ocaml_use_ocamlc') || !executable('ocamlc')
|
|
|
|
let g:syntastic_ocaml_use_ocamlc = 0
|
|
|
|
endif
|
|
|
|
|
|
|
|
if !exists('g:syntastic_ocaml_use_janestreet_core')
|
2014-09-27 11:32:18 -04:00
|
|
|
let g:syntastic_ocaml_use_janestreet_core = 0
|
2014-02-08 05:05:16 -05:00
|
|
|
endif
|
|
|
|
|
2016-05-14 07:57:54 -04:00
|
|
|
if !exists('g:syntastic_ocaml_janestreet_core_dir')
|
|
|
|
let g:syntastic_ocaml_janestreet_core_dir = '.'
|
|
|
|
endif
|
|
|
|
|
2015-07-13 06:22:46 -04:00
|
|
|
if !exists('g:syntastic_ocaml_use_ocamlbuild') || !executable('ocamlbuild')
|
2014-02-08 05:05:16 -05:00
|
|
|
let g:syntastic_ocaml_use_ocamlbuild = 0
|
|
|
|
endif
|
|
|
|
|
2015-01-18 07:58:28 -05:00
|
|
|
" }}}1
|
|
|
|
|
|
|
|
function! SyntaxCheckers_ocaml_camlp4o_IsAvailable() dict " {{{1
|
2016-05-14 07:57:54 -04:00
|
|
|
let s:ocamlpp = get(g:, 'syntastic_ocaml_camlp4r', 0) ? 'camlp4r' : 'camlp4o'
|
2015-01-18 07:58:28 -05:00
|
|
|
return executable(s:ocamlpp)
|
|
|
|
endfunction " }}}1
|
|
|
|
|
|
|
|
function! SyntaxCheckers_ocaml_camlp4o_GetLocList() dict " {{{1
|
2017-08-03 11:21:37 -04:00
|
|
|
let buf = bufnr('')
|
|
|
|
let makeprg = s:GetMakeprg(buf)
|
2015-07-13 06:22:46 -04:00
|
|
|
if makeprg ==# ''
|
2014-02-08 05:05:16 -05:00
|
|
|
return []
|
|
|
|
endif
|
|
|
|
|
|
|
|
let errorformat =
|
2015-03-14 16:02:10 -04:00
|
|
|
\ '%WWarning: File "%f"\, line %l\, chars %c-%n:,'.
|
|
|
|
\ '%WWarning: line %l\, chars %c-%n:,'.
|
|
|
|
\ '%AFile "%f"\, line %l\, characters %c-%n:,'.
|
2014-02-08 05:05:16 -05:00
|
|
|
\ '%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 %.%#,'.
|
2015-03-14 16:02:10 -04:00
|
|
|
\ '%C%tarning %*\d: %m,'.
|
2014-02-08 05:05:16 -05:00
|
|
|
\ '%C%m,'.
|
|
|
|
\ '%-G+%.%#'
|
|
|
|
|
2015-03-14 16:02:10 -04:00
|
|
|
let loclist = SyntasticMake({
|
|
|
|
\ 'makeprg': makeprg,
|
|
|
|
\ 'errorformat': errorformat,
|
2017-08-03 11:21:37 -04:00
|
|
|
\ 'defaults': {'bufnr': buf} })
|
2015-03-14 16:02:10 -04:00
|
|
|
|
|
|
|
for e in loclist
|
|
|
|
if get(e, 'col', 0) && get(e, 'nr', 0)
|
|
|
|
let e['hl'] = '\%>' . (e['col'] - 1) . 'c\%<' . (e['nr'] + 1) . 'c'
|
|
|
|
let e['nr'] = 0
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
|
|
|
return loclist
|
2015-01-18 07:58:28 -05:00
|
|
|
endfunction " }}}1
|
2014-02-08 05:05:16 -05:00
|
|
|
|
2015-01-18 07:58:28 -05:00
|
|
|
" Utilities {{{1
|
|
|
|
|
2017-08-03 11:21:37 -04:00
|
|
|
function! s:GetMakeprg(buf) " {{{2
|
2016-05-14 07:57:54 -04:00
|
|
|
return
|
|
|
|
\ g:syntastic_ocaml_use_ocamlc ? g:syntastic_ocaml_use_ocamlc :
|
2017-08-03 11:21:37 -04:00
|
|
|
\ (g:syntastic_ocaml_use_ocamlbuild && isdirectory('_build')) ? s:GetOcamlcMakeprg(a:buf) :
|
|
|
|
\ s:GetOtherMakeprg(a:buf)
|
2015-01-18 07:58:28 -05:00
|
|
|
endfunction " }}}2
|
2014-02-08 05:05:16 -05:00
|
|
|
|
2017-08-03 11:21:37 -04:00
|
|
|
function! s:GetOcamlcMakeprg(buf) " {{{2
|
2016-05-14 07:57:54 -04:00
|
|
|
let build_cmd = g:syntastic_ocaml_use_janestreet_core ?
|
|
|
|
\ 'ocamlc -I ' . syntastic#util#shexpand(g:syntastic_ocaml_janestreet_core_dir) : 'ocamlc'
|
2017-08-03 11:21:37 -04:00
|
|
|
let build_cmd .= ' -c ' . syntastic#util#shescape(bufname(a:buf))
|
2016-05-14 07:57:54 -04:00
|
|
|
return build_cmd
|
2015-01-18 07:58:28 -05:00
|
|
|
endfunction " }}}2
|
2014-02-08 05:05:16 -05:00
|
|
|
|
2017-08-03 11:21:37 -04:00
|
|
|
function! s:GetOcamlBuildMakeprg(buf) " {{{2
|
2015-07-13 06:22:46 -04:00
|
|
|
return 'ocamlbuild -quiet -no-log -tag annot,' . s:ocamlpp . ' -no-links -no-hygiene -no-sanitize ' .
|
2017-08-03 11:21:37 -04:00
|
|
|
\ syntastic#util#shexpand(fnamemodify(bufname(a:buf), ':r')) . '.cmi'
|
2015-01-18 07:58:28 -05:00
|
|
|
endfunction " }}}2
|
2014-02-08 05:05:16 -05:00
|
|
|
|
2017-08-03 11:21:37 -04:00
|
|
|
function! s:GetOtherMakeprg(buf) " {{{2
|
2014-02-08 05:05:16 -05:00
|
|
|
"TODO: give this function a better name?
|
|
|
|
"
|
|
|
|
"TODO: should use throw/catch instead of returning an empty makeprg
|
|
|
|
|
2017-08-03 11:21:37 -04:00
|
|
|
let fname = bufname(a:buf)
|
|
|
|
let extension = fnamemodify(fname, ':e')
|
2015-07-13 06:22:46 -04:00
|
|
|
let makeprg = ''
|
2014-02-08 05:05:16 -05:00
|
|
|
|
2015-07-13 06:22:46 -04:00
|
|
|
if stridx(extension, 'mly') >= 0 && executable('menhir')
|
2014-02-08 05:05:16 -05:00
|
|
|
" ocamlyacc output can't be redirected, so use menhir
|
2017-08-03 11:21:37 -04:00
|
|
|
let makeprg = 'menhir --only-preprocess ' . syntastic#util#shescape(fname) . ' >' . syntastic#util#DevNull()
|
2015-07-13 06:22:46 -04:00
|
|
|
elseif stridx(extension,'mll') >= 0 && executable('ocamllex')
|
2017-08-03 11:21:37 -04:00
|
|
|
let makeprg = 'ocamllex -q ' . syntastic#c#NullOutput() . ' ' . syntastic#util#shescape(fname)
|
2014-02-08 05:05:16 -05:00
|
|
|
else
|
2017-08-03 11:21:37 -04:00
|
|
|
let makeprg = 'camlp4o ' . syntastic#c#NullOutput() . ' ' . syntastic#util#shescape(fname)
|
2014-02-08 05:05:16 -05:00
|
|
|
endif
|
|
|
|
|
|
|
|
return makeprg
|
2015-01-18 07:58:28 -05:00
|
|
|
endfunction " }}}2
|
|
|
|
|
|
|
|
" }}}1
|
2014-02-08 05:05:16 -05:00
|
|
|
|
|
|
|
call g:SyntasticRegistry.CreateAndRegisterChecker({
|
|
|
|
\ 'filetype': 'ocaml',
|
|
|
|
\ 'name': 'camlp4o'})
|
|
|
|
|
|
|
|
let &cpo = s:save_cpo
|
|
|
|
unlet s:save_cpo
|
|
|
|
|
2015-01-18 07:58:28 -05:00
|
|
|
" vim: set sw=4 sts=4 et fdm=marker:
|