Skip to content

Commit

Permalink
Fixes #3, breaks '.'.
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangmiao committed Mar 27, 2016
1 parent 7f548cb commit 0c30ba8
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions plugin/auto-pairs.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -194,7 +206,7 @@ function! AutoPairsInsert(key)
endif
endif

return open.close."\<C-G>U\<Left>"
return open.close.s:Left
endfunction

function! AutoPairsDelete()
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0c30ba8

Please sign in to comment.