From ebe4380188e7a03432229270f5c980fa4f422121 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Wed, 25 Mar 2015 14:17:45 +0900 Subject: [PATCH] Adding g:argwrap_wrap_closing_brace , getting rid of g_argwrap_wrap_style --- README.md | 20 ++++++++++------- autoload/argwrap.vim | 52 +++++++++++++++----------------------------- doc/argwrap.txt | 22 ++++++++++++------- 3 files changed, 43 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index e56f7a3..029b32c 100644 --- a/README.md +++ b/README.md @@ -27,11 +27,15 @@ information. 3. You can customize the wrapping/unwrapping behavior of this extension by setting values for any of the following optional global variables in your `.vimrc` file: - * `g:argwrap_wrap_style` + * `g:argwrap_wrap_closing_brace` - Specifies the style in which arguments should be wrapped. + Specifies if the closing brace should be wrapped to a new line. This setting is helpful when working with + languages such as Google's [Go](https://golang.org/project/), which enforce coding style during compliation. - `'default'` argument wrapping: + Specifies if the closing brace should be wrapped to a new line. This setting is helpful for languages such as + Google's which enforce this style during compliation. + + Brace wrapping enabled (default) ``` Foo( @@ -41,13 +45,13 @@ information. ) ``` - `'bx'` argument wrapping: + Brace wrapping disabled (`let g:argwrap_wrap_closing_brace = 0`) ``` - Foo(wibble - , wobble - , wubble - ) + Foo( + wibble, + wobble, + wubble) ``` * `g:argwrap_padded_braces` diff --git a/autoload/argwrap.vim b/autoload/argwrap.vim index 0c0a95b..904a671 100644 --- a/autoload/argwrap.vim +++ b/autoload/argwrap.vim @@ -139,45 +139,27 @@ function! argwrap#extractContainer(range) return {'indent': l:indent, 'prefix': l:prefix, 'suffix': l:suffix} endfunction -function! argwrap#wrapContainer(range, container, arguments, style) +function! argwrap#wrapContainer(range, container, arguments, wrapBrace) let l:argCount = len(a:arguments) let l:line = a:range.lineStart - if a:style ==? 'default' - call setline(l:line, a:container.indent . a:container.prefix) + call setline(l:line, a:container.indent . a:container.prefix) - for l:index in range(l:argCount) - let l:text = a:container.indent . 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 - - call append(l:line, a:container.indent . a:container.suffix) - elseif a:style ==? 'bx' - let l:lineText = a:container.indent . a:container.prefix - if l:argCount > 0 - let l:lineText .= a:arguments[0] - let l:arguments = a:arguments[1:] - let l:argCount -= 1 + for l:index in range(l:argCount) + let l:text = a:container.indent . a:arguments[l:index] + if l:index < l:argCount - 1 + let l:text .= ',' + elseif !a:wrapBrace + let l:text .= a:container.suffix endif - call setline(l:line, l:lineText) - - for l:index in range(l:argCount) - let l:text = a:container.indent . ', ' . l:arguments[l:index] - - call append(l:line, l:text) - let l:line += 1 - exec printf('%s>', l:line) - endfor + call append(l:line, l:text) + let l:line += 1 + exec printf('%s>', l:line) + endfor + if a:wrapBrace call append(l:line, a:container.indent . a:container.suffix) - exec printf('%s>', l:line + 1) endif endfunction @@ -195,10 +177,10 @@ function! argwrap#unwrapContainer(range, container, arguments, padded) endfunction function! argwrap#toggle() - if exists('g:argwrap_wrap_style') - let l:style = g:argwrap_wrap_style + if exists('g:argwrap_wrap_closing_brace') + let l:wrapBrace = g:argwrap_wrap_closing_brace else - let l:style = 'default' + let l:wrapBrace = 1 endif if exists('g:argwrap_padded_braces') @@ -222,7 +204,7 @@ function! argwrap#toggle() let l:container = argwrap#extractContainer(l:range) if l:range.lineStart == l:range.lineEnd - call argwrap#wrapContainer(l:range, l:container, l:arguments, l:style) + call argwrap#wrapContainer(l:range, l:container, l:arguments, l:wrapBrace) else call argwrap#unwrapContainer(l:range, l:container, l:arguments, l:padded) endif diff --git a/doc/argwrap.txt b/doc/argwrap.txt index 5743c10..6f3d14f 100644 --- a/doc/argwrap.txt +++ b/doc/argwrap.txt @@ -39,24 +39,30 @@ INSTALLATION *argwrap-installation* setting values for any of the following optional global variables in your .vimrc file: - * g:argwrap_wrap_style + * g:argwrap_wrap_closing_brace - Specifies the style in which arguments should be wrapped. + Specifies if the closing brace should be wrapped to a new line. This + setting is helpful when working with languages such as Google's Go, + which enforce coding style during compliation. - 'default' argument wrapping: + Brace wrapping enabled (default) + ``` Foo( wibble, wobble, wubble ) + ``` - 'bx' argument wrapping: + Brace wrapping disabled (let g:argwrap_wrap_closing_brace = 0) - Foo(wibble - , wobble - , wubble - ) + ``` + Foo( + wibble, + wobble, + wubble) + ``` * g:argwrap_padded_braces