Call #Finish() only when necessary for <BS>. As mentioned in #124.

This commit is contained in:
Israel Chauca Fuentes
2013-03-27 18:33:58 -04:00
parent eb7738e4aa
commit 739d2f9bd4

View File

@@ -279,6 +279,10 @@ function! s:FlushBuffer() " {{{
return '' return ''
endfunction " }}} endfunction " }}}
function! s:empty_buffer()
return empty(b:_l_delimitMate_buffer)
endfunction
"}}} "}}}
" Mappers: {{{ " Mappers: {{{
@@ -331,7 +335,7 @@ endfunction "}}}
function! s:ExtraMappings() "{{{ function! s:ExtraMappings() "{{{
" If pair is empty, delete both delimiters: " If pair is empty, delete both delimiters:
inoremap <silent> <Plug>delimitMateBS <C-R>=delimitMate#BS()<CR> inoremap <silent><expr> <Plug>delimitMateBS delimitMate#WithinEmptyPair() ? "\<C-R>=delimitMate#BS()\<CR>" : "\<BS>"
if !hasmapto('<Plug>delimitMateBS','i') && maparg('<BS>'. 'i') == '' if !hasmapto('<Plug>delimitMateBS','i') && maparg('<BS>'. 'i') == ''
silent! imap <unique> <buffer> <BS> <Plug>delimitMateBS silent! imap <unique> <buffer> <BS> <Plug>delimitMateBS
endif endif
@@ -367,7 +371,7 @@ function! s:ExtraMappings() "{{{
\ 'ScrollWheelRight', 'S-ScrollWheelRight', 'C-ScrollWheelRight'] \ 'ScrollWheelRight', 'S-ScrollWheelRight', 'C-ScrollWheelRight']
" Flush the char buffer on movement keystrokes: " Flush the char buffer on movement keystrokes:
for map in keys for map in keys
exec 'inoremap <silent><expr> <Plug>delimitMate'.map.' !empty(b:_l_delimitMate_buffer) ? "<C-R>=delimitMate#Finish(1)<CR><'.map.'>" : "<'.map.'>"' exec 'inoremap <silent><expr> <Plug>delimitMate'.map.' !<SID>empty_buffer() ? "<C-R>=delimitMate#Finish(1)<CR><'.map.'>" : "<'.map.'>"'
if !hasmapto('<Plug>delimitMate'.map, 'i') && maparg('<'.map.'>', 'i') == '' if !hasmapto('<Plug>delimitMate'.map, 'i') && maparg('<'.map.'>', 'i') == ''
exec 'silent! imap <unique> <buffer> <'.map.'> <Plug>delimitMate'.map exec 'silent! imap <unique> <buffer> <'.map.'> <Plug>delimitMate'.map
endif endif
@@ -383,7 +387,7 @@ function! s:ExtraMappings() "{{{
endif endif
" Except when pop-up menu is active: " Except when pop-up menu is active:
for map in ['Up', 'Down', 'PageUp', 'PageDown', 'S-Down', 'S-Up'] for map in ['Up', 'Down', 'PageUp', 'PageDown', 'S-Down', 'S-Up']
exec 'inoremap <silent> <expr> <Plug>delimitMate'.map.' pumvisible() \|\| empty(b:_l_delimitMate_buffer) ? "\<'.map.'>" : "\<C-R>=\<SID>Finish()\<CR>\<'.map.'>"' exec 'inoremap <silent> <expr> <Plug>delimitMate'.map.' pumvisible() \|\| <SID>empty_buffer() ? "\<'.map.'>" : "\<C-R>=\<SID>Finish()\<CR>\<'.map.'>"'
if !hasmapto('<Plug>delimitMate'.map, 'i') && maparg('<'.map.'>', 'i') == '' if !hasmapto('<Plug>delimitMate'.map, 'i') && maparg('<'.map.'>', 'i') == ''
exec 'silent! imap <unique> <buffer> <'.map.'> <Plug>delimitMate'.map exec 'silent! imap <unique> <buffer> <'.map.'> <Plug>delimitMate'.map
endif endif