Add support for line prefixes
This commit is contained in:
parent
a83fdc725d
commit
bf3da537eb
@ -66,7 +66,7 @@ function! argwrap#findClosestRange()
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! argwrap#extractContainerArgText(range)
|
function! argwrap#extractContainerArgText(range, linePrefix)
|
||||||
let l:text = ''
|
let l:text = ''
|
||||||
|
|
||||||
for l:lineIndex in range(a:range.lineStart, a:range.lineEnd)
|
for l:lineIndex in range(a:range.lineStart, a:range.lineEnd)
|
||||||
@ -85,6 +85,9 @@ function! argwrap#extractContainerArgText(range)
|
|||||||
if l:extractStart < l:extractEnd
|
if l:extractStart < l:extractEnd
|
||||||
let l:extract = l:lineText[l:extractStart : l:extractEnd - 1]
|
let l:extract = l:lineText[l:extractStart : l:extractEnd - 1]
|
||||||
let l:extract = substitute(l:extract, '^\s*\(.\{-}\)\s*$', '\1', '')
|
let l:extract = substitute(l:extract, '^\s*\(.\{-}\)\s*$', '\1', '')
|
||||||
|
if stridx(l:extract, a:linePrefix) == 0
|
||||||
|
let l:extract = l:extract[len(a:linePrefix):]
|
||||||
|
endif
|
||||||
let l:extract = substitute(l:extract, ',$', ', ', '')
|
let l:extract = substitute(l:extract, ',$', ', ', '')
|
||||||
let l:text .= l:extract
|
let l:text .= l:extract
|
||||||
endif
|
endif
|
||||||
@ -153,14 +156,14 @@ 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, wrapBrace, tailComma)
|
function! argwrap#wrapContainer(range, container, arguments, wrapBrace, tailComma, linePrefix)
|
||||||
let l:argCount = len(a:arguments)
|
let l:argCount = len(a:arguments)
|
||||||
let l:line = a:range.lineStart
|
let l:line = a:range.lineStart
|
||||||
|
|
||||||
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:linePrefix . a:arguments[l:index]
|
||||||
if l:index < l:argCount - 1 || a:tailComma
|
if l:index < l:argCount - 1 || a:tailComma
|
||||||
let l:text .= ','
|
let l:text .= ','
|
||||||
elseif !a:wrapBrace
|
elseif !a:wrapBrace
|
||||||
@ -173,7 +176,7 @@ function! argwrap#wrapContainer(range, container, arguments, wrapBrace, tailComm
|
|||||||
endfor
|
endfor
|
||||||
|
|
||||||
if a:wrapBrace
|
if a:wrapBrace
|
||||||
call append(l:line, a:container.indent . a:container.suffix)
|
call append(l:line, a:container.indent . a:linePrefix . a:container.suffix)
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@ -209,13 +212,14 @@ function! argwrap#toggle()
|
|||||||
let l:tailComma = argwrap#getSetting('tail_comma', 0)
|
let l:tailComma = argwrap#getSetting('tail_comma', 0)
|
||||||
let l:wrapBrace = argwrap#getSetting('wrap_closing_brace', 1)
|
let l:wrapBrace = argwrap#getSetting('wrap_closing_brace', 1)
|
||||||
let l:padded = argwrap#getSetting('padded_braces', '')
|
let l:padded = argwrap#getSetting('padded_braces', '')
|
||||||
|
let l:linePrefix = argwrap#getSetting('line_prefix', '')
|
||||||
|
|
||||||
let l:range = argwrap#findClosestRange()
|
let l:range = argwrap#findClosestRange()
|
||||||
if !argwrap#validateRange(l:range)
|
if !argwrap#validateRange(l:range)
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let l:argText = argwrap#extractContainerArgText(l:range)
|
let l:argText = argwrap#extractContainerArgText(l:range, l:linePrefix)
|
||||||
let l:arguments = argwrap#extractContainerArgs(l:argText)
|
let l:arguments = argwrap#extractContainerArgs(l:argText)
|
||||||
if len(l:arguments) == 0
|
if len(l:arguments) == 0
|
||||||
return
|
return
|
||||||
@ -223,7 +227,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:wrapBrace, l:tailComma)
|
call argwrap#wrapContainer(l:range, l:container, l:arguments, l:wrapBrace, l:tailComma, l:linePrefix)
|
||||||
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
|
||||||
|
Loading…
Reference in New Issue
Block a user