Fixes #3, breaks '.'.

This commit is contained in:
Miao Jiang 2016-03-28 03:06:51 +08:00
parent 7f548cbb18
commit 0c30ba85f0

View File

@ -69,6 +69,18 @@ if !exists('g:AutoPairsSmartQuotes')
let g:AutoPairsSmartQuotes = 1
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 && has("patch849")
let s:Go = "\<C-G>U"
else
let s:Go = ""
endif
let s:Left = s:Go."\<LEFT>"
let s:Right = s:Go."\<RIGHT>"
" Will auto generated {']' => '[', ..., '}' => '{'}in initialize.
let g:AutoPairsClosedPairs = {}
@ -105,13 +117,13 @@ function! AutoPairsInsert(key)
" Skip the character if current character is the same as input
if current_char == a:key
return "\<C-G>U\<Right>"
return s:Right
end
if !g:AutoPairsFlyMode
" Skip the character if next character is space
if current_char == ' ' && next_char == a:key
return "\<C-G>U\<Right>\<C-G>U\<Right>"
return s:Right.s:Right
end
" Skip the character if closed pair is next character
@ -132,7 +144,7 @@ function! AutoPairsInsert(key)
" Fly Mode, and the key is closed-pairs, search closed-pair and jump
if g:AutoPairsFlyMode && has_key(b:AutoPairsClosedPairs, a:key)
if search(a:key, 'W')
return "\<C-G>U\<Right>"
return s:Right
endif
endif
@ -144,7 +156,7 @@ function! AutoPairsInsert(key)
let close = b:AutoPairs[open]
if current_char == close && open == close
return "\<C-G>U\<Right>"
return s:Right
end
" Ignore auto close ' if follows a word
@ -159,7 +171,7 @@ function! AutoPairsInsert(key)
let pprev_char = line[col('.')-3]
if pprev_char == open && prev_char == open
" Double pair found
return repeat(a:key, 4) . repeat("\<C-G>U\<LEFT>", 3)
return repeat(a:key, 4) . repeat(s:Left, 3)
end
end
@ -194,7 +206,7 @@ function! AutoPairsInsert(key)
endif
endif
return open.close."\<C-G>U\<Left>"
return open.close.s:Left
endfunction
function! AutoPairsDelete()
@ -318,10 +330,10 @@ function! AutoPairsFastWrap()
else
call search(s:FormatChunk(followed_open_pair, followed_close_pair), 'We')
end
return "\<C-G>U\<RIGHT>".inputed_close_pair."\<C-G>U\<LEFT>"
return s:Right.inputed_close_pair.s:Left
else
normal he
return "\<C-G>U\<RIGHT>".current_char."\<C-G>U\<LEFT>"
return s:Right.current_char.s:Left
end
endfunction
@ -388,7 +400,7 @@ function! AutoPairsSpace()
let cmd = ''
let cur_char =line[col('.')-1]
if has_key(g:AutoPairsParens, prev_char) && g:AutoPairsParens[prev_char] == cur_char
let cmd = "\<SPACE>\<C-G>U\<LEFT>"
let cmd = "\<SPACE>".s:Left
endif
return "\<SPACE>".cmd
endfunction