vimmode cabal "integration"

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
function! SetToCabalBuild()
  if glob("*.cabal") != ''
    let a = system( 'grep "/\* package .* \*/"  dist/build/autogen/cabal_macros.h' )
    let b = system( 'sed -e "s/\/\* /-/" -e "s/\*\///"', a )
    let pkgs = "-hide-all-packages " .  system( 'xargs echo -n', b )
    let hs = "import Distribution.Dev.Interactive\n"
    let hs .= "import Data.List\n"
    let hs .= 'main = withOpts [""] error return >>= putStr . intercalate " "'
    let opts = system( 'runhaskell', hs )
    let b:ghc_staticoptions = opts . ' ' . pkgs
  else
    let b:ghc_staticoptions = '-Wall -fno-warn-name-shadowing'
  endif
  execute 'setlocal makeprg=' . g:ghc . '\ ' . escape(b:ghc_staticoptions,' ') .'\ -e\ :q\ %'
  let b:my_changedtick -=1
endfunction

autocmd BufEnter *.hs,*.lhs :call SetToCabalBuild()