1
0
mirror of https://github.com/amix/vimrc synced 2025-07-21 03:44:59 +08:00
This commit is contained in:
huangqundl
2017-03-17 23:12:53 +08:00
parent 47b213d974
commit cba39b7326
855 changed files with 59981 additions and 35298 deletions

View File

@ -9,62 +9,16 @@
" See http://sam.zoy.org/wtfpl/COPYING for more details.
"
"============================================================================
"
" 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).
"
"
" 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).
if exists("g:loaded_syntastic_ocaml_camlp4o_checker")
if exists('g:loaded_syntastic_ocaml_camlp4o_checker')
finish
endif
let g:loaded_syntastic_ocaml_camlp4o_checker = 1
if exists('g:syntastic_ocaml_camlp4r') && g:syntastic_ocaml_camlp4r != 0
let s:ocamlpp="camlp4r"
else
let s:ocamlpp="camlp4o"
endif
let s:save_cpo = &cpo
set cpo&vim
function! SyntaxCheckers_ocaml_camlp4o_IsAvailable() dict
return executable(s:ocamlpp)
endfunction
" Checker options {{{1
if !exists('g:syntastic_ocaml_use_ocamlc') || !executable('ocamlc')
let g:syntastic_ocaml_use_ocamlc = 0
@ -74,77 +28,99 @@ if !exists('g:syntastic_ocaml_use_janestreet_core')
let g:syntastic_ocaml_use_janestreet_core = 0
endif
if !exists('g:syntastic_ocaml_use_ocamlbuild') || !executable("ocamlbuild")
if !exists('g:syntastic_ocaml_janestreet_core_dir')
let g:syntastic_ocaml_janestreet_core_dir = '.'
endif
if !exists('g:syntastic_ocaml_use_ocamlbuild') || !executable('ocamlbuild')
let g:syntastic_ocaml_use_ocamlbuild = 0
endif
function! SyntaxCheckers_ocaml_camlp4o_GetLocList() dict
let makeprg = s:GetMakeprg()
if makeprg == ""
" }}}1
function! SyntaxCheckers_ocaml_camlp4o_IsAvailable() dict " {{{1
let s:ocamlpp = get(g:, 'syntastic_ocaml_camlp4r', 0) ? 'camlp4r' : 'camlp4o'
return executable(s:ocamlpp)
endfunction " }}}1
function! SyntaxCheckers_ocaml_camlp4o_GetLocList() dict " {{{1
let buf = bufnr('')
let makeprg = s:GetMakeprg(buf)
if makeprg ==# ''
return []
endif
let errorformat =
\ '%AFile "%f"\, line %l\, characters %c-%*\d:,'.
\ '%WWarning: File "%f"\, line %l\, chars %c-%n:,'.
\ '%WWarning: line %l\, chars %c-%n:,'.
\ '%AFile "%f"\, line %l\, characters %c-%n:,'.
\ '%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%tarning %*\d: %m,'.
\ '%C%m,'.
\ '%-G+%.%#'
return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat })
endfunction
let loclist = SyntasticMake({
\ 'makeprg': makeprg,
\ 'errorformat': errorformat,
\ 'defaults': {'bufnr': buf} })
function! s:GetMakeprg()
if g:syntastic_ocaml_use_ocamlc
return s:GetOcamlcMakeprg()
endif
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
if g:syntastic_ocaml_use_ocamlbuild && isdirectory('_build')
return s:GetOcamlBuildMakeprg()
endif
return loclist
endfunction " }}}1
return s:GetOtherMakeprg()
endfunction
" Utilities {{{1
function! s:GetOcamlcMakeprg()
if g:syntastic_ocaml_use_janestreet_core
let build_cmd = "ocamlc -I "
let build_cmd .= expand(g:syntastic_ocaml_janestreet_core_dir)
let build_cmd .= " -c " . syntastic#util#shexpand('%')
return build_cmd
else
return "ocamlc -c " . syntastic#util#shexpand('%')
endif
endfunction
function! s:GetMakeprg(buf) " {{{2
return
\ g:syntastic_ocaml_use_ocamlc ? g:syntastic_ocaml_use_ocamlc :
\ (g:syntastic_ocaml_use_ocamlbuild && isdirectory('_build')) ? s:GetOcamlcMakeprg(a:buf) :
\ s:GetOtherMakeprg(a:buf)
endfunction " }}}2
function! s:GetOcamlBuildMakeprg()
return "ocamlbuild -quiet -no-log -tag annot," . s:ocamlpp . " -no-links -no-hygiene -no-sanitize " .
\ syntastic#util#shexpand('%:r') . ".cmi"
endfunction
function! s:GetOcamlcMakeprg(buf) " {{{2
let build_cmd = g:syntastic_ocaml_use_janestreet_core ?
\ 'ocamlc -I ' . syntastic#util#shexpand(g:syntastic_ocaml_janestreet_core_dir) : 'ocamlc'
let build_cmd .= ' -c ' . syntastic#util#shescape(bufname(a:buf))
return build_cmd
endfunction " }}}2
function! s:GetOtherMakeprg()
function! s:GetOcamlBuildMakeprg(buf) " {{{2
return 'ocamlbuild -quiet -no-log -tag annot,' . s:ocamlpp . ' -no-links -no-hygiene -no-sanitize ' .
\ syntastic#util#shexpand(fnamemodify(bufname(a:buf), ':r')) . '.cmi'
endfunction " }}}2
function! s:GetOtherMakeprg(buf) " {{{2
"TODO: give this function a better name?
"
"TODO: should use throw/catch instead of returning an empty makeprg
let extension = expand('%:e')
let makeprg = ""
let fname = bufname(a:buf)
let extension = fnamemodify(fname, ':e')
let makeprg = ''
if stridx(extension, 'mly') >= 0 && executable("menhir")
if stridx(extension, 'mly') >= 0 && executable('menhir')
" ocamlyacc output can't be redirected, so use menhir
let makeprg = "menhir --only-preprocess " . syntastic#util#shexpand('%') . " >" . syntastic#util#DevNull()
elseif stridx(extension,'mll') >= 0 && executable("ocamllex")
let makeprg = "ocamllex -q " . syntastic#c#NullOutput() . " " . syntastic#util#shexpand('%')
let makeprg = 'menhir --only-preprocess ' . syntastic#util#shescape(fname) . ' >' . syntastic#util#DevNull()
elseif stridx(extension,'mll') >= 0 && executable('ocamllex')
let makeprg = 'ocamllex -q ' . syntastic#c#NullOutput() . ' ' . syntastic#util#shescape(fname)
else
let makeprg = "camlp4o " . syntastic#c#NullOutput() . " " . syntastic#util#shexpand('%')
let makeprg = 'camlp4o ' . syntastic#c#NullOutput() . ' ' . syntastic#util#shescape(fname)
endif
return makeprg
endfunction
endfunction " }}}2
" }}}1
call g:SyntasticRegistry.CreateAndRegisterChecker({
\ 'filetype': 'ocaml',
@ -153,4 +129,4 @@ call g:SyntasticRegistry.CreateAndRegisterChecker({
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: set et sts=4 sw=4:
" vim: set sw=4 sts=4 et fdm=marker: