Permalink
Browse files

Improve #36, Keep quotes number is odd in one line.

  • Loading branch information...
1 parent 2982312 commit fc5b845f6b99a6bf0c560535f02434ddd70b0fa3 @jiangmiao committed Mar 4, 2013
Showing with 25 additions and 1 deletion.
  1. +25 −1 plugin/auto-pairs.vim
View
@@ -58,6 +58,10 @@ if !exists('g:AutoPairsShortcutBackInsert')
let g:AutoPairsShortcutBackInsert = '<M-b>'
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."\<Left>"
endfunction

0 comments on commit fc5b845

Please sign in to comment.