Skip to content

Instantly share code, notes, and snippets.

@roman
Created June 4, 2011 22:18
Show Gist options
  • Save roman/1008420 to your computer and use it in GitHub Desktop.
Save roman/1008420 to your computer and use it in GitHub Desktop.
Code to use QuickFix with GHC + Cabal
" let mapleader='\'
" When using \b on normal mode, it will compile the
" project
nmap <LEADER>b :<C-u>make<CR>
" Close the QuickFix window just with the q
au FileType qf nnoremap <buffer> q :<C-u>cclose<CR>
" After compiling, open the QuickFix window if there
" is any error
au QuickFixCmdPost make call OpenQuickFixBuffer()
" Opens/Closes the quickfix window depending
" if the error list is empty or not
function! OpenQuickFixBuffer()
let qflist = getqflist()
if empty(qflist)
cclose
else
copen
endif
endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
au FileType haskell call QuickFixHaskell()
" This will set the variables that QuickFix needs
" in order to compile, if you are on a project that
" has a cabal file, use "cabal build", otherwise
" use "ghc --make" on the current file
function! QuickFixHaskell()
let l:cabalFilePresent = filereadable(glob('*.cabal'))
if l:cabalFilePresent
setl makeprg=cabal\ build
else
let l:currentFile = expand('%')
if !exists('b:qfOutputdir')
let b:qfOutputdir = tempname()
call mkdir(b:qfOutputdir)
endif
let &l:makeprg = 'ghc --make % -outputdir ' . b:qfOutputdir
endif
" Previous format given by Martin Norbäck
"setl errorformat+=%A%f:%l:\ %m,%A%f:%l:,%C%\\s%m,%Z
" New format taken from haskellmode.vim
setl errorformat=
\%-Z\ %#,
\%W%f:%l:%c:\ Warning:\ %m,
\%E%f:%l:%c:\ %m,
\%E%>%f:%l:%c:,
\%+C\ \ %#%m,
\%W%>%f:%l:%c:,
\%+C\ \ %#%tarning:\ %m,
endfunction
@refaelsh
Copy link

Very cool! Thank you :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment