diff options
author | Akshay <[email protected]> | 2020-08-05 15:48:22 +0100 |
---|---|---|
committer | Akshay <[email protected]> | 2020-08-05 15:48:22 +0100 |
commit | 9f4180abeab0067ba8404a6e56e22e69425e16ce (patch) | |
tree | 21cf84eabfee6ae312295ec29ce954727823b24a /nvim/.config/nvim | |
parent | d4a4a67fcb1b7a8cf7f987c1e3012043fd84e076 (diff) |
add haskell augroups
Diffstat (limited to 'nvim/.config/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 | ||