mirror of
https://github.com/Raimondi/delimitMate.git
synced 2025-12-06 12:44:27 +08:00
Fix space expansion. Closes #68.
This commit is contained in:
@@ -238,6 +238,19 @@ function! delimitMate#RmBuffer(num) " {{{
|
|||||||
return ""
|
return ""
|
||||||
endfunction " }}}
|
endfunction " }}}
|
||||||
|
|
||||||
|
function! delimitMate#IsSmartQuote(char) "{{{
|
||||||
|
if !b:_l_delimitMate_smart_quotes
|
||||||
|
return 0
|
||||||
|
endif
|
||||||
|
let char_at = delimitMate#GetCharFromCursor(0)
|
||||||
|
let char_before = delimitMate#GetCharFromCursor(-1)
|
||||||
|
let word_before = char_before =~ '\w'
|
||||||
|
let word_at = char_at =~ '\w'
|
||||||
|
let escaped = delimitMate#CursorIdx() >= 1 && delimitMate#GetCharFromCursor(-1) == '\'
|
||||||
|
let result = word_before || escaped || word_at
|
||||||
|
return result
|
||||||
|
endfunction "delimitMate#SmartQuote }}}
|
||||||
|
|
||||||
" }}}
|
" }}}
|
||||||
|
|
||||||
" Doers {{{
|
" Doers {{{
|
||||||
@@ -304,21 +317,20 @@ function! delimitMate#QuoteDelim(char) "{{{
|
|||||||
if delimitMate#IsForbidden(a:char)
|
if delimitMate#IsForbidden(a:char)
|
||||||
return a:char
|
return a:char
|
||||||
endif
|
endif
|
||||||
if delimitMate#GetCharFromCursor(-1) == "\\"
|
let char_at = delimitMate#GetCharFromCursor(0)
|
||||||
" Seems like a escaped character, insert one quotation mark.
|
let char_before = delimitMate#GetCharFromCursor(-1)
|
||||||
|
if delimitMate#IsSmartQuote(a:char)
|
||||||
|
" Seems like a smart quote, insert a single char.
|
||||||
return a:char
|
return a:char
|
||||||
"elseif line[col + 1] == a:char &&
|
"elseif line[col + 1] == a:char &&
|
||||||
elseif delimitMate#GetCharFromCursor(0) == a:char &&
|
elseif char_at == a:char &&
|
||||||
\ index(b:_l_delimitMate_nesting_quotes, a:char) < 0
|
\ index(b:_l_delimitMate_nesting_quotes, a:char) < 0
|
||||||
" Get out of the string.
|
" Get out of the string.
|
||||||
return a:char . delimitMate#Del()
|
return a:char . delimitMate#Del()
|
||||||
elseif (delimitMate#GetCharFromCursor(-1) =~ '\w' && a:char == "'") ||
|
elseif (char_before =~ '\w' && a:char == "'")
|
||||||
\ (b:_l_delimitMate_smart_quotes &&
|
" Seems like an apostrophe, insert a single quote.
|
||||||
\ (delimitMate#GetCharFromCursor(-1) =~ '\w' ||
|
|
||||||
\ delimitMate#GetCharFromCursor(0) =~ '\w'))
|
|
||||||
" Seems like an apostrophe or a smart quote case, insert a single quote.
|
|
||||||
return a:char
|
return a:char
|
||||||
elseif (delimitMate#GetCharFromCursor(-1) == a:char && delimitMate#GetCharFromCursor(0) != a:char) && b:_l_delimitMate_smart_quotes
|
elseif (char_before == a:char && char_at != a:char) && b:_l_delimitMate_smart_quotes
|
||||||
" Seems like we have an unbalanced quote, insert one quotation mark and jump to the middle.
|
" Seems like we have an unbalanced quote, insert one quotation mark and jump to the middle.
|
||||||
call delimitMate#AddToBuffer(a:char)
|
call delimitMate#AddToBuffer(a:char)
|
||||||
return delimitMate#WriteAfter(a:char)
|
return delimitMate#WriteAfter(a:char)
|
||||||
@@ -409,7 +421,8 @@ function! delimitMate#ExpandSpace() "{{{
|
|||||||
if delimitMate#IsForbidden("\<Space>")
|
if delimitMate#IsForbidden("\<Space>")
|
||||||
return "\<Space>"
|
return "\<Space>"
|
||||||
endif
|
endif
|
||||||
if delimitMate#WithinEmptyPair()
|
let escaped = delimitMate#CursorIdx() >= 2 && delimitMate#GetCharFromCursor(-2) == '\'
|
||||||
|
if delimitMate#WithinEmptyPair() && !escaped
|
||||||
" Expand:
|
" Expand:
|
||||||
call delimitMate#AddToBuffer('s')
|
call delimitMate#AddToBuffer('s')
|
||||||
return delimitMate#WriteAfter(' ') . "\<Space>"
|
return delimitMate#WriteAfter(' ') . "\<Space>"
|
||||||
|
|||||||
Reference in New Issue
Block a user