1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
function! Target()
let start_position = getpos('.')
normal! e
let end_position = getpos('.')
return ['v', start_position, end_position]
endfunction
function! s:target()
let start_position = getpos('.')
normal! w
let end_position = getpos('.')
return ['v', start_position, end_position]
endfunction
call textobj#user#plugin('newstyle', {
\ 'select-pattern': {
\ 'pattern': 'pat*ern',
\ 'select': ['ansp', 'insp'],
\ },
\ 'select-function-global': {
\ 'select-function': 'Target',
\ 'select': ['ansfg', 'insfg'],
\ },
\ 'select-function-local': {
\ 'sfile': expand('<sfile>:p'),
\ 'select-function': 's:target',
\ 'select': ['ansfs', 'insfs'],
\ },
\ })
call textobj#user#plugin('oldstyle', {
\ 'select-pattern': {
\ '*pattern*': 'pat*ern',
\ 'select': ['aosp', 'iosp'],
\ },
\ 'select-function-global': {
\ '*select-function*': 'Target',
\ 'select': ['aosfg', 'iosfg'],
\ },
\ 'select-function-local': {
\ '*sfile*': expand('<sfile>:p'),
\ '*select-function*': 's:target',
\ 'select': ['aosfs', 'iosfs'],
\ },
\ })
describe '"*pattern*"'
before
new
call setline(1, 'pat patttttern put')
end
after
close!
end
it 'is treated as same as "pattern"'
let @0 = ''
normal! gg0
normal yaosp
let old_result = @0
let @0 = ''
normal! gg0
normal yansp
let new_result = @0
Expect old_result ==# new_result
Expect old_result ==# 'patttttern'
end
end
describe '"*{property}-function*"'
before
new
call setline(1, 'pat patttttern put')
end
after
close!
end
it 'is treated as same as "{property}-function"'
let @0 = ''
normal! gg0
normal yaosfg
let old_result = @0
let @0 = ''
normal! gg0
normal yansfg
let new_result = @0
Expect old_result ==# new_result
Expect old_result ==# 'pat'
end
end
describe '"*sfile*"'
before
new
call setline(1, 'pat patttttern put')
end
after
close!
end
it 'is treated as same as "sfile"'
let @0 = ''
normal! gg0
normal yaosfs
let old_result = @0
let @0 = ''
normal! gg0
normal yansfs
let new_result = @0
Expect old_result ==# new_result
Expect old_result ==# 'pat p'
end
end
|