Fix #44, compatible with old vim before 7.3.
This commit is contained in:
parent
0a79f50acb
commit
24ffa783f0
@ -442,10 +442,9 @@ function! AutoPairsInit()
|
|||||||
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:ExpandMap(map, sid)
|
function! s:ExpandMap(map)
|
||||||
let map = a:map
|
let map = a:map
|
||||||
let map = substitute(map, '\(<Plug>\w\+\)', '\=maparg(submatch(1), "i")', 'g')
|
let map = substitute(map, '\(<Plug>\w\+\)', '\=maparg(submatch(1), "i")', 'g')
|
||||||
let map = substitute(map, '<SID>', '<SNR>' . a:sid . '_', 'g')
|
|
||||||
return map
|
return map
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@ -468,23 +467,42 @@ function! AutoPairsTryInit()
|
|||||||
" Buffer level keys mapping
|
" Buffer level keys mapping
|
||||||
" comptible with other plugin
|
" comptible with other plugin
|
||||||
if g:AutoPairsMapCR
|
if g:AutoPairsMapCR
|
||||||
let info = maparg('<CR>', 'i', 0, 1)
|
if v:version >= 703
|
||||||
if !empty(info)
|
" VIM 7.3 supports advancer maparg which could get <expr> info
|
||||||
let old_cr = info['rhs']
|
" then auto-pairs could remap <CR> in any case.
|
||||||
if old_cr !~ 'AutoPairsReturn'
|
let info = maparg('<CR>', 'i', 0, 1)
|
||||||
let old_cr = s:ExpandMap(old_cr, info['sid'])
|
if empty(info)
|
||||||
if info['expr']
|
let old_cr = '<CR>'
|
||||||
" remap <expr> to `name` to avoid mix expr and non-expr mode
|
let is_expr = 0
|
||||||
let name = '<SID>AutoPairsOldCRWrapper'
|
else
|
||||||
execute 'inoremap <buffer> <expr> <script> '. name . ' ' . old_cr
|
let old_cr = info['rhs']
|
||||||
let old_cr = name
|
let old_cr = s:ExpandMap(old_cr)
|
||||||
end
|
let old_cr = substitute(old_cr, '<SID>', '<SNR>' . info['sid'] . '_', 'g')
|
||||||
end
|
let is_expr = 1
|
||||||
|
let wrapper_name = '<SID>AutoPairsOldCRWrapper73'
|
||||||
|
endif
|
||||||
else
|
else
|
||||||
let old_cr = '<CR>'
|
" VIM version less than 7.3
|
||||||
|
" the mapping's <expr> info is lost, so guess it is expr or not, it's
|
||||||
|
" not accurate.
|
||||||
|
let old_cr = maparg('<CR>', 'i')
|
||||||
|
if old_cr == ''
|
||||||
|
let old_cr = '<CR>'
|
||||||
|
let is_expr = 0
|
||||||
|
else
|
||||||
|
let old_cr = s:ExpandMap(old_cr)
|
||||||
|
" old_cr contain (), I guess the old cr is in expr mode
|
||||||
|
let is_expr = old_cr =~ '\V()'
|
||||||
|
let wrapper_name = '<SID>AutoPairsOldCRWrapper'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if old_cr !~ 'AutoPairsReturn'
|
if old_cr !~ 'AutoPairsReturn'
|
||||||
|
if is_expr
|
||||||
|
" remap <expr> to `name` to avoid mix expr and non-expr mode
|
||||||
|
execute 'inoremap <buffer> <expr> <script> '. wrapper_name . ' ' . old_cr
|
||||||
|
let old_cr = wrapper_name
|
||||||
|
end
|
||||||
" Alawys slient mapping
|
" Alawys slient mapping
|
||||||
execute 'inoremap <script> <buffer> <silent> <CR> '.old_cr.'<SID>AutoPairsReturn'
|
execute 'inoremap <script> <buffer> <silent> <CR> '.old_cr.'<SID>AutoPairsReturn'
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user