mirror of
https://github.com/Raimondi/delimitMate.git
synced 2025-12-07 05:04:34 +08:00
Don't use setline() for left-side matchpair.
This commit is contained in:
@@ -353,34 +353,31 @@ function! delimitMate#SkipDelim(char) "{{{
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! delimitMate#ParenDelim(char) " {{{
|
||||
if delimitMate#IsForbidden(a:char)
|
||||
return ''
|
||||
function! delimitMate#ParenDelim(right) " {{{
|
||||
let left = s:g('left_delims')[index(s:g('right_delims'),a:right)]
|
||||
if delimitMate#IsForbidden(a:right)
|
||||
return left
|
||||
endif
|
||||
" Try to balance matchpairs
|
||||
if s:g('balance_matchpairs') &&
|
||||
\ delimitMate#BalancedParens(a:char) <= 0
|
||||
return ''
|
||||
\ delimitMate#BalancedParens(a:right) < 0
|
||||
return left
|
||||
endif
|
||||
let line = getline('.')
|
||||
let col = col('.')-2
|
||||
let tail = len(line) == (col + 1) ? s:g('eol_marker') : ''
|
||||
let left = s:g('left_delims')[index(s:g('right_delims'),a:char)]
|
||||
let smart_matchpairs = substitute(s:g('smart_matchpairs'), '\\!', left, 'g')
|
||||
let smart_matchpairs = substitute(smart_matchpairs, '\\#', a:char, 'g')
|
||||
let smart_matchpairs = substitute(smart_matchpairs, '\\#', a:right, 'g')
|
||||
|
||||
if s:g('smart_matchpairs') != '' &&
|
||||
\ line[col+1:] =~ smart_matchpairs
|
||||
return ''
|
||||
elseif (col) < 0
|
||||
call setline('.',a:char.line)
|
||||
call delimitMate#AddToBuffer(a:char)
|
||||
else
|
||||
"echom string(col).':'.line[:(col)].'|'.line[(col+1):]
|
||||
call setline('.',line[:(col)].a:char.tail.line[(col+1):])
|
||||
call delimitMate#AddToBuffer(a:char . tail)
|
||||
return left
|
||||
"elseif (col) < 0
|
||||
" call setline('.',a:right.line)
|
||||
" call delimitMate#AddToBuffer(a:right)
|
||||
endif
|
||||
return ''
|
||||
call delimitMate#AddToBuffer(a:right . tail)
|
||||
return left . a:right . tail . repeat("\<Left>", len(split(tail, '\zs')) + 1)
|
||||
endfunction " }}}
|
||||
|
||||
function! delimitMate#QuoteDelim(char) "{{{
|
||||
|
||||
@@ -296,7 +296,7 @@ function! s:AutoClose() "{{{
|
||||
while i < len(s:g('matchpairs_list'))
|
||||
let ld = s:g('left_delims')[i] == '|' ? '<bar>' : s:g('left_delims')[i]
|
||||
let rd = s:g('right_delims')[i] == '|' ? '<bar>' : s:g('right_delims')[i]
|
||||
exec 'inoremap <silent> <Plug>delimitMate' . ld . ' ' . ld . '<C-R>=delimitMate#ParenDelim("' . escape(rd, '|') . '")<CR>'
|
||||
exec 'inoremap <silent> <Plug>delimitMate' . ld . ' <C-R>=delimitMate#ParenDelim("' . escape(rd, '|') . '")<CR>'
|
||||
exec 'silent! imap <unique> <buffer> '.ld.' <Plug>delimitMate'.ld
|
||||
let i += 1
|
||||
endwhile
|
||||
|
||||
Reference in New Issue
Block a user