From 207107a684791eeebed881cb26d7099eaa2bfa81 Mon Sep 17 00:00:00 2001 From: "jiangfriend@gmail.com" Date: Tue, 24 Jan 2012 19:34:25 +0800 Subject: [PATCH] Fixes #7: compatible with other plugin for key --- plugin/auto-pairs.vim | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/plugin/auto-pairs.vim b/plugin/auto-pairs.vim index 04fea83..5e867a4 100644 --- a/plugin/auto-pairs.vim +++ b/plugin/auto-pairs.vim @@ -1,8 +1,8 @@ " Insert or delete brackets, parens, quotes in pairs. " Maintainer: JiangMiao " Contributor: camthompson -" Last Change: 2012-01-17 -" Version: 1.1.4 +" Last Change: 2012-01-24 +" Version: 1.1.5 " Homepage: http://www.vim.org/scripts/script.php?script_id=3599 " Repository: https://github.com/jiangmiao/auto-pairs @@ -206,7 +206,8 @@ endfunction function! AutoPairsReturn() let line = getline('.') - let prev_char = line[col('.')-2] + let pline = getline(line('.')-1) + let prev_char = pline[strlen(pline)-1] let cmd = '' let cur_char = line[col('.')-1] if has_key(g:AutoPairs, prev_char) && g:AutoPairs[prev_char] == cur_char @@ -217,12 +218,12 @@ function! AutoPairsReturn() " javascript need indent new line " coffeescript forbid indent new line if &filetype == 'coffeescript' - return "\\".cur_char."\k==o".cmd + return "\k==o".cmd else - return "\\".cur_char."\=ko".cmd + return "\=ko".cmd endif end - return "\" + return '' endfunction function! AutoPairsSpace() @@ -239,6 +240,8 @@ endfunction function! AutoPairsInit() let b:autopairs_loaded = 1 let b:autopairs_enabled = 1 + + " buffer level map pairs keys for [open, close] in items(g:AutoPairs) call AutoPairsMap(open) if open != close @@ -247,19 +250,17 @@ function! AutoPairsInit() let g:AutoPairsClosedPairs[close] = 1 endfor + " Still use level mapping for if g:AutoPairsMapBS execute 'inoremap AutoPairsDelete()' end - if g:AutoPairsMapCR - execute 'inoremap AutoPairsReturn()' - end - if g:AutoPairsMapSpace - execute 'inoremap AutoPairsSpace()' + execute 'inoremap AutoPairsSpace()' end execute 'inoremap '.g:AutoPairsShortcutFastWrap.' =AutoPairsFastWrap()' + " use to ensure showing the status when toggle execute 'inoremap '.g:AutoPairsShortcutToggle.' AutoPairsToggle()' execute 'noremap '.g:AutoPairsShortcutToggle.' :call AutoPairsToggle()' " If the keys map conflict with your own settings, delete or change them @@ -278,4 +279,18 @@ function! AutoPairsForceInit() endif endfunction + +" Global keys mapping +" comptible with other plugin +if g:AutoPairsMapCR + let old_cr = maparg('', 'i') + if old_cr == '' + let old_cr = '' + endif + + if old_cr !~ 'AutoPairsReturn' + execute 'imap '.old_cr.'=AutoPairsReturn()' + end +endif + au BufEnter * :call AutoPairsForceInit()