Skip to content

Commit

Permalink
Quit guessing the type if the current buffer is modified (#24)
Browse files Browse the repository at this point in the history
I introduced new variant :GhcModType! and :GhcModTypeInsert! which is
executed even if the current buffer is modified (the previous behavior
of :GhcModType and :GhcModTypeInsert).
  • Loading branch information
eagletmt committed Mar 13, 2013
1 parent 2f85421 commit b488b2a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
11 changes: 9 additions & 2 deletions after/ftplugin/haskell/ghcmod.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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(<bang>0)
command! -buffer -nargs=0 -bang GhcModTypeInsert call ghcmod#type_insert(<bang>0)
command! -buffer -nargs=? GhcModInfo call s:echo(s:info(<q-args>))
command! -buffer -nargs=0 GhcModTypeClear call ghcmod#type_clear()
command! -buffer -nargs=? GhcModInfoPreview call ghcmod#preview(s:info(<q-args>), g:ghcmod_max_preview_size)
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 10 additions & 4 deletions autoload/ghcmod.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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('.')
Expand Down Expand Up @@ -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.')
Expand All @@ -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
Expand Down
15 changes: 15 additions & 0 deletions doc/ghcmod.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit b488b2a

Please sign in to comment.