summaryrefslogtreecommitdiff
path: root/ftplugin/haskell.vim
blob: 651f033ee1baf4009902c2b57bf8d186b4047910 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function! s:OverwriteBuffer(output)
    let winview = winsaveview()
    silent! undojoin
    normal! gg"_dG
    call append(0, split(a:output, '\v\n'))
    normal! G"_dd
    call winrestview(winview)
endfunction

function! s:RunStylishHaskell()
    let output = system("stylish-haskell" . " " . bufname("%"))
    let errors = matchstr(output, '\(Language\.Haskell\.Stylish\.Parse\.parseModule:[^\x0]*\)')
    if v:shell_error != 0
        echom output
    elseif empty(errors)
        call s:OverwriteBuffer(output)
        write
    else
        echom errors
    endif
endfunction

set formatprg=stylish-haskell
set makeprg=hlint

augroup HaskellLint
    autocmd!
    autocmd BufWritePost *.hs | call s:RunStylishHaskell() | silent make! <afile> | silent redraw!
    autocmd QuickFixCmdPost [^l]* cwindow
augroup END