mirror of
https://github.com/jiangmiao/auto-pairs.git
synced 2025-04-20 19:28:48 +08:00
Improve <CR> mapping compatible. #43
This commit is contained in:
parent
d23864fdd6
commit
85a9a7daac
34
README.md
34
README.md
@ -269,40 +269,6 @@ Known Issues
|
||||
-----------------------
|
||||
There are the issues I cannot fix.
|
||||
|
||||
Compatible with Vimwiki - [issue #19](https://github.com/jiangmiao/auto-pairs/issues/19)
|
||||
|
||||
Description: When works with vimwiki `<CR>` will output `<SNR>xx_CR()`
|
||||
Reason: vimwiki uses `<expr>` on mapping `<CR>` that auto-pairs cannot expanding.
|
||||
Solution A: Add
|
||||
|
||||
" Copy from vimwiki.vim s:CR function for CR remapping
|
||||
function! VimwikiCR()
|
||||
let res = vimwiki#lst#kbd_cr()
|
||||
if res == "\<CR>" && g:vimwiki_table_mappings
|
||||
let res = vimwiki#tbl#kbd_cr()
|
||||
endif
|
||||
return res
|
||||
endfunction
|
||||
autocmd filetype vimwiki inoremap <buffer> <silent> <CR> <C-R>=VimwikiCR()<CR><C-R>=AutoPairsReturn()<CR>
|
||||
|
||||
to .vimrc, it will make vimwiki and auto-pairs 'Return' feature works together.
|
||||
|
||||
Solution B: add `let g:AutoPairsMapCR = 0` to .vimrc to disable `<CR>` mapping.
|
||||
|
||||
Compatible with viki - [issue #25](https://github.com/jiangmiao/auto-pairs/issues/25)
|
||||
|
||||
Description: When works with viki `<CR>` will output viki#ExprMarkInexistentInElement('ParagraphVisible','<CR>')
|
||||
Reason: viki uses `<expr>` on mapping `<CR>` that auto-pairs cannot expanding.
|
||||
Solution A: Add
|
||||
|
||||
autocmd filetype viki inoremap <buffer> <silent> <CR> <C-R>=viki#ExprMarkInexistentInElement('ParagraphVisible',"\n")<CR><C-R>=AutoPairsReturn()<CR>`
|
||||
|
||||
to .vimrc, it will make viki and auto-pairs works together.
|
||||
|
||||
Solution B: add `let g:AutoPairsMapCR = 0` to .vimrc to disable `<CR>` mapping.
|
||||
|
||||
Remarks: Solution A need NOT add `let g:AutoPairsMapCR = 0` to .vimrc, if Solution A still cannot work, then have to use Solution B to disable auto-pairs `<CR>`.
|
||||
|
||||
Breaks '.' - [issue #3](https://github.com/jiangmiao/auto-pairs/issues/3)
|
||||
|
||||
Description: After entering insert mode and inputing `[hello` then leave insert
|
||||
|
@ -442,11 +442,10 @@ function! AutoPairsInit()
|
||||
|
||||
endfunction
|
||||
|
||||
function! s:ExpandMap(map)
|
||||
function! s:ExpandMap(map, sid)
|
||||
let map = a:map
|
||||
if map =~ '<Plug>'
|
||||
let map = substitute(map, '\(<Plug>\w\+\)', '\=maparg(submatch(1), "i")', 'g')
|
||||
endif
|
||||
let map = substitute(map, '\(<Plug>\w\+\)', '\=maparg(submatch(1), "i")', 'g')
|
||||
let map = substitute(map, '<SID>', '<SNR>' . a:sid . '_', 'g')
|
||||
return map
|
||||
endfunction
|
||||
|
||||
@ -469,26 +468,24 @@ function! AutoPairsTryInit()
|
||||
" Buffer level keys mapping
|
||||
" comptible with other plugin
|
||||
if g:AutoPairsMapCR
|
||||
let old_cr = maparg('<CR>', 'i')
|
||||
if old_cr == ''
|
||||
let old_cr = '<CR>'
|
||||
let info = maparg('<CR>', 'i', 0, 1)
|
||||
if !empty(info)
|
||||
let old_cr = info['rhs']
|
||||
if old_cr !~ 'AutoPairsReturn'
|
||||
let old_cr = s:ExpandMap(old_cr, info['sid'])
|
||||
if info['expr']
|
||||
" remap <expr> to <SID>OldCR to avoid mix expr and non-expr mode
|
||||
let name = '<SID>AutoPairsOldCRWrapper'
|
||||
execute 'inoremap <expr> <script> '. name . ' ' . old_cr
|
||||
let old_cr = name
|
||||
end
|
||||
end
|
||||
else
|
||||
let old_cr = s:ExpandMap(old_cr)
|
||||
endif
|
||||
|
||||
" compatible with clang_complete
|
||||
" https://github.com/jiangmiao/auto-pairs/issues/18
|
||||
let pattern = '<SNR>\d\+_HandlePossibleSelectionEnter()'
|
||||
if old_cr =~ pattern
|
||||
execute 'imap <expr> <script> <SID>AutoPairsClangCompleteCR ' . matchstr(old_cr, pattern)
|
||||
let old_cr = substitute(old_cr, pattern , '<SID>AutoPairsClangCompleteCR', '')
|
||||
endif
|
||||
let old_cr = '<CR>'
|
||||
end
|
||||
|
||||
if old_cr !~ 'AutoPairsReturn'
|
||||
" generally speaking, <silent> should not be here because every plugin
|
||||
" has there own silent solution. but for some plugin which wasn't double silent
|
||||
" mapping, when maparg expand the map will lose the silent info, so <silent> always.
|
||||
" use inoremap for neocomplcache
|
||||
" Alawys slient mapping
|
||||
execute 'inoremap <script> <buffer> <silent> <CR> '.old_cr.'<SID>AutoPairsReturn'
|
||||
end
|
||||
endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user