From fc5b845f6b99a6bf0c560535f02434ddd70b0fa3 Mon Sep 17 00:00:00 2001 From: Miao Jiang Date: Mon, 4 Mar 2013 14:19:13 +0800 Subject: [PATCH] Improve #36, Keep quotes number is odd in one line. --- plugin/auto-pairs.vim | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/plugin/auto-pairs.vim b/plugin/auto-pairs.vim index 8072e53..b4c079d 100644 --- a/plugin/auto-pairs.vim +++ b/plugin/auto-pairs.vim @@ -58,6 +58,10 @@ if !exists('g:AutoPairsShortcutBackInsert') let g:AutoPairsShortcutBackInsert = '' endif +if !exists('g:AutoPairsSmartQuotes') + let g:AutoPairsSmartQuotes = 1 +endif + " Will auto generated {']' => '[', ..., '}' => '{'}in initialize. let g:AutoPairsClosedPairs = {} @@ -119,7 +123,7 @@ function! AutoPairsInsert(key) endif endif - " Input directly if the key is not an open key + " Insert directly if the key is not an open key return a:key end @@ -146,6 +150,26 @@ function! AutoPairsInsert(key) end end + " Keep quote number is odd. + " Because quotes should be matched in the same line in most of situation + if g:AutoPairsSmartQuotes && open == close + " Remove \\ , \" \' + let cleaned_line = substitute(line, '\v(\\.)', '', 'g') + let n = 0 + let pos = 0 + while 1 + let pos = stridx(cleaned_line, open, pos) + if pos == -1 + break + end + let n = n + 1 + let pos = pos + 1 + endwhile + if n % 2 == 1 + return a:key + endif + endif + return open.close."\" endfunction