Skip to content

Commit

Permalink
Merge pull request #46 from anihm136/master
Browse files Browse the repository at this point in the history
Add eventignore to prevent autocommand triggering
  • Loading branch information
LunarWatcher committed Nov 11, 2021
2 parents a2ae9c9 + 7842ed6 commit 4dceac4
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions autoload/autopairs/Keybinds.vim
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
function! autopairs#Keybinds#IgnoreInsertEnter(f) abort
" TODO: Change this to use <cmd> when support for vim 8.2.19xx is dropped
let l:pre = "\<C-r>=autopairs#Keybinds#SetEventignore()\<CR>"
let l:val = call(function(a:f), a:000)
let l:post = "\<C-r>=autopairs#Keybinds#ResetEventignore()\<CR>"
return l:pre . l:val . l:post
endfunction

function! autopairs#Keybinds#IgnoreInsertEnterCmd(cmd) abort
call autopairs#Keybinds#SetEventignore()
normal a:cmd
call autopairs#Keybinds#ResetEventignore()
return ''
endfunction

function! autopairs#Keybinds#SetEventignore()
" TODO: Add InsertLeavePre when we know how to check version correctly on nvim
" or when support for vim 8.2.1873 and below is dropped
set eventignore+=InsertEnter,InsertLeave
return ''
endfunction

function! autopairs#Keybinds#ResetEventignore()
set eventignore-=InsertEnter,InsertLeave
return ''
endfunction

" Always silent the command
inoremap <silent> <SID>AutoPairsReturn <C-R>=autopairs#AutoPairsReturn()<CR>
inoremap <silent> <SID>AutoPairsReturn <C-r>=autopairs#Keybinds#IgnoreInsertEnter('autopairs#AutoPairsReturn')<cr>
imap <Plug>AutoPairsReturn <SID>AutoPairsReturn
func! autopairs#Keybinds#ExpandMap(map)
Expand Down Expand Up @@ -222,7 +249,7 @@ fun! autopairs#Keybinds#mapKeys()
if b:AutoPairsMoveExpression != ""
for key in split(b:AutoPairsMoveCharacter, '\s*')
let escaped_key = substitute(key, "'", "''", 'g')
execute 'inoremap <silent> <buffer> ' . substitute(b:AutoPairsMoveExpression, "%key", key, "") . " <C-R>=autopairs#AutoPairsMoveCharacter('".escaped_key."')<CR>"
execute 'inoremap <silent> <buffer> ' . substitute(b:AutoPairsMoveExpression, "%key", key, "") . " <C-R>=autopairs#Keybinds#IgnoreInsertEnter('autopairs#AutoPairsMoveCharacter', '".escaped_key."')<CR>"
endfor
endif

Expand Down Expand Up @@ -266,7 +293,9 @@ fun! autopairs#Keybinds#mapKeys()
endif

if b:AutoPairsShortcutJump != ''
execute 'inoremap <buffer> <silent> ' . b:AutoPairsShortcutJump . ' <ESC>:call autopairs#AutoPairsJump()<CR>a'
" execute 'inoremap <buffer> <silent> ' . b:AutoPairsShortcutJump . ' <cmd>set eventignore+=InsertEnter,InsertLeavePre,InsertLeave<CR><ESC>:call autopairs#AutoPairsJump()<CR>a<cmd>set eventignore-=InsertEnter,InsertLeavePre,InsertLeave<CR>'
execute 'inoremap <buffer> <silent> ' . b:AutoPairsShortcutJump . ' <C-r>=autopairs#Keybinds#IgnoreInsertEnterCmd("<ESC>:call autopairs#AutoPairsJump()<CR>a")'
execute 'inoremap <buffer> <silent> ' . b:AutoPairsShortcutJump . ' <cmd>call autopairs#AutoPairsJump()<CR>'
execute 'noremap <buffer> <silent> ' . b:AutoPairsShortcutJump . ' :call autopairs#AutoPairsJump()<CR>'
end

Expand Down

0 comments on commit 4dceac4

Please sign in to comment.