diff --git a/argwrap.vim b/argwrap.vim index b017302..3b45a19 100644 --- a/argwrap.vim +++ b/argwrap.vim @@ -96,10 +96,17 @@ function! argwrap#extractContainer(range) endfunction function! argwrap#wrapContainer(range, container, arguments) - let l:line = a:range.lineStart + let l:argCount = len(a:arguments) + let l:line = a:range.lineStart + call setline(l:line, a:container.prefix) - for l:argument in a:arguments - call append(l:line, l:argument . ",") + for l:index in range(l:argCount) + let l:text = a:arguments[l:index] + if l:index < l:argCount - 1 + let l:text .= "," + endif + + call append(l:line, l:text) let l:line += 1 exec printf("%s>", l:line) endfor diff --git a/sample.txt b/sample.txt index faba30b..72271f2 100644 --- a/sample.txt +++ b/sample.txt @@ -1,16 +1,15 @@ -a = Foo(a, [b, z], "hello, world", c, ) - -Foo(a, b) +a = Foo(a, [b, z], "hello, world", c) Foo( a, - [b, c], - d + b ) +Foo(a, [b, c], d) + Foo( - a - [b, "c"] + a, + [b, "c"], d ) @@ -20,11 +19,4 @@ Foo( d ) -Foo( - a, - [ - b, - c - ], - d -) +Foo(a, [b, c], d)