This commit is contained in:
Alex Yatskov 2014-12-02 09:36:14 +09:00
parent f07af29b99
commit b948dbb2d6

View File

@ -132,43 +132,48 @@ 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 = match(l:textStart, '\S')
let l:prefix = l:textStart[l:indent : a:range.colStart - 1] let l:prefix = l:textStart[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}
endfunction endfunction
function! argwrap#wrapContainer(range, container, arguments) function! argwrap#wrapContainer(range, container, arguments)
let l:argCount = len(a:arguments) let l:argCount = len(a:arguments)
let l:padding = repeat(" ", a:container.indent) let l:padding = repeat(' ', a:container.indent)
let l:line = a:range.lineStart let l:line = a:range.lineStart
call setline(l:line, l:padding . a:container.prefix) call setline(l:line, l:padding . 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 = l:padding . a:arguments[l:index]
if l:index < l:argCount - 1 if l:index < l:argCount - 1
let l:text .= "," let l:text .= ','
endif endif
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, l:padding . a:container.suffix)
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 = repeat(' ', 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("%d,%dd", a:range.lineStart + 1, a:range.lineEnd) exec printf('%d,%dd_', a:range.lineStart + 1, a:range.lineEnd)
endfunction endfunction
function! argwrap#toggle() function! argwrap#toggle()
let l:range = argwrap#findClosestRange()
if !argwrap#validateRange(l:range)
call search('[\(\[\{]')
call search('[^\(\[\{]')
let l:range = argwrap#findClosestRange() let l:range = argwrap#findClosestRange()
if !argwrap#validateRange(l:range) if !argwrap#validateRange(l:range)
return return
endif endif
endif
let l:argText = argwrap#extractArgumentText(l:range) let l:argText = argwrap#extractArgumentText(l:range)
let l:arguments = argwrap#extractArguments(l:argText) let l:arguments = argwrap#extractArguments(l:argText)