From 9f4180abeab0067ba8404a6e56e22e69425e16ce Mon Sep 17 00:00:00 2001 From: Akshay Date: Wed, 5 Aug 2020 20:18:22 +0530 Subject: add haskell augroups --- nvim/.config/nvim/ftplugin/haskell.vim | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 nvim/.config/nvim/ftplugin/haskell.vim (limited to 'nvim') 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 @@ +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 -- cgit v1.2.3