From f8006b7b12c3130b1734f0f973626fe374269472 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Mon, 1 Dec 2014 19:00:05 +0900 Subject: [PATCH] Adding namespaces --- argwrap.vim | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/argwrap.vim b/argwrap.vim index b7eb9c1..b975800 100644 --- a/argwrap.vim +++ b/argwrap.vim @@ -18,13 +18,13 @@ " CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -function! FindRange() +function! argwrap#FindRange() let [l:lineStart, l:colStart] = searchpairpos("(", "", ")", "Wnb") let [l:lineEnd, l:colEnd] = searchpairpos("(", "", ")", "Wn") return {"lineStart": l:lineStart, "colStart": l:colStart, "lineEnd": l:lineEnd, "colEnd": l:colEnd} endfunction -function! ExtractArgumentText(range) +function! argwrap#ExtractArgumentText(range) let l:text = "" for l:lineIndex in range(a:range.lineStart, a:range.lineEnd) @@ -51,7 +51,7 @@ function! ExtractArgumentText(range) return l:text endfunction -function! UpdateScopeStack(stack, char) +function! argwrap#UpdateScope(stack, char) let l:pairs = {"\"": "\"", "\'": "\'", ")": "(", "]": "[", "}": "{"} let l:length = len(a:stack) @@ -62,20 +62,20 @@ function! UpdateScopeStack(stack, char) endif endfunction -function! TrimArgument(text) +function! argwrap#TrimArgument(text) let l:stripped = substitute(a:text, "\\s\\+", "", "") let l:stripped = substitute(l:stripped, "^\\s\\+", "", "") return l:stripped endfunction -function! ExtractArguments(text) +function! argwrap#ExtractArguments(text) let l:stack = [] let l:arguments = [] let l:argument = "" for l:index in range(strlen(a:text)) let l:char = a:text[l:index] - call UpdateScopeStack(l:stack, l:char) + call UpdateScope(l:stack, l:char) if len(l:stack) == 0 && l:char == "," call add(l:arguments, TrimArgument(l:argument)) @@ -89,13 +89,13 @@ function! ExtractArguments(text) return l:arguments endfunction -function! ExtractContainer(range) +function! argwrap#ExtractContainer(range) let l:prefix = getline(a:range.lineStart)[: a:range.colStart - 1] let l:suffix = getline(a:range.lineEnd)[a:range.colEnd - 1:] return {"prefix": l:prefix, "suffix": l:suffix} endfunction -function! WrapContainer(range, container, arguments) +function! argwrap#WrapContainer(range, container, arguments) let l:line = a:range.lineStart call setline(l:line, a:container.prefix) for l:argument in a:arguments @@ -106,13 +106,13 @@ function! WrapContainer(range, container, arguments) call append(l:line, a:container.suffix) endfunction -function! UnwrapContainer(range, container, arguments) +function! argwrap#UnwrapContainer(range, container, arguments) let l:text = a:container.prefix . join(a:arguments, ", ") . a:container.suffix call setline(a:range.lineStart, l:text) exec printf("%d,%dd", a:range.lineStart + 1, a:range.lineEnd) endfunction -function! Unwrap() +function! argwrap#Unwrap() let l:range = FindRange() let l:argText = ExtractArgumentText(l:range) let l:arguments = ExtractArguments(l:argText) @@ -121,7 +121,7 @@ function! Unwrap() call UnwrapContainer(l:range, l:container, l:arguments) endfunction -function! Wrap() +function! argwrap#Wrap() let l:range = FindRange() let l:argText = ExtractArgumentText(l:range) let l:arguments = ExtractArguments(l:argText)