diff options
Diffstat (limited to 'nvim')
-rw-r--r-- | nvim/.config/nvim/ftplugin/haskell.vim | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/nvim/.config/nvim/ftplugin/haskell.vim b/nvim/.config/nvim/ftplugin/haskell.vim new file mode 100644 index 0000000..c389121 --- /dev/null +++ b/nvim/.config/nvim/ftplugin/haskell.vim | |||
@@ -0,0 +1,29 @@ | |||
1 | function! s:OverwriteBuffer(output) | ||
2 | let winview = winsaveview() | ||
3 | silent! undojoin | ||
4 | normal! gg"_dG | ||
5 | call append(0, split(a:output, '\v\n')) | ||
6 | normal! G"_dd | ||
7 | call winrestview(winview) | ||
8 | endfunction | ||
9 | |||
10 | function! s:RunStylishHaskell() | ||
11 | let output = system("stylish-haskell" . " " . bufname("%")) | ||
12 | let errors = matchstr(output, '\(Language\.Haskell\.Stylish\.Parse\.parseModule:[^\x0]*\)') | ||
13 | if v:shell_error != 0 | ||
14 | echom output | ||
15 | elseif empty(errors) | ||
16 | call s:OverwriteBuffer(output) | ||
17 | write | ||
18 | else | ||
19 | echom errors | ||
20 | endif | ||
21 | endfunction | ||
22 | |||
23 | augroup haskell-formatting | ||
24 | autocmd! | ||
25 | autocmd BufWritePost *.hs call s:RunStylishHaskell() | ||
26 | augroup END | ||
27 | |||
28 | |||
29 | set formatprg=stylish-haskell | ||