Skip to content

Commit

Permalink
Clean up legacy code
Browse files Browse the repository at this point in the history
  • Loading branch information
LunarWatcher committed Jan 23, 2023
1 parent 6f2c32e commit dde1132
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 67 deletions.
77 changes: 22 additions & 55 deletions autoload/autopairs/Keybinds.vim
Original file line number Diff line number Diff line change
Expand Up @@ -198,54 +198,28 @@ endfun

fun! autopairs#Keybinds#mapKeys()

" TODO: decode this comment
" for auto-pairs starts with 'a', so the priority is higher than supertab and vim-endwise
" This bit of code attempts to be compatible with other plugins.
" It isn't always successful (:h autopairs-bad-cr), which is
" overwhelmingly caused by other plugins doing weird shit with their
" functions, in a way that often expects dedicated `<CR>` access.
"
" vim-endwise doesn't support <Plug>AutoPairsReturn
" when use <Plug>AutoPairsReturn will cause <Plug> isn't expanded
"
" supertab doesn't support <SID>AutoPairsReturn
" when use <SID>AutoPairsReturn will cause Duplicated <CR>
"
" and when load after vim-endwise will cause unexpected endwise inserted.
" so always load AutoPairs at last

" Buffer level keys mapping
" comptible with other plugin
" This leads to incompatibilities, some of which were previously listed in
" a comment here, but have been moved to :h autopairs-incompatible-cr, at
" least for plugins that have a confirmed incompatibility
if b:AutoPairsMapCR
if v:version == 703 && has('patch32') || v:version > 703
" VIM 7.3 supports advancer maparg which could get <expr> info
" then auto-pairs could remap <CR> in any case.
let info = maparg(g:AutoPairsCRKey, 'i', 0, 1)
if empty(info)
" Not _entirely_ sure if this should be <CR> or
" g:AutoPairsCRKey.
let old_cr = '<CR>'
let is_expr = 0
else
let old_cr = info['rhs']
let old_cr = autopairs#Keybinds#ExpandMap(old_cr)
let old_cr = substitute(old_cr, '<SID>', '<SNR>' .. info['sid'] .. '_', 'g')
let is_expr = info['expr']
let wrapper_name = '<SID>AutoPairsOldCRWrapper73'
endif
" VIM 7.3 supports the advanced maparg, which can get <expr> info
let info = maparg(g:AutoPairsCRKey, 'i', 0, 1)
if empty(info)
" Not _entirely_ sure if this should be <CR> or
" g:AutoPairsCRKey.
let old_cr = '<CR>'
let is_expr = 0
else
" 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(b:AutoPairsCRKey, 'i')
if old_cr == ''
let old_cr = '<CR>'
let is_expr = 0
else
let old_cr = autopairs#Keybinds#ExpandMap(old_cr)
" old_cr contain (, I guess the old cr is in expr mode
let is_expr = old_cr =~ '\V(' && toupper(old_cr) !~ '\V<C-R>'

" The old_cr start with " it must be in expr mode
let is_expr = is_expr || old_cr =~ '\v^"'
let wrapper_name = '<SID>AutoPairsOldCRWrapper'
endif
let old_cr = info['rhs']
let old_cr = autopairs#Keybinds#ExpandMap(old_cr)
let old_cr = substitute(old_cr, '<SID>', '<SNR>' .. info['sid'] .. '_', 'g')
let is_expr = info['expr']
let wrapper_name = '<SID>AutoPairsOldCRWrapper73'
endif

if old_cr !~ 'AutoPairsReturn'
Expand Down Expand Up @@ -273,16 +247,9 @@ fun! autopairs#Keybinds#mapKeys()
end

if b:AutoPairsMapSpace
" Try to respect abbreviations on a <SPACE>
let do_abbrev = ""
" neovim appears to set v:version to 800, so it should be compatible
" with this.
" Admittedly, probably not compatible with the same version checks,
" but hey, it's fine.
if v:version == 703 && has("patch489") || v:version > 703
let do_abbrev = "<C-]>"
endif
execute 'inoremap <buffer> <silent> <SPACE> ' .. do_abbrev .. '<C-R>=autopairs#AutoPairsSpace()<CR>'

" <C-]> is required to respect abbreviations
execute 'inoremap <buffer> <silent> <SPACE> <C-]><C-R>=autopairs#AutoPairsSpace()<CR>'
end

if b:AutoPairsShortcutFastWrap != ''
Expand Down
13 changes: 5 additions & 8 deletions autoload/autopairs/Strings.vim
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ if !has('nvim') && has('vimscript-4')
scriptversion 4
endif

" 7.4.849 support <C-G>U to avoid breaking '.'
" Issue talk: https://github.com/jiangmiao/auto-pairs/issues/3
" Vim note: https://github.com/vim/vim/releases/tag/v7.4.849
if v:version > 704 || v:version == 704 && has("patch849")
let g:autopairs#Strings#Go = "\<C-G>U"
else
let g:autopairs#Strings#Go = ""
endif

" This statement previously had a version check, but it has been removed as
" that check isn't necessary anymore. A newer version is enforced, so this is
" guaranteed supported
let g:autopairs#Strings#Go = "\<C-G>U"

let g:autopairs#Strings#Left = g:autopairs#Strings#Go.."\<LEFT>"
let g:autopairs#Strings#Right = g:autopairs#Strings#Go.."\<RIGHT>"
Expand Down
4 changes: 0 additions & 4 deletions autoload/autopairs/Variables.vim
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ fun! s:define(name, default)
endif
endfun

fun! autopairs#Variables#_InitVariables()
echoerr "This function has been renamed. Use autopairs#Variables#InitVariables instead (note the missing _)"
endfun

" TODO: sort this garbage
fun! autopairs#Variables#InitVariables()
" Default autopairs
Expand Down

0 comments on commit dde1132

Please sign in to comment.