From 1884e426ca065a8e0ef4b38565d2ed0b900f6f30 Mon Sep 17 00:00:00 2001 From: Miao Jiang Date: Tue, 15 Jan 2019 17:03:32 +0800 Subject: [PATCH] Fix delete pairs incorrect --- plugin/auto-pairs.vim | 108 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 89 insertions(+), 19 deletions(-) diff --git a/plugin/auto-pairs.vim b/plugin/auto-pairs.vim index bcfd0ec..2cb6340 100644 --- a/plugin/auto-pairs.vim +++ b/plugin/auto-pairs.vim @@ -29,6 +29,10 @@ if !exists('g:AutoPairsMapCR') let g:AutoPairsMapCR = 1 end +if !exists('g:AutoPairsWildClosedPair') + let g:AutoPairsWildClosedPair = ']' +end + if !exists('g:AutoPairsMapSpace') let g:AutoPairsMapSpace = 1 end @@ -87,8 +91,6 @@ let s:Left = s:Go."\" let s:Right = s:Go."\" -" Will auto generated {']' => '[', ..., '}' => '{'}in initialize. -let g:AutoPairsClosedPairs = {} " unicode len @@ -132,6 +134,22 @@ func! s:getline() return [before, after] endf +" split text to two part +func! s:matchend(text, open) + let m = matchstr(a:text, '\V'.a:open.'\v$') + if m == "" + return [] + end + return [a:text, strpart(a:text, 0, len(a:text)-len(m)), m] +endf +func! s:matchbegin(text, close) + let m = matchstr(a:text, '^\V'.a:close) + if m == "" + return [] + end + return [a:text, m, strpart(a:text, len(m), len(a:text)-len(m))] +endf + " add or delete pairs base on g:AutoPairs " AutoPairsDefine(addPairs:dict[, removeOpenPairList:list]) " @@ -168,7 +186,7 @@ func! AutoPairsInsert(key) " check close pairs for [open, close] in b:AutoPairsList if close[0] == a:key - let m = matchlist(after, '\v^\s*(\V'.close.'\v)') + let m = s:matchbegin(after, '\v\s*\V'.close) if len(m) > 0 " skip close pair call search(m[1], 'We') @@ -180,18 +198,45 @@ func! AutoPairsInsert(key) " check open pairs let text=before.a:key for [open, close] in b:AutoPairsList - let m = matchstr(text, '\V'.open.'\v$') - if m != '' + let m = s:matchend(text, open) + if len(m) > 0 " process the open pair " remove inserted pair " eg: if the pairs include < > and " when