Adding g:argwrap_wrap_closing_brace , getting rid of g_argwrap_wrap_style

This commit is contained in:
Alex Yatskov 2015-03-25 14:17:45 +09:00
parent a899077bf5
commit ebe4380188
3 changed files with 43 additions and 51 deletions

View File

@ -27,11 +27,15 @@ information.
3. You can customize the wrapping/unwrapping behavior of this extension by setting values for any of the following 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: 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( Foo(
@ -41,13 +45,13 @@ information.
) )
``` ```
`'bx'` argument wrapping: Brace wrapping disabled (`let g:argwrap_wrap_closing_brace = 0`)
``` ```
Foo(wibble Foo(
, wobble wibble,
, wubble wobble,
) wubble)
``` ```
* `g:argwrap_padded_braces` * `g:argwrap_padded_braces`

View File

@ -139,45 +139,27 @@ function! argwrap#extractContainer(range)
return {'indent': l:indent, 'prefix': l:prefix, 'suffix': l:suffix} return {'indent': l:indent, 'prefix': l:prefix, 'suffix': l:suffix}
endfunction endfunction
function! argwrap#wrapContainer(range, container, arguments, style) function! argwrap#wrapContainer(range, container, arguments, wrapBrace)
let l:argCount = len(a:arguments) let l:argCount = len(a:arguments)
let l:line = a:range.lineStart 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) for l:index in range(l:argCount)
let l:text = a:container.indent . a:arguments[l:index] let l:text = a:container.indent . a:arguments[l:index]
if l:index < l:argCount - 1 if l:index < l:argCount - 1
let l:text .= ',' let l:text .= ','
endif elseif !a:wrapBrace
let l:text .= a:container.suffix
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
endif endif
call setline(l:line, l:lineText) call append(l:line, l:text)
let l:line += 1
for l:index in range(l:argCount) exec printf('%s>', l:line)
let l:text = a:container.indent . ', ' . l:arguments[l:index] 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) call append(l:line, a:container.indent . a:container.suffix)
exec printf('%s>', l:line + 1)
endif endif
endfunction endfunction
@ -195,10 +177,10 @@ function! argwrap#unwrapContainer(range, container, arguments, padded)
endfunction endfunction
function! argwrap#toggle() function! argwrap#toggle()
if exists('g:argwrap_wrap_style') if exists('g:argwrap_wrap_closing_brace')
let l:style = g:argwrap_wrap_style let l:wrapBrace = g:argwrap_wrap_closing_brace
else else
let l:style = 'default' let l:wrapBrace = 1
endif endif
if exists('g:argwrap_padded_braces') if exists('g:argwrap_padded_braces')
@ -222,7 +204,7 @@ function! argwrap#toggle()
let l:container = argwrap#extractContainer(l:range) let l:container = argwrap#extractContainer(l:range)
if l:range.lineStart == l:range.lineEnd 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 else
call argwrap#unwrapContainer(l:range, l:container, l:arguments, l:padded) call argwrap#unwrapContainer(l:range, l:container, l:arguments, l:padded)
endif endif

View File

@ -39,24 +39,30 @@ INSTALLATION *argwrap-installation*
setting values for any of the following optional global variables in your setting values for any of the following optional global variables in your
.vimrc file: .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( Foo(
wibble, wibble,
wobble, wobble,
wubble wubble
) )
```
'bx' argument wrapping: Brace wrapping disabled (let g:argwrap_wrap_closing_brace = 0)
Foo(wibble ```
, wobble Foo(
, wubble wibble,
) wobble,
wubble)
```
* g:argwrap_padded_braces * g:argwrap_padded_braces