mirror of
https://github.com/Raimondi/delimitMate.git
synced 2025-12-07 21:24:51 +08:00
Consider space and CR expansions when jumping over. Closes #95.
This commit is contained in:
@@ -10,30 +10,35 @@
|
|||||||
|
|
||||||
"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 char = delimitMate#GetCharFromCursor(0)
|
let char = delimitMate#GetCharFromCursor(0)
|
||||||
let list = b:_l_delimitMate_right_delims + b:_l_delimitMate_quotes_list
|
let list = b:_l_delimitMate_right_delims + b:_l_delimitMate_quotes_list
|
||||||
|
|
||||||
" Closing delimiter on the right.
|
" Closing delimiter on the right.
|
||||||
if index(list, char) > -1
|
if (!a:0 && index(list, char) > -1)
|
||||||
|
\ || (a:0 && char == a:1)
|
||||||
return 1
|
return 1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Closing delimiter with space expansion.
|
" Closing delimiter with space expansion.
|
||||||
let nchar = delimitMate#GetCharFromCursor(1)
|
let nchar = delimitMate#GetCharFromCursor(1)
|
||||||
if b:_l_delimitMate_expand_space && char == " "
|
if !a:0 && b:_l_delimitMate_expand_space && char == " "
|
||||||
if index(list, nchar) > -1
|
if index(list, nchar) > -1
|
||||||
return 1
|
return 2
|
||||||
endif
|
endif
|
||||||
|
elseif a:0 && b:_l_delimitMate_expand_space && nchar == a:1
|
||||||
|
return 3
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Closing delimiter with CR expansion.
|
" Closing delimiter with CR expansion.
|
||||||
let uchar = getline(line('.') + 1)[0]
|
let uchar = matchstr(getline(line('.') + 1), '^\s*\zs\S')
|
||||||
if b:_l_delimitMate_expand_cr && char == ""
|
if !a:0 && b:_l_delimitMate_expand_cr && char == ""
|
||||||
if index(list, uchar) > -1
|
if index(list, uchar) > -1
|
||||||
return 1
|
return 4
|
||||||
endif
|
endif
|
||||||
|
elseif a:0 && b:_l_delimitMate_expand_cr && uchar == a:1
|
||||||
|
return 5
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
@@ -343,8 +348,15 @@ function! delimitMate#JumpOut(char) "{{{
|
|||||||
if delimitMate#IsForbidden(a:char)
|
if delimitMate#IsForbidden(a:char)
|
||||||
return a:char
|
return a:char
|
||||||
endif
|
endif
|
||||||
if delimitMate#GetCharFromCursor(0) == a:char
|
let jump = delimitMate#ShouldJump(a:char)
|
||||||
|
if jump == 1
|
||||||
return a:char . delimitMate#Del()
|
return a:char . delimitMate#Del()
|
||||||
|
elseif jump == 3
|
||||||
|
return ' '.a:char.delimitMate#Del().delimitMate#Del()
|
||||||
|
elseif jump == 5
|
||||||
|
call delimitMate#FlushBuffer()
|
||||||
|
return "\<CR>" . matchstr(getline(line('.') + 1), '^\s*\S')
|
||||||
|
\ . delimitMate#Del() . "\<Del>"
|
||||||
else
|
else
|
||||||
return a:char
|
return a:char
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -10,3 +10,11 @@ $(document).ready(function() {
|
|||||||
x
|
x
|
||||||
})
|
})
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
# Issue #95
|
||||||
|
new
|
||||||
|
exec "normal i(\<CR>test)x"
|
||||||
|
================================================================================
|
||||||
|
(
|
||||||
|
test
|
||||||
|
)x
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|||||||
6
test/expand_space.txt
Normal file
6
test/expand_space.txt
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
# Issue #95
|
||||||
|
new
|
||||||
|
exec "normal i( test)x"
|
||||||
|
================================================================================
|
||||||
|
( test )x
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
42
test/expand_space.vim
Normal file
42
test/expand_space.vim
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
let g:delimitMate_expand_space = 1
|
||||||
|
"DelimitMateReload
|
||||||
|
let lines = readfile(expand('<sfile>:t:r').'.txt')
|
||||||
|
call vimtest#StartTap()
|
||||||
|
let testsnumber = len(filter(copy(lines), 'v:val =~ ''^=\{80}$'''))
|
||||||
|
call vimtap#Plan(testsnumber)
|
||||||
|
let tcount = 1
|
||||||
|
let expect = 0
|
||||||
|
let evaluate = 0
|
||||||
|
for item in lines
|
||||||
|
if item =~ '^=\{80}$'
|
||||||
|
let expect = 1
|
||||||
|
let expected = []
|
||||||
|
continue
|
||||||
|
endif
|
||||||
|
|
||||||
|
if item =~ '^#\|^\s*$' && expect == 0
|
||||||
|
" A comment or empty line.
|
||||||
|
continue
|
||||||
|
endif
|
||||||
|
if ! expect
|
||||||
|
" A command.
|
||||||
|
exec item
|
||||||
|
call vimtap#Diag(item)
|
||||||
|
continue
|
||||||
|
endif
|
||||||
|
if item =~ '^-\{80}$'
|
||||||
|
let expect = 0
|
||||||
|
endif
|
||||||
|
if expect
|
||||||
|
call add(expected, item)
|
||||||
|
continue
|
||||||
|
endif
|
||||||
|
let lines = getline(1, line('$'))
|
||||||
|
let passed = lines == expected
|
||||||
|
echom string(lines)
|
||||||
|
echom string(expected)
|
||||||
|
call vimtap#Ok(passed, string(expected) .
|
||||||
|
\ (passed ? ' =' : ' !') . '= ' . string(lines))
|
||||||
|
let tcount += 1
|
||||||
|
endfor
|
||||||
|
call vimtest#Quit()
|
||||||
Reference in New Issue
Block a user