blob: c38912133da248db800c2cb6a91a2acf67a8bdc8 (
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
|
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
augroup haskell-formatting
autocmd!
autocmd BufWritePost *.hs call s:RunStylishHaskell()
augroup END
set formatprg=stylish-haskell
|