mirror of
https://github.com/Raimondi/delimitMate.git
synced 2025-12-16 01:17:07 +08:00
Replace GeetChar*Cursor with GetCharFromCursor.
This commit is contained in:
@@ -8,39 +8,32 @@
|
|||||||
|
|
||||||
" Utilities {{{
|
" Utilities {{{
|
||||||
|
|
||||||
let delimitMate_loaded = 1
|
"let delimitMate_loaded = 1
|
||||||
|
|
||||||
function! delimitMate#ShouldJump() "{{{
|
function! delimitMate#ShouldJump() "{{{
|
||||||
" Returns 1 if the next character is a closing delimiter.
|
" Returns 1 if the next character is a closing delimiter.
|
||||||
let col = col('.')
|
let char = delimitMate#GetCharFromCursor(0)
|
||||||
let lcol = col('$')
|
let list = b:_l_delimitMate_right_delims + b:_l_delimitMate_quotes_list
|
||||||
let char = delimitMate#GetCharUnderCursor()
|
|
||||||
|
|
||||||
" Closing delimiter on the right.
|
" Closing delimiter on the right.
|
||||||
for cdel in b:_l_delimitMate_right_delims + b:_l_delimitMate_quotes_list
|
if index(list, char) > -1
|
||||||
if char == cdel
|
return 1
|
||||||
return 1
|
endif
|
||||||
endif
|
|
||||||
endfor
|
|
||||||
|
|
||||||
" Closing delimiter with space expansion.
|
" Closing delimiter with space expansion.
|
||||||
let nchar = getline('.')[col]
|
let nchar = delimitMate#GetCharFromCursor(1)
|
||||||
if b:_l_delimitMate_expand_space && char == " "
|
if b:_l_delimitMate_expand_space && char == " "
|
||||||
for cdel in b:_l_delimitMate_right_delims + b:_l_delimitMate_quotes_list
|
if index(list, nchar) > -1
|
||||||
if nchar == cdel
|
return 1
|
||||||
return 1
|
endif
|
||||||
endif
|
|
||||||
endfor
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Closing delimiter with CR expansion.
|
" Closing delimiter with CR expansion.
|
||||||
let uchar = getline(line('.') + 1)[0]
|
let uchar = getline(line('.') + 1)[0]
|
||||||
if b:_l_delimitMate_expand_cr && char == ""
|
if b:_l_delimitMate_expand_cr && char == ""
|
||||||
for cdel in b:_l_delimitMate_right_delims + b:_l_delimitMate_quotes_list
|
if index(list, uchar) > -1
|
||||||
if uchar == cdel
|
return 1
|
||||||
return 1
|
endif
|
||||||
endif
|
|
||||||
endfor
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
@@ -60,19 +53,19 @@ function! delimitMate#IsEmptyPair(str) "{{{
|
|||||||
return 0
|
return 0
|
||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
|
|
||||||
function! delimitMate#GetCharBeforeCursor() "{{{
|
function! delimitMate#GetCharFromCursor(...) "{{{
|
||||||
let line = getline('.')
|
let idx = col('.') - 1
|
||||||
let col = col('.') - 1
|
if !a:0 || (a:0 && a:1 >= 0)
|
||||||
" get char before the cursor.
|
" Get chars from cursor.
|
||||||
return matchstr(line[: col - 1], '.$')
|
let line = getline('.')[idx :]
|
||||||
endfunction "delimitMate#GetCharUnderCursor }}}
|
let pos = a:0 ? a:1 : 0
|
||||||
|
return matchstr(line, '^'.repeat('.', pos).'\zs.')
|
||||||
function! delimitMate#GetCharUnderCursor() "{{{
|
endif
|
||||||
let line = getline('.')
|
" Get chars behind cursor.
|
||||||
let col = col('.') - 1
|
let line = getline('.')[: idx - 1]
|
||||||
" get char under the cursor.
|
let pos = 0 - (1 + a:1)
|
||||||
return matchstr(line[col :], '^.')
|
return matchstr(line, '.\ze'.repeat('.', pos).'$')
|
||||||
endfunction "delimitMate#GetCharUnderCursor }}}
|
endfunction "delimitMate#GetCharFromCursor }}}
|
||||||
|
|
||||||
function! delimitMate#IsCRExpansion() " {{{
|
function! delimitMate#IsCRExpansion() " {{{
|
||||||
let nchar = getline(line('.')-1)[-1:]
|
let nchar = getline(line('.')-1)[-1:]
|
||||||
@@ -114,9 +107,9 @@ endfunction " }}} IsSpaceExpansion()
|
|||||||
|
|
||||||
function! delimitMate#WithinEmptyPair() "{{{
|
function! delimitMate#WithinEmptyPair() "{{{
|
||||||
" get char before the cursor.
|
" get char before the cursor.
|
||||||
let char1 = delimitMate#GetCharBeforeCursor()
|
let char1 = delimitMate#GetCharFromCursor(-1)
|
||||||
" get char under the cursor.
|
" get char under the cursor.
|
||||||
let char2 = delimitMate#GetCharUnderCursor()
|
let char2 = delimitMate#GetCharFromCursor(0)
|
||||||
return delimitMate#IsEmptyPair( char1.char2 )
|
return delimitMate#IsEmptyPair( char1.char2 )
|
||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
|
|
||||||
@@ -249,10 +242,10 @@ function! delimitMate#SkipDelim(char) "{{{
|
|||||||
let col = col('.') - 1
|
let col = col('.') - 1
|
||||||
let line = getline('.')
|
let line = getline('.')
|
||||||
if col > 0
|
if col > 0
|
||||||
let cur = delimitMate#GetCharUnderCursor()
|
let cur = delimitMate#GetCharFromCursor(0)
|
||||||
let pre = delimitMate#GetCharBeforeCursor()
|
let pre = delimitMate#GetCharFromCursor(-1)
|
||||||
else
|
else
|
||||||
let cur = delimitMate#GetCharUnderCursor()
|
let cur = delimitMate#GetCharFromCursor(0)
|
||||||
let pre = ""
|
let pre = ""
|
||||||
endif
|
endif
|
||||||
if pre == "\\"
|
if pre == "\\"
|
||||||
@@ -305,21 +298,21 @@ function! delimitMate#QuoteDelim(char) "{{{
|
|||||||
if delimitMate#IsForbidden(a:char)
|
if delimitMate#IsForbidden(a:char)
|
||||||
return a:char
|
return a:char
|
||||||
endif
|
endif
|
||||||
if delimitMate#GetCharBeforeCursor() == "\\"
|
if delimitMate#GetCharFromCursor(-1) == "\\"
|
||||||
" Seems like a escaped character, insert one quotation mark.
|
" Seems like a escaped character, insert one quotation mark.
|
||||||
return a:char
|
return a:char
|
||||||
"elseif line[col + 1] == a:char &&
|
"elseif line[col + 1] == a:char &&
|
||||||
elseif delimitMate#GetCharUnderCursor() == a:char &&
|
elseif delimitMate#GetCharFromCursor(0) == 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#GetCharBeforeCursor() =~ '\w' && a:char == "'") ||
|
elseif (delimitMate#GetCharFromCursor(-1) =~ '\w' && a:char == "'") ||
|
||||||
\ (b:_l_delimitMate_smart_quotes &&
|
\ (b:_l_delimitMate_smart_quotes &&
|
||||||
\ (delimitMate#GetCharBeforeCursor() =~ '\w' ||
|
\ (delimitMate#GetCharFromCursor(-1) =~ '\w' ||
|
||||||
\ delimitMate#GetCharUnderCursor() =~ '\w'))
|
\ delimitMate#GetCharFromCursor(0) =~ '\w'))
|
||||||
" Seems like an apostrophe or a smart quote case, insert a single quote.
|
" Seems like an apostrophe or a smart quote case, insert a single quote.
|
||||||
return a:char
|
return a:char
|
||||||
elseif (delimitMate#GetCharBeforeCursor() == a:char && delimitMate#GetCharUnderCursor() != a:char) && b:_l_delimitMate_smart_quotes
|
elseif (delimitMate#GetCharFromCursor(-1) == a:char && delimitMate#GetCharFromCursor(0) != 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 insert(b:_l_delimitMate_buffer, a:char)
|
call insert(b:_l_delimitMate_buffer, a:char)
|
||||||
return delimitMate#WriteAfter(a:char)
|
return delimitMate#WriteAfter(a:char)
|
||||||
@@ -335,7 +328,7 @@ function! delimitMate#JumpOut(char) "{{{
|
|||||||
if delimitMate#IsForbidden(a:char)
|
if delimitMate#IsForbidden(a:char)
|
||||||
return a:char
|
return a:char
|
||||||
endif
|
endif
|
||||||
if delimitMate#GetCharUnderCursor() == a:char
|
if delimitMate#GetCharFromCursor(0) == a:char
|
||||||
return a:char . delimitMate#Del()
|
return a:char . delimitMate#Del()
|
||||||
else
|
else
|
||||||
return a:char
|
return a:char
|
||||||
@@ -350,7 +343,7 @@ function! delimitMate#JumpAny(key) " {{{
|
|||||||
return a:key
|
return a:key
|
||||||
endif
|
endif
|
||||||
" Let's get the character on the right.
|
" Let's get the character on the right.
|
||||||
let char = delimitMate#GetCharUnderCursor()
|
let char = delimitMate#GetCharFromCursor(0)
|
||||||
if char == " "
|
if char == " "
|
||||||
" Space expansion.
|
" Space expansion.
|
||||||
"let char = char . getline('.')[col('.')] . delimitMate#Del()
|
"let char = char . getline('.')[col('.')] . delimitMate#Del()
|
||||||
@@ -362,7 +355,7 @@ function! delimitMate#JumpAny(key) " {{{
|
|||||||
let b:_l_delimitMate_buffer = []
|
let b:_l_delimitMate_buffer = []
|
||||||
return "\<CR>" . getline(line('.') + 1)[0] . delimitMate#Del() . "\<Del>"
|
return "\<CR>" . getline(line('.') + 1)[0] . delimitMate#Del() . "\<Del>"
|
||||||
else
|
else
|
||||||
call delimitMate#RmBuffer(1)
|
"call delimitMate#RmBuffer(1)
|
||||||
return char . delimitMate#Del()
|
return char . delimitMate#Del()
|
||||||
endif
|
endif
|
||||||
endfunction " delimitMate#JumpAny() }}}
|
endfunction " delimitMate#JumpAny() }}}
|
||||||
@@ -396,7 +389,7 @@ function! delimitMate#ExpandReturn() "{{{
|
|||||||
if delimitMate#WithinEmptyPair()
|
if delimitMate#WithinEmptyPair()
|
||||||
" Expand:
|
" Expand:
|
||||||
call delimitMate#FlushBuffer()
|
call delimitMate#FlushBuffer()
|
||||||
let char = delimitMate#GetCharUnderCursor()
|
let char = delimitMate#GetCharFromCursor(0)
|
||||||
"return "\<Esc>a\<CR>x\<CR>\<Esc>k$\"_xa"
|
"return "\<Esc>a\<CR>x\<CR>\<Esc>k$\"_xa"
|
||||||
"return "\<Esc>a\<CR>\<UP>\<Esc>o"
|
"return "\<Esc>a\<CR>\<UP>\<Esc>o"
|
||||||
call feedkeys("\<Esc>a\<Del>\<Esc>ox\<BS>\<CR>".char."\<Esc>kA", 't')
|
call feedkeys("\<Esc>a\<Del>\<Esc>ox\<BS>\<CR>".char."\<Esc>kA", 't')
|
||||||
@@ -467,7 +460,9 @@ function! delimitMate#Finish(move_back) " {{{
|
|||||||
let lefts = lefts . "\<Left>"
|
let lefts = lefts . "\<Left>"
|
||||||
let i += 1
|
let i += 1
|
||||||
endwhile
|
endwhile
|
||||||
return substitute(buffer, "s", "\<Space>", 'g') . lefts
|
let result = substitute(buffer, "s", "\<Space>", 'g') . lefts
|
||||||
|
echo 'buffer: '.result
|
||||||
|
return result
|
||||||
endif
|
endif
|
||||||
return ''
|
return ''
|
||||||
endfunction " }}}
|
endfunction " }}}
|
||||||
|
|||||||
Reference in New Issue
Block a user