Hobby-hacking Eric

2009-07-29

vim and building with cabal

I don't know about you, but I've got map ,m :make<Enter> in my .vimrc to bind comma-m to my build program. This could be "ant" for Java files (for example) and "make" otherwise.

Now here is a snippet to set it to "cabal build" as needed
"-----------------------8<--------------------------
function! SetToCabalBuild()
if glob("*.cabal") != ''
set makeprg=cabal\ build
endif
endfunction

autocmd BufEnter *.hs,*.lhs :call SetToCabalBuild()
"-----------------------8<--------------------------
Apologies for making noise in case this is already redundant with a piece of Claus Reinke's very interesting and modular-looking Haskell mode for Vim (which I've been promising myself to install some day). Perhaps the above will be useful anyway for those of us still limping along with configuration files cobbled together from bits and bobs on the web.


3 comments:

Anonymous said...

Go install Claus' vim plugin, and then never look back. It doesn't use cabal build, but ghc directly, which means it even works for small throwaway scripts without .cabal faffing...plus it gives you (for files that typecheck) local type completions, decent omni-complete, and lots of other goodies.

C said...

I couldn't second the recommendation of Claus' vim plugin enough---I've been using for months now and love it.

kowey said...

Alright, you've motivated me! I didn't realise that it was as easy as (1) download vimball (2) vim the vimball.

Next I need to watch the screencasts to figure out how to make use of all these goodies.