From 0b4d014c2e42fa5666c7992d66491a639d361b2b Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Mon, 1 Dec 2014 12:31:53 +0900 Subject: [PATCH] More fixup --- sample.txt | 4 ++-- wrap.vim | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/sample.txt b/sample.txt index 6f2077d..55dbdd9 100644 --- a/sample.txt +++ b/sample.txt @@ -1,4 +1,4 @@ -Foo(a, b, c) +Foo(a, [b, z], c) Foo( a, @@ -15,7 +15,7 @@ Foo( a, [ b, - c + "c" ], d ) diff --git a/wrap.vim b/wrap.vim index f953765..a32498a 100644 --- a/wrap.vim +++ b/wrap.vim @@ -47,7 +47,10 @@ function! ExtractText(range) endif if l:extractStart < l:extractEnd - let l:text .= l:lineText[l:extractStart : l:extractEnd - 1] + let l:extract = l:lineText[l:extractStart : l:extractEnd - 1] + let l:extract = substitute(l:extract, "^\\s\\+", "", "g") + let l:extract = substitute(l:extract, ",$", ", ", "g") + let l:text .= l:extract endif endfor @@ -65,6 +68,12 @@ function! UpdateScopeStack(stack, char) endif endfunction +function! StripArgument(text) + let l:stripped = substitute(a:text, "\\s\\+", "", "") + let l:stripped = substitute(l:stripped, "^\\s\\+", "", "") + return l:stripped +endfunction + function! ExtractArguments(text) let l:stack = [] let l:arguments = [] @@ -75,14 +84,14 @@ function! ExtractArguments(text) call UpdateScopeStack(l:stack, l:char) if len(l:stack) == 0 && l:char == "," - call add(l:arguments, l:argument) + call add(l:arguments, StripArgument(l:argument)) let l:argument = "" else let l:argument .= l:char endif endfor - call add(l:arguments, l:argument) + call add(l:arguments, StripArgument(l:argument)) return l:arguments endfunction