-
Notifications
You must be signed in to change notification settings - Fork 59
Customize
ghcmod.vim passes these options to GHC via ghc-mod.
By default, ghcmod.vim doesn’t pass any GHC options.
Example: passing -idir1
and -idir2
to GHC
let g:ghcmod_ghc_options = ['-idir1', '-idir2']
ghmod.vim passes these options to hlint via ghc-mod.
By default, ghcmod.vim doesn’t pass any hlint options.
Example: passing '--ignore=Redundant $'
to hlint
let g:ghcmod_hlint_options = ['--ignore=Redundant $']
The highlight group used in :GhcModType
.
By default, the Search
group is used.
See :help :highlight
for details on Vim’s highlighting.
Example: highlighting sub-expressions with yellow background
hi ghcmodType ctermbg=yellow
let g:ghcmod_type_highlight = 'ghcmodType'
Put the below in your ~/.vimrc
.
When you write *.hs
buffer to a file, both check and lint are run.
autocmd BufWritePost *.hs call s:check_and_lint()
function! s:check_and_lint()
let l:qflist = ghcmod#make('check', expand('%'))
call extend(l:qflist, ghcmod#make('lint', expand('%')))
call setqflist(l:qflist)
cwindow
if empty(l:qflist)
echo "No errors found"
endif
endfunction
If you like asynchronous checking, put the below instead.
autocmd BufWritePost *.hs GhcModCheckAndLintAsync
ghcmod.vim gather errors into quickfix, so it could be useful to simply display in statusline whether quickfix is empty or not.
Put the below in your ~/.vim/ftplugin/haskell.vim
, then the statusline editing Haskell source has [No Errors] or [Errors Found] field.
let &l:statusline = '%{empty(getqflist()) ? "[No Errors]" : "[Errors Found]"}' . (empty(&l:statusline) ? &statusline : &l:statusline)
These autoload functions would be useful if you want to define a new command using ghcmod.vim.
ghcmod#type()
highlights the current sub-expression and returns highlighted region [line1, col1, line2, col2]
and its type.
Example return value: [['6', '10', '6', '17'], 'Maybe a']
ghcmod#type_clear()
clears the highlight created by ghcmod#type()
.
ghcmod#parse_make()
parses lines (which is ghc-mod’s output) and returns a list of quickfix items which can be used as an argument of setqflist()
.
This function is used by ghcmod#make()
and ghcmod#async_make()
.
Note that ghc-mod produces NUL-characters. Using the result of split(system('ghc-mod check /path/to/file.hs'), '\n')
is not a good idea.
ghcmod#make()
invokes ghc-mod and returns its output as a list of quckfix items.
type is either check
or lint
.
Example return value: [{'lnum': '3', 'col': '1', 'filename': 'M.hs', 'type': 'W', 'text': 'Top-level binding with no type signature: foo :: Int'}]
ghcmod#async_make()
invokes ghc-mod asynchronously and set its output at quickfix.
action is passed to setqflist()
’s second argument.
ghcmod#async#exist_session()
returns whether running sessions created via ghcmod#async#register()
exist.
ghcmod#async_make()
uses ghcmod#async#register()
internally.
This function is useful when you want to run check/lint automatically. See the definition of :GhcModCheckAndLintAsync
as an example.
ghcmod#expand()
returns the result of ghc-mod expand
as a list of quickfix items.
Example return value: [{'lnum': '5', 'col': '5', 'filename': 'N.hs', 'text': 'Splicing expression'}, {'text': ' " hello TH " ======> " hello TH "'}]
ghcmod#check_version()
returns whether ghc-mod’s version is higher or equal to version.
ghcmod#build_command()
returns a ghc-mod command.
This function adds g:ghcmod_ghc_options
to args .