From 7df01d85669decb75cc7d2aac5815aa41015e0ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=B6r=C3=B6k=20Edwin?= Date: Fri, 13 Jan 2012 15:48:25 +0200 Subject: [PATCH 1/4] Add ocamlbuild support Enabled with 'let g:syntastic_ocaml_use_ocamlbuild = 1' in .vimrc, also creates .annot files for t. Not enabled by default because it writes to disk (_build dir). --- syntax_checkers/ocaml.vim | 72 ++++++++++++++++++++++++++++++--------- 1 file changed, 56 insertions(+), 16 deletions(-) diff --git a/syntax_checkers/ocaml.vim b/syntax_checkers/ocaml.vim index 0ebe30cb..d405e8eb 100644 --- a/syntax_checkers/ocaml.vim +++ b/syntax_checkers/ocaml.vim @@ -9,37 +9,77 @@ " See http://sam.zoy.org/wtfpl/COPYING for more details. " "============================================================================ +" +" 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 .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("loaded_ocaml_syntax_checker") finish endif let loaded_ocaml_syntax_checker = 1 -"bail if the user doesnt have camlp4o installed -if !executable("camlp4o") +if exists('g:syntastic_ocaml_camlp4r') && + \ g:syntastic_ocaml_camlp4r != 0 + let s:ocamlpp="camlp4r" +else + let s:ocamlpp="camlp4o" +endif + +"bail if the user doesnt have the preprocessor +if !executable(s:ocamlpp) finish endif function! SyntaxCheckers_ocaml_GetLocList() - let extension = expand('%:e') - if match(extension, 'mly') >= 0 - " ocamlyacc output can't be redirected, so use menhir - if !executable("menhir") - return [] - endif - let makeprg = "menhir --only-preprocess ".shellescape(expand('%')) . " >/dev/null" - elseif match(extension,'mll') >= 0 - if !executable("ocamllex") - return [] - endif - let makeprg = "ocamllex -q -o /dev/null ".shellescape(expand('%')) + if exists('g:syntastic_ocaml_use_ocamlbuild') && + \ g:syntastic_ocaml_use_ocamlbuild != 0 && + \ executable("ocamlbuild") + let makeprg = "ocamlbuild -quiet -no-log -tag annot,". s:ocamlpp. " -no-links -no-hygiene -no-sanitize ". + \ shellescape(expand('%:r')).".cmi" else - let makeprg = "camlp4o -o /dev/null ".shellescape(expand('%')) + let extension = expand('%:e') + if match(extension, 'mly') >= 0 + " ocamlyacc output can't be redirected, so use menhir + if !executable("menhir") + return [] + endif + let makeprg = "menhir --only-preprocess ".shellescape(expand('%')) . " >/dev/null" + elseif match(extension,'mll') >= 0 + if !executable("ocamllex") + return [] + endif + let makeprg = "ocamllex -q -o /dev/null ".shellescape(expand('%')) + else + let makeprg = "camlp4o -o /dev/null ".shellescape(expand('%')) + endif endif let errorformat = '%EFile "%f"\, line %l\, characters %c-%*\d:,'. \ '%EFile "%f"\, line %l\, characters %c-%*\d (end at line %*\d\, character %*\d):,'. \ '%EFile "%f"\, line %l\, character %c:,'. \ '%EFile "%f"\, line %l\, character %c:%m,'. - \ '%C%m' + \ '%C%m,'. + \ '%-G+%.%#' return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) endfunction From cb1d8c12ce3063b47cc7fe2da672c1a996f2bf2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=B6r=C3=B6k=20Edwin?= Date: Mon, 16 Jan 2012 16:27:21 +0200 Subject: [PATCH 2/4] ocaml syntax: handle warnings and ignore some ocamlbuild messages --- syntax_checkers/ocaml.vim | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/syntax_checkers/ocaml.vim b/syntax_checkers/ocaml.vim index d405e8eb..1fe1557c 100644 --- a/syntax_checkers/ocaml.vim +++ b/syntax_checkers/ocaml.vim @@ -74,10 +74,13 @@ function! SyntaxCheckers_ocaml_GetLocList() let makeprg = "camlp4o -o /dev/null ".shellescape(expand('%')) endif endif - let errorformat = '%EFile "%f"\, line %l\, characters %c-%*\d:,'. - \ '%EFile "%f"\, line %l\, characters %c-%*\d (end at line %*\d\, character %*\d):,'. - \ '%EFile "%f"\, line %l\, character %c:,'. - \ '%EFile "%f"\, line %l\, character %c:%m,'. + 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+%.%#' From c7380d7ab46d6d4d3211b8bd6a2292cb54bc1315 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=B6r=C3=B6k=20Edwin?= Date: Mon, 16 Jan 2012 16:27:35 +0200 Subject: [PATCH 3/4] drop locaml syntax there is no such syntax, copy+pasto error. --- syntax_checkers/locaml.vim | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 syntax_checkers/locaml.vim diff --git a/syntax_checkers/locaml.vim b/syntax_checkers/locaml.vim deleted file mode 100644 index 02b1280e..00000000 --- a/syntax_checkers/locaml.vim +++ /dev/null @@ -1,26 +0,0 @@ -"============================================================================ -"File: locaml.vim -"Description: Syntax checking plugin for syntastic.vim -"Maintainer: Török Edwin -"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. -" -"============================================================================ -if exists("loaded_locaml_syntax_checker") - finish -endif -let loaded_locaml_syntax_checker = 1 - -"bail if the user doesnt have camlp4o installed -if !executable("camlp4o") - finish -endif - -runtime syntax_checkers/ocaml.vim - -function! SyntaxCheckers_locaml_GetLocList() - return SyntaxCheckers_ocaml_GetLocList() -endfunction From 331e821a0192412b9b841f4eb57636f10da9bca6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=B6r=C3=B6k=20Edwin?= Date: Mon, 16 Jan 2012 16:42:01 +0200 Subject: [PATCH 4/4] ocaml: only run ocamlbuild if _build already exists --- syntax_checkers/ocaml.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/syntax_checkers/ocaml.vim b/syntax_checkers/ocaml.vim index 1fe1557c..6a2470f4 100644 --- a/syntax_checkers/ocaml.vim +++ b/syntax_checkers/ocaml.vim @@ -54,7 +54,8 @@ endif function! SyntaxCheckers_ocaml_GetLocList() if exists('g:syntastic_ocaml_use_ocamlbuild') && \ g:syntastic_ocaml_use_ocamlbuild != 0 && - \ executable("ocamlbuild") + \ executable("ocamlbuild") && + \ isdirectory('_build') let makeprg = "ocamlbuild -quiet -no-log -tag annot,". s:ocamlpp. " -no-links -no-hygiene -no-sanitize ". \ shellescape(expand('%:r')).".cmi" else