diff options
author | Jesse Luehrs <doy@tozt.net> | 2018-03-08 22:41:30 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2018-03-08 22:53:03 -0500 |
commit | 666f03d346c79c61928412b761cdc27027c8ef58 (patch) | |
tree | c7fc811a78624f89587b03f16e8137e54880baef | |
parent | ede742dca0477d08edaaa14cc178bd80bd181126 (diff) | |
download | vim-textobj-666f03d346c79c61928412b761cdc27027c8ef58.tar.gz vim-textobj-666f03d346c79c61928412b761cdc27027c8ef58.zip |
improve the configuration interface
-rw-r--r-- | plugin/textobj.vim | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/plugin/textobj.vim b/plugin/textobj.vim index bb620fe..55eb1ff 100644 --- a/plugin/textobj.vim +++ b/plugin/textobj.vim @@ -62,14 +62,15 @@ endfunction " }}} " Text object definitions {{{ " arbitrary paired symbols (/ for regex, etc) {{{ -function Textobj_paired(inner, count, char) +function Textobj_paired(inner, count, ...) + let char = a:1 let pos = getpos('.') let line = strpart(getline(pos[1]), 0, pos[2]) let lines = getline(1, pos[1] - 1) + [line] let linenum = pos[1] for line in reverse(lines) - let objstart = match(line, '.*\zs\\\@<!'.a:char) + 1 + let objstart = match(line, '.*\zs\\\@<!'.char) + 1 if objstart != 0 break endif @@ -85,14 +86,14 @@ function Textobj_paired(inner, count, char) let lines = [line] + getline(pos[1] + 1, line('$')) let linenum = pos[1] for line in lines - let objend = match(line, '\\\@<!'.a:char) + 1 + let objend = match(line, '\\\@<!'.char) + 1 if objend != 0 if linenum == pos[1] " have to account for the possibility of a split escape " sequence if objend == 1 if getline(pos[1])[pos[2] - 2] == '\' - let objend = match(line, '\\\@<!'.a:char, 1) + 1 + let objend = match(line, '\\\@<!'.char, 1) + 1 if objend == 0 let linenum += 1 continue @@ -119,7 +120,7 @@ function Textobj_paired(inner, count, char) endfunction " }}} " f for folds {{{ -function Textobj_fold(inner, count) +function Textobj_fold(inner, count, ...) if foldlevel(line('.')) == 0 throw 'no-match' endif @@ -132,7 +133,7 @@ function Textobj_fold(inner, count) endfunction " }}} " , for function arguments {{{ -function Textobj_arg(inner, count) +function Textobj_arg(inner, count, ...) let pos = getpos('.') let curchar = getline(pos[1])[pos[2] - 1] if curchar == ',' @@ -236,8 +237,19 @@ endfunction " }}} " }}} " Text object loading {{{ -for object in g:Textobj_defs - call call('Textobj', object) -endfor -unlet object +function s:load_textobjs(defs) + for l:char in keys(g:textobj_defs) + let l:extra_args = g:textobj_defs[l:char] + let l:callback = remove(l:extra_args, 0) + if len(l:extra_args) == 0 + call add(l:extra_args, l:char) + endif + let l:args = [l:char, 'Textobj_'.l:callback] + call extend(l:args, l:extra_args) + call call('Textobj', l:args) + endfor +endfunction +if exists('g:textobj_defs') + call s:load_textobjs(g:textobj_defs) +endif " }}} |