diff --git a/autoload/autopairs/Keybinds.vim b/autoload/autopairs/Keybinds.vim index 34a6939..499ef95 100644 --- a/autoload/autopairs/Keybinds.vim +++ b/autoload/autopairs/Keybinds.vim @@ -1,5 +1,32 @@ +function! autopairs#Keybinds#IgnoreInsertEnter(f) abort + " TODO: Change this to use when support for vim 8.2.19xx is dropped + let l:pre = "\=autopairs#Keybinds#SetEventignore()\" + let l:val = call(function(a:f), a:000) + let l:post = "\=autopairs#Keybinds#ResetEventignore()\" + 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 AutoPairsReturn =autopairs#AutoPairsReturn() +inoremap AutoPairsReturn =autopairs#Keybinds#IgnoreInsertEnter('autopairs#AutoPairsReturn') imap AutoPairsReturn AutoPairsReturn func! autopairs#Keybinds#ExpandMap(map) @@ -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 ' . substitute(b:AutoPairsMoveExpression, "%key", key, "") . " =autopairs#AutoPairsMoveCharacter('".escaped_key."')" + execute 'inoremap ' . substitute(b:AutoPairsMoveExpression, "%key", key, "") . " =autopairs#Keybinds#IgnoreInsertEnter('autopairs#AutoPairsMoveCharacter', '".escaped_key."')" endfor endif @@ -266,7 +293,9 @@ fun! autopairs#Keybinds#mapKeys() endif if b:AutoPairsShortcutJump != '' - execute 'inoremap ' . b:AutoPairsShortcutJump . ' :call autopairs#AutoPairsJump()a' + " execute 'inoremap ' . b:AutoPairsShortcutJump . ' set eventignore+=InsertEnter,InsertLeavePre,InsertLeave:call autopairs#AutoPairsJump()aset eventignore-=InsertEnter,InsertLeavePre,InsertLeave' + execute 'inoremap ' . b:AutoPairsShortcutJump . ' =autopairs#Keybinds#IgnoreInsertEnterCmd(":call autopairs#AutoPairsJump()a")' + execute 'inoremap ' . b:AutoPairsShortcutJump . ' call autopairs#AutoPairsJump()' execute 'noremap ' . b:AutoPairsShortcutJump . ' :call autopairs#AutoPairsJump()' end