Adding option to add space padding inside of braces; adding global option for wrap style

This commit is contained in:
Alex Yatskov 2015-01-28 13:40:42 +09:00
parent c4f7aa3d80
commit ae18d6d987

View File

@ -181,14 +181,32 @@ function! argwrap#wrapContainer(range, container, arguments, style)
endif endif
endfunction endfunction
function! argwrap#unwrapContainer(range, container, arguments) function! argwrap#unwrapContainer(range, container, arguments, padded)
let l:text = a:container.indent . a:container.prefix . join(a:arguments, ', ') . a:container.suffix let l:brace = a:container.prefix[strlen(a:container.prefix) - 1]
if stridx(a:padded, l:brace) == -1
let l:padding = ''
else
let l:padding = ' '
endif
let l:text = a:container.indent . a:container.prefix . l:padding . join(a:arguments, ', ') . l:padding . a:container.suffix
call setline(a:range.lineStart, l:text) call setline(a:range.lineStart, l:text)
exec printf('silent %d,%dd_', a:range.lineStart + 1, a:range.lineEnd) exec printf('silent %d,%dd_', a:range.lineStart + 1, a:range.lineEnd)
endfunction endfunction
function! argwrap#toggle(...) function! argwrap#toggle(...)
if exists('g:argwrap_wrap_style')
let l:style = g:argwrap_wrap_style
else
let l:style = a:0 == 0 ? 'default' : a:1 let l:style = a:0 == 0 ? 'default' : a:1
endif
if exists('g:argwrap_padded_braces')
let l:padded = g:argwrap_padded_braces
else
let l:padded = ''
endif
let l:cursor = getpos('.') let l:cursor = getpos('.')
let l:range = argwrap#findClosestRange() let l:range = argwrap#findClosestRange()
@ -206,7 +224,7 @@ function! argwrap#toggle(...)
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:style)
else else
call argwrap#unwrapContainer(l:range, l:container, l:arguments) call argwrap#unwrapContainer(l:range, l:container, l:arguments, l:padded)
endif endif
call setpos('.', l:cursor) call setpos('.', l:cursor)