Skip to content
Browse files

vim: operator: user: Support register designation

  • Loading branch information...
1 parent bc15a00 commit 2da6728d390c03ea17a7bc2ae29cbf885308a70e @kana committed Sep 7, 2009
Showing with 73 additions and 1 deletion.
  1. +14 −0 autoload/operator/user.vim
  2. +2 −0 doc/operator-user.txt
  3. +14 −1 test/0001.expected
  4. +43 −0 test/0001.input
View
14 autoload/operator/user.vim
@@ -51,13 +51,15 @@ function! operator#user#_define(operator_keyseq, function_name, ...) "{{{2
execute printf(('nnoremap <script> <silent> %s ' .
\ ':<C-u>call operator#user#_set_up(%s)%s<Return>' .
\ '<SID>(count)' .
+ \ '<SID>(register)' .
\ 'g@'),
\ a:operator_keyseq,
\ string(a:function_name),
\ additional_settings)
execute printf(('vnoremap <script> <silent> %s ' .
\ ':<C-u>call operator#user#_set_up(%s)%s<Return>' .
\ 'gv' .
+ \ '<SID>(register)' .
\ 'g@'),
\ a:operator_keyseq,
\ string(a:function_name),
@@ -84,6 +86,7 @@ endfunction
function! operator#user#_set_up(operator_function_name) "{{{2
let &operatorfunc = a:operator_function_name
+ let s:register_designation = v:register
endfunction
@@ -117,9 +120,20 @@ nnoremap <expr> <SID>(count) v:count ? v:count : ''
" vnoremap <expr> <SID>(count) v:count ? v:count : ''
+function! s:register_designation()
+ return s:register_designation == '' ? '' : '"' . s:register_designation
+endfunction
+
+nnoremap <expr> <SID>(register) <SID>register_designation()
+vnoremap <expr> <SID>(register) <SID>register_designation()
+
+
" See operator#user#_do_ex_command() and operator#user#_set_ex_command().
" let s:ex_command = ''
+" See operator#user#_set_up() and s:register_designation()
+" let s:register_designation = ''
+
View
2 doc/operator-user.txt
@@ -226,6 +226,8 @@ CHANGELOG *operator-user-changelog*
- Fix a bug that it rarely fails to select the same text as a given
{motion} in Normal mode. It is caused by a bug in Vim; |v:count1|
may be 0 in some cases.
+ - Fix a bug that register designation ("a, "b, etc) doesn't work for
+ user defiend operators.
0.0.3 2009-09-04T20:11:07+09:00 *operator-user-changelog-0.0.3*
Incompatible change:
View
15 test/0001.expected
@@ -78,5 +78,18 @@ TEST: getline('.', line('.')+1) ==> ['a g n e', 's'] ... FAILED
TEST: getline('.', line('.')+4) ==> ['a', 'g', 'n', 'e', 's'] ... ok
Result: 5 / 6
+===== "register designation for user defined operator"
+TEST: getline('.') ==> '"' ... ok
+TEST: getline('.') ==> '"' ... ok
+TEST: getline('.') ==> 'A' ... ok
+TEST: getline('.') ==> 'x' ... ok
+TEST: getline('.') ==> 'y' ... ok
+TEST: getline('.') ==> '"' ... ok
+TEST: getline('.') ==> '"' ... ok
+TEST: getline('.') ==> 'A' ... ok
+TEST: getline('.') ==> 'x' ... ok
+TEST: getline('.') ==> 'y' ... ok
+Result: 10 / 10
+
===== Total
-Result: 53 / 56
+Result: 63 / 66
View
43 test/0001.input
@@ -240,6 +240,49 @@ endfunction
+function s:test_operator_user_define_0006() "{{{1
+ Title "register designation for user defined operator"
+
+ map _ <Plug>(operator-echo)
+ call operator#user#define('echo', 'TestOperatorFunction6')
+ function! TestOperatorFunction6(motion_wise)
+ put =v:register
+ endfunction
+
+ normal __
+ Assert getline('.') ==> '"'
+
+ normal ""_L
+ Assert getline('.') ==> '"'
+
+ normal "A_w
+ Assert getline('.') ==> 'A'
+
+ normal 3"x_k
+ Assert getline('.') ==> 'x'
+
+ normal "y8_G
+ Assert getline('.') ==> 'y'
+
+ normal v_
+ Assert getline('.') ==> '"'
+
+ normal V""_
+ Assert getline('.') ==> '"'
+
+ normal v"A_
+ Assert getline('.') ==> 'A'
+
+ normal V3"x_
+ Assert getline('.') ==> 'x'
+
+ normal v"y8_
+ Assert getline('.') ==> 'y'
+endfunction
+
+
+
+
Test "{{{1
" __END__

0 comments on commit 2da6728

Please sign in to comment.
Something went wrong with that request. Please try again.