Close empty pairs smartly

This commit is contained in:
Miao Jiang 2019-01-23 00:49:16 +08:00
parent 3413c38fe3
commit f1d9a2bf63
2 changed files with 16 additions and 11 deletions

View File

@ -31,7 +31,7 @@ Features
| |
} (press } to close the pair) } (press } to close the pair)
output: { output: {
}| (the inserted empty line will be deleted) }| (the inserted blank line will be deleted)
* Insert spaces before closing characters, only for [], (), {} * Insert spaces before closing characters, only for [], (), {}

View File

@ -194,21 +194,26 @@ func! AutoPairsInsert(key)
end end
if a:key == g:AutoPairsWildClosedPair || opt['mapclose'] && close[0] == a:key if a:key == g:AutoPairsWildClosedPair || opt['mapclose'] && close[0] == a:key
" the close pair is in the same line " the close pair is in the same line
let m = matchstr(after, '^\v\s*\zs\V'.close) let m = matchstr(afterline, '^\v\s*\V'.close)
if m != '' if m != ''
if b:autopairs_return_pos == line('.') && getline('.') =~ '\v^\s*$' if before =~ '\V'.open.'\v\s*$' && m[0] =~ '\v\s'
normal! ddk$ " remove the space we inserted if the text in pairs is blank
elseif col('.') > 1 return "\<DEL>".s:right(m[1:])
normal! h
elseif line('.') > 1
normal! k$
else else
return s:right(m) return s:right(m)
end
end
let m = matchstr(after, '^\v\s*\zs\V'.close)
if m != ''
if a:key == g:AutoPairsWildClosedPair || opt['multiline']
if b:autopairs_return_pos == line('.') && getline('.') =~ '\v^\s*$'
normal! ddk$
end
call search(m, 'We')
return "\<Right>"
else
break break
end end
call search(m, 'We')
return "\<Right>"
break
end end
end end
endfor endfor