diff options
author | jluehrs2 <jluehrs2@uiuc.edu> | 2008-04-28 01:23:21 -0500 |
---|---|---|
committer | jluehrs2 <jluehrs2@uiuc.edu> | 2008-04-28 01:23:21 -0500 |
commit | a947fe64e577e6ba8dd2701fc6cb40ac6fb05a76 (patch) | |
tree | c7aec4721ceb56ce93514b4c39c0d7b3e610fe44 | |
parent | 7d8db40713259d3c376871386d4eaea376d9359e (diff) | |
download | vim-textobj-a947fe64e577e6ba8dd2701fc6cb40ac6fb05a76.tar.gz vim-textobj-a947fe64e577e6ba8dd2701fc6cb40ac6fb05a76.zip |
convert regex text object to use the new helper function
-rw-r--r-- | vimrc | 26 |
1 files changed, 6 insertions, 20 deletions
@@ -319,10 +319,9 @@ function Textobj(char, callback) endfunction " }}} " / for regex {{{ -function Textobj_regex(inner, operator) +function Textobj_regex(inner, count) let pos = getpos('.') let objstart = 0 - let objlength = 0 let line = strpart(getline('.'), 0, pos[2]) let lines = getline(1, pos[1] - 1) + [line] @@ -330,14 +329,12 @@ function Textobj_regex(inner, operator) for line in reverse(lines) let objstart = match(line, '.*\zs\\\@<!/') if objstart != -1 - let objlength += strlen(line) - objstart + let objstart += 1 break endif let linenum -= 1 - let objlength += strlen(line) + 1 endfor let objstart += a:inner - let objlength -= a:inner let objstartline = linenum let line = strpart(getline('.'), pos[2] - 1) @@ -350,24 +347,13 @@ function Textobj_regex(inner, operator) break endif let linenum += 1 - let objlength += strlen(line) + 1 endfor - let objlength -= a:inner + let objend -= a:inner + let objendline = linenum - call cursor(objstartline, objstart + 1) - let objcmd = "normal! ".a:operator.objlength." " - exe objcmd - if a:operator == 'c' - normal! l - startinsert - elseif a:operator == 'v' - normal! h - endif + return [objstartline, objstart, objendline, objend] endfunction -onoremap <silent>a/ <Esc>:call Textobj_regex(0, v:operator)<CR> -onoremap <silent>i/ <Esc>:call Textobj_regex(1, v:operator)<CR> -xnoremap <silent>a/ <Esc>:call Textobj_regex(0, 'v')<CR> -xnoremap <silent>i/ <Esc>:call Textobj_regex(1, 'v')<CR> +call Textobj('/', 'Textobj_regex') " }}} " f for folds {{{ function Textobj_fold(inner, operator, count) |