aboutsummaryrefslogtreecommitdiff
path: root/nvim/.config/nvim/ftplugin/haskell.vim
blob: 5bcdd4c7fa47e0d382842306845288fb8d1fb72e (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 | silent make! <afile> | silent redraw!
    autocmd QuickFixCmdPost [^l]* cwindow
augroup END