Adding g:argwrap_wrap_closing_brace , getting rid of g_argwrap_wrap_style
This commit is contained in:
parent
a899077bf5
commit
ebe4380188
20
README.md
20
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
|
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`
|
||||||
|
@ -139,17 +139,18 @@ 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 .= ','
|
||||||
|
elseif !a:wrapBrace
|
||||||
|
let l:text .= a:container.suffix
|
||||||
endif
|
endif
|
||||||
|
|
||||||
call append(l:line, l:text)
|
call append(l:line, l:text)
|
||||||
@ -157,27 +158,8 @@ function! argwrap#wrapContainer(range, container, arguments, style)
|
|||||||
exec printf('%s>', l:line)
|
exec printf('%s>', l:line)
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
|
if a:wrapBrace
|
||||||
call append(l:line, a:container.indent . a:container.suffix)
|
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
|
|
||||||
|
|
||||||
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, 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
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user