Properly handle tabs

This commit is contained in:
Alex Yatskov 2014-12-03 13:44:31 +09:00
parent c5f010787e
commit 0b9a40b45f

View File

@ -132,8 +132,8 @@ function! argwrap#extractContainer(range)
let l:textStart = getline(a:range.lineStart) let l:textStart = getline(a:range.lineStart)
let l:textEnd = getline(a:range.lineEnd) let l:textEnd = getline(a:range.lineEnd)
let l:indent = match(l:textStart, '\S') let l:indent = matchstr(l:textStart, '\s*')
let l:prefix = l:textStart[l:indent : a:range.colStart - 1] let l:prefix = l:textStart[strlen(l:indent) : a:range.colStart - 1]
let l:suffix = l:textEnd[a:range.colEnd - 1:] let l:suffix = l:textEnd[a:range.colEnd - 1:]
return {'indent': l:indent, 'prefix': l:prefix, 'suffix': l:suffix} return {'indent': l:indent, 'prefix': l:prefix, 'suffix': l:suffix}
@ -141,14 +141,13 @@ endfunction
function! argwrap#wrapContainer(range, container, arguments, style) function! argwrap#wrapContainer(range, container, arguments, style)
let l:argCount = len(a:arguments) let l:argCount = len(a:arguments)
let l:padding = repeat(' ', a:container.indent)
let l:line = a:range.lineStart let l:line = a:range.lineStart
if a:style ==? 'default' if a:style ==? 'default'
call setline(l:line, l:padding . 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 = l:padding . 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 endif
@ -158,9 +157,9 @@ function! argwrap#wrapContainer(range, container, arguments, style)
exec printf('%s>', l:line) exec printf('%s>', l:line)
endfor endfor
call append(l:line, l:padding . a:container.suffix) call append(l:line, a:container.indent . a:container.suffix)
elseif a:style ==? 'bx' elseif a:style ==? 'bx'
let l:lineText = l:padding . a:container.prefix let l:lineText = a:container.indent . a:container.prefix
if l:argCount > 0 if l:argCount > 0
let l:lineText .= a:arguments[0] let l:lineText .= a:arguments[0]
let l:arguments = a:arguments[1:] let l:arguments = a:arguments[1:]
@ -170,20 +169,20 @@ function! argwrap#wrapContainer(range, container, arguments, style)
call setline(l:line, l:lineText) call setline(l:line, l:lineText)
for l:index in range(l:argCount) for l:index in range(l:argCount)
let l:text = ', ' . l:padding . l:arguments[l:index] let l:text = a:container.indent . ', ' . l:arguments[l:index]
call append(l:line, l:text) call append(l:line, l:text)
let l:line += 1 let l:line += 1
exec printf('%s>', l:line) exec printf('%s>', l:line)
endfor endfor
call append(l:line, l:padding . a:container.suffix) call append(l:line, a:container.indent . a:container.suffix)
exec printf('%s>', l:line + 1) exec printf('%s>', l:line + 1)
endif endif
endfunction endfunction
function! argwrap#unwrapContainer(range, container, arguments) function! argwrap#unwrapContainer(range, container, arguments)
let l:text = repeat(' ', a:container.indent) . a:container.prefix . join(a:arguments, ', ') . a:container.suffix let l:text = a:container.indent . a:container.prefix . join(a:arguments, ', ') . 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