From b8b1a476cd6aec65d47bc6c6eefa60a45d87e677 Mon Sep 17 00:00:00 2001 From: jluehrs2 Date: Tue, 29 Apr 2008 20:19:13 -0500 Subject: make the argument text object work across multiple lines. inner == 0 is probably not working yet, and empty lines still mess things up --- vimrc | 48 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/vimrc b/vimrc index 2db2339..4d52461 100644 --- a/vimrc +++ b/vimrc @@ -400,10 +400,48 @@ call Textobj('f', 'Textobj_fold') " }}} " , for function arguments {{{ function Textobj_arg(inner, count) - let line = getline('.') - let curcol = col('.') - let argbegin = matchend(strpart(line, 0, curcol), '.*\%(,\s*\|(\)') + 1 - let argend = match(strpart(line, curcol), '\zs.\?\%(,\|)\)') + curcol + 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 argbegin = matchend(line, '.*\%(,\s*\|(\)') + 1 + if argbegin != 0 + if argbegin > strlen(line) + let linenum += 1 + let argbegin = matchend(getline(linenum), '^\s*') + 1 + endif + break + endif + let linenum -= 1 + endfor + if argbegin == 0 + throw 'no-match' + endif + let argstartline = linenum + + let line = strpart(getline(pos[1]), pos[2] - 1) + let lines = [line] + getline(pos[1] + 1, line('$')) + let linenum = pos[1] + for line in lines + let argend = match(line, '\zs.\?\%(,\|)\)') + 1 + if argend != 0 + if linenum == pos[1] + let argend += pos[2] - 1 + endif + if argend == 1 && getline(linenum)[argend - 1] == ')' + let linenum -= 1 + let argend = strlen(getline(linenum)) + endif + break + endif + let linenum += 1 + endfor + if argend == 0 + throw 'no-match' + endif + let argendline = linenum if a:inner == 0 if line[argend] == ')' && line[argbegin - 2] != '(' @@ -415,7 +453,7 @@ function Textobj_arg(inner, count) endif endif - return [line('.'), argbegin, line('.'), argend] + return [argstartline, argbegin, argendline, argend] endfunction call Textobj(',', 'Textobj_arg') " }}} -- cgit v1.2.3-54-g00ecf