diff --git a/after/ftplugin/haskell/ghcmod.vim b/after/ftplugin/haskell/ghcmod.vim index 4c8c151..e04a93b 100644 --- a/after/ftplugin/haskell/ghcmod.vim +++ b/after/ftplugin/haskell/ghcmod.vim @@ -34,8 +34,8 @@ if !exists('g:ghcmod_max_preview_size') let g:ghcmod_max_preview_size = 10 endif -command! -buffer -nargs=0 GhcModType call s:echo(ghcmod#type()[1]) -command! -buffer -nargs=0 GhcModTypeInsert call ghcmod#type_insert() +command! -buffer -nargs=0 -bang GhcModType call s:type(0) +command! -buffer -nargs=0 -bang GhcModTypeInsert call ghcmod#type_insert(0) command! -buffer -nargs=? GhcModInfo call s:echo(s:info()) command! -buffer -nargs=0 GhcModTypeClear call ghcmod#type_clear() command! -buffer -nargs=? GhcModInfoPreview call ghcmod#preview(s:info(), g:ghcmod_max_preview_size) @@ -69,6 +69,13 @@ function! s:echo(msg) endif endfunction +function! s:type(force) + let l:type = ghcmod#type(a:force)[1] + if !empty(l:type) + echo l:type + endif +endfunction + function! s:make(type) let l:qflist = ghcmod#make(a:type) call setqflist(l:qflist) diff --git a/autoload/ghcmod.vim b/autoload/ghcmod.vim index 1e7fa06..2f99583 100644 --- a/autoload/ghcmod.vim +++ b/autoload/ghcmod.vim @@ -78,9 +78,15 @@ function! ghcmod#info(fexp)"{{{ return l:output endfunction"}}} -function! ghcmod#type()"{{{ +function! ghcmod#type(force)"{{{ if &l:modified - call ghcmod#print_warning('ghcmod#type: the buffer has been modified but not written') + let l:msg = 'ghcmod#type: the buffer has been modified but not written' + if a:force + call ghcmod#print_warning(l:msg) + else + call ghcmod#print_error(l:msg) + return ['', ''] + endif endif let l:line = line('.') let l:col = col('.') @@ -506,7 +512,7 @@ function! ghcmod#version()"{{{ return [0, 3, 0] endfunction"}}} -function! ghcmod#type_insert() "{{{ +function! ghcmod#type_insert(force) "{{{ let fexp = ghcmod#getHaskellIdentifier() if !exists('fexp') || fexp == '' call ghcmod#print_error('Failed to determine identifier under cursor.') @@ -516,7 +522,7 @@ function! ghcmod#type_insert() "{{{ if exists("b:ghcmod_type") unlet b:ghcmod_type " Make sure we aren't doing some weird persistence tricks endif - let [locsym, type] = ghcmod#type() + let [locsym, type] = ghcmod#type(a:force) call ghcmod#clear_highlight() if type == "" " Everything failed so let's just abort return diff --git a/doc/ghcmod.txt b/doc/ghcmod.txt index baf21b6..eb637ce 100644 --- a/doc/ghcmod.txt +++ b/doc/ghcmod.txt @@ -48,6 +48,21 @@ If you'd like to give GHC options, set |g:ghcmod_ghc_options|. Sub-expressions are highlighted as |hl-Search| by default. You can customize it by setting |g:ghcmod_type_highlight|. + If the current buffer is modified, this command is disabled. + +:GhcModType! *:GhcModType!* + Same as |:GhcModType|, but this command is executed even if the + current buffer is modified. + +:GhcModTypeInsert *:GhcModTypeInsert* + Insert a type signature under the cursor. + + If the current buffer is modified, this command is disabled. + +:GhcModTypeInsert! *:GhcModTypeInsert!* + Same as |:GhcModTypeInsert|, but this command is executed even if the + current buffer is modified. + :GhcModInfo *:GhcModInfo* Information about the identifier under the cursor is echoed.