2012-10-29 17:22:28 -04:00
|
|
|
"============================================================================
|
|
|
|
"File: ghc-mod.vim
|
|
|
|
"Description: Syntax checking plugin for syntastic.vim
|
|
|
|
"Maintainer: Anthony Carapetis <anthony.carapetis 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.
|
|
|
|
"
|
|
|
|
"============================================================================
|
|
|
|
|
2013-08-12 15:46:20 -04:00
|
|
|
if exists('g:loaded_syntastic_haskell_ghc_mod_checker')
|
2013-02-21 10:50:41 -05:00
|
|
|
finish
|
|
|
|
endif
|
2013-08-12 15:46:20 -04:00
|
|
|
let g:loaded_syntastic_haskell_ghc_mod_checker = 1
|
2013-02-21 10:50:41 -05:00
|
|
|
|
2013-11-05 13:28:19 -05:00
|
|
|
let s:ghc_mod_new = -1
|
|
|
|
|
2014-01-03 04:29:08 -05:00
|
|
|
let s:save_cpo = &cpo
|
|
|
|
set cpo&vim
|
|
|
|
|
2013-11-05 13:34:54 -05:00
|
|
|
function! SyntaxCheckers_haskell_ghc_mod_IsAvailable() dict
|
2014-10-06 15:15:44 -04:00
|
|
|
if !executable(self.getExec())
|
|
|
|
return 0
|
|
|
|
endif
|
|
|
|
|
2014-10-09 02:06:54 -04:00
|
|
|
" ghc-mod 5.0.0 and later needs the "version" command to print the
|
|
|
|
" version. But the "version" command appeared in 4.1.0. Thus, we need to
|
|
|
|
" know the version in order to know how to find out the version. :)
|
|
|
|
|
|
|
|
" Try "ghc-mod version".
|
2014-11-03 13:40:44 -05:00
|
|
|
let ver = filter(split(system(self.getExecEscaped() . ' version'), '\n'), 'v:val =~# ''\m\sversion''')
|
2014-10-09 02:06:54 -04:00
|
|
|
if !len(ver)
|
|
|
|
" That didn't work. Try "ghc-mod" alone.
|
2014-11-03 13:40:44 -05:00
|
|
|
let ver = filter(split(system(self.getExecEscaped()), '\n'), 'v:val =~# ''\m\sversion''')
|
2014-10-09 02:06:54 -04:00
|
|
|
endif
|
|
|
|
|
|
|
|
if len(ver)
|
|
|
|
" Encouraged by the great success in finding out the version, now we
|
|
|
|
" need either a Vim that can handle NULs in system() output, or a
|
|
|
|
" ghc-mod that has the "--boundary" option.
|
|
|
|
let parsed_ver = syntastic#util#parseVersion(ver[0])
|
2014-10-06 15:15:44 -04:00
|
|
|
call self.log(self.getExec() . ' version =', parsed_ver)
|
|
|
|
let s:ghc_mod_new = syntastic#util#versionIsAtLeast(parsed_ver, [2, 1, 2])
|
2014-10-09 02:06:54 -04:00
|
|
|
else
|
2014-10-06 15:15:44 -04:00
|
|
|
call syntastic#log#error("checker haskell/ghc_mod: can't parse version string (abnormal termination?)")
|
|
|
|
let s:ghc_mod_new = -1
|
2014-10-09 02:06:54 -04:00
|
|
|
endif
|
2014-10-06 15:15:44 -04:00
|
|
|
|
2013-11-05 13:28:19 -05:00
|
|
|
return (s:ghc_mod_new >= 0) && (v:version >= 704 || s:ghc_mod_new)
|
2013-01-27 15:08:30 -05:00
|
|
|
endfunction
|
|
|
|
|
2013-10-28 07:53:33 -04:00
|
|
|
function! SyntaxCheckers_haskell_ghc_mod_GetLocList() dict
|
2013-11-05 13:34:54 -05:00
|
|
|
let makeprg = self.makeprgBuild({
|
2014-02-07 04:19:30 -05:00
|
|
|
\ 'exe': self.getExecEscaped() . ' check' . (s:ghc_mod_new ? ' --boundary=""' : '') })
|
2013-08-12 15:46:20 -04:00
|
|
|
|
2013-04-25 15:40:03 -04:00
|
|
|
let errorformat =
|
|
|
|
\ '%-G%\s%#,' .
|
|
|
|
\ '%f:%l:%c:%trror: %m,' .
|
|
|
|
\ '%f:%l:%c:%tarning: %m,'.
|
|
|
|
\ '%f:%l:%c: %trror: %m,' .
|
|
|
|
\ '%f:%l:%c: %tarning: %m,' .
|
|
|
|
\ '%f:%l:%c:%m,' .
|
|
|
|
\ '%E%f:%l:%c:,' .
|
|
|
|
\ '%Z%m'
|
|
|
|
|
2013-08-12 15:46:20 -04:00
|
|
|
return SyntasticMake({
|
2013-05-31 14:05:45 -04:00
|
|
|
\ 'makeprg': makeprg,
|
2013-08-12 15:46:20 -04:00
|
|
|
\ 'errorformat': errorformat,
|
2013-12-04 16:58:57 -05:00
|
|
|
\ 'postprocess': ['compressWhitespace'],
|
|
|
|
\ 'returns': [0] })
|
2012-10-29 17:22:28 -04:00
|
|
|
endfunction
|
|
|
|
|
2013-01-27 15:08:30 -05:00
|
|
|
call g:SyntasticRegistry.CreateAndRegisterChecker({
|
|
|
|
\ 'filetype': 'haskell',
|
2013-10-28 11:30:25 -04:00
|
|
|
\ 'name': 'ghc_mod',
|
2014-01-03 04:29:08 -05:00
|
|
|
\ 'exec': 'ghc-mod' })
|
|
|
|
|
|
|
|
let &cpo = s:save_cpo
|
|
|
|
unlet s:save_cpo
|
|
|
|
|
2015-01-04 05:46:54 -05:00
|
|
|
" vim: set sw=4 sts=4 et fdm=marker:
|