File tree Expand file tree Collapse file tree 3 files changed +34
-6
lines changed Expand file tree Collapse file tree 3 files changed +34
-6
lines changed Original file line number Diff line number Diff line change @@ -34,8 +34,8 @@ if !exists('g:ghcmod_max_preview_size')
3434 let g: ghcmod_max_preview_size = 10
3535endif
3636
37- command ! - buffer -nargs =0 GhcModType call s: echo ( ghcmod# type ()[ 1 ] )
38- command ! - buffer -nargs =0 GhcModTypeInsert call ghcmod#type_insert ()
37+ command ! - buffer -nargs =0 - bang GhcModType call s: type (<bang> 0 )
38+ command ! - buffer -nargs =0 - bang GhcModTypeInsert call ghcmod#type_insert (<bang> 0 )
3939command ! - buffer -nargs =? GhcModInfo call s: echo (s: info (<q-args> ))
4040command ! - buffer -nargs =0 GhcModTypeClear call ghcmod#type_clear ()
4141command ! - buffer -nargs =? GhcModInfoPreview call ghcmod#preview (s: info (<q-args> ), g: ghcmod_max_preview_size )
@@ -69,6 +69,13 @@ function! s:echo(msg)
6969 endif
7070endfunction
7171
72+ function ! s: type (force)
73+ let l: type = ghcmod#type (a: force )[1 ]
74+ if ! empty (l: type )
75+ echo l: type
76+ endif
77+ endfunction
78+
7279function ! s: make (type )
7380 let l: qflist = ghcmod#make (a: type )
7481 call setqflist (l: qflist )
Original file line number Diff line number Diff line change @@ -78,9 +78,15 @@ function! ghcmod#info(fexp)"{{{
7878 return l: output
7979endfunction " }}}
8080
81- function ! ghcmod#type ()" {{{
81+ function ! ghcmod#type (force )" {{{
8282 if &l: modified
83- call ghcmod#print_warning (' ghcmod#type: the buffer has been modified but not written' )
83+ let l: msg = ' ghcmod#type: the buffer has been modified but not written'
84+ if a: force
85+ call ghcmod#print_warning (l: msg )
86+ else
87+ call ghcmod#print_error (l: msg )
88+ return [' ' , ' ' ]
89+ endif
8490 endif
8591 let l: line = line (' .' )
8692 let l: col = col (' .' )
@@ -506,7 +512,7 @@ function! ghcmod#version()"{{{
506512 return [0 , 3 , 0 ]
507513endfunction " }}}
508514
509- function ! ghcmod#type_insert () " {{{
515+ function ! ghcmod#type_insert (force ) " {{{
510516 let fexp = ghcmod#getHaskellIdentifier ()
511517 if ! exists (' fexp' ) || fexp == ' '
512518 call ghcmod#print_error (' Failed to determine identifier under cursor.' )
@@ -516,7 +522,7 @@ function! ghcmod#type_insert() "{{{
516522 if exists (" b:ghcmod_type" )
517523 unlet b: ghcmod_type " Make sure we aren't doing some weird persistence tricks
518524 endif
519- let [locsym, type ] = ghcmod#type ()
525+ let [locsym, type ] = ghcmod#type (a: force )
520526 call ghcmod#clear_highlight ()
521527 if type == " " " Everything failed so let's just abort
522528 return
Original file line number Diff line number Diff line change @@ -48,6 +48,21 @@ If you'd like to give GHC options, set |g:ghcmod_ghc_options|.
4848 Sub-expressions are highlighted as | hl-Search | by default. You can
4949 customize it by setting | g:ghcmod_type_highlight | .
5050
51+ If the current buffer is modified, this command is disabled.
52+
53+ :GhcModType! *:GhcModType!*
54+ Same as | :GhcModType | , but this command is executed even if the
55+ current buffer is modified.
56+
57+ :GhcModTypeInsert *:GhcModTypeInsert*
58+ Insert a type signature under the cursor.
59+
60+ If the current buffer is modified, this command is disabled.
61+
62+ :GhcModTypeInsert! *:GhcModTypeInsert!*
63+ Same as | :GhcModTypeInsert | , but this command is executed even if the
64+ current buffer is modified.
65+
5166:GhcModInfo *:GhcModInfo*
5267 Information about the identifier under the cursor is echoed.
5368
You can’t perform that action at this time.
0 commit comments