From 068637fb624be232b30d761669273e7a9e634809 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Wed, 1 Jun 2016 22:19:00 -0700 Subject: [PATCH] Support commaFirst option --- autoload/argwrap.vim | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/autoload/argwrap.vim b/autoload/argwrap.vim index b5eb14f..b263186 100644 --- a/autoload/argwrap.vim +++ b/autoload/argwrap.vim @@ -156,19 +156,30 @@ function! argwrap#extractContainer(range) return {'indent': l:indent, 'prefix': l:prefix, 'suffix': l:suffix} endfunction -function! argwrap#wrapContainer(range, container, arguments, wrapBrace, tailComma, linePrefix) +function! argwrap#wrapContainer(range, container, arguments, wrapBrace, tailComma, linePrefix, commaFirst) let l:argCount = len(a:arguments) let l:line = a:range.lineStart call setline(l:line, a:container.indent . a:container.prefix) for l:index in range(l:argCount) - let l:text = a:container.indent . a:linePrefix . a:arguments[l:index] let l:last = l:index == l:argCount - 1 + let l:first = l:index == 0 + let l:text = '' - if !l:last || a:tailComma - let l:text .= ',' + if a:commaFirst + let l:text .= a:container.indent . a:linePrefix + if !l:first + let l:text .= ', ' + end + let l:text .= a:arguments[l:index] + else + let l:text .= a:container.indent . a:linePrefix . a:arguments[l:index] + if !l:last || a:tailComma + let l:text .= ',' + end end + if l:last && !a:wrapBrace let l:text .= a:container.suffix end @@ -216,6 +227,7 @@ function! argwrap#toggle() let l:padded = argwrap#getSetting('padded_braces', '') let l:tailComma = argwrap#getSetting('tail_comma', 0) let l:wrapBrace = argwrap#getSetting('wrap_closing_brace', 1) + let l:commaFirst = argwrap#getSetting('comma_first', 0) let l:range = argwrap#findClosestRange() if !argwrap#validateRange(l:range) @@ -230,7 +242,7 @@ function! argwrap#toggle() let l:container = argwrap#extractContainer(l:range) if l:range.lineStart == l:range.lineEnd - call argwrap#wrapContainer(l:range, l:container, l:arguments, l:wrapBrace, l:tailComma, l:linePrefix) + call argwrap#wrapContainer(l:range, l:container, l:arguments, l:wrapBrace, l:tailComma, l:linePrefix, l:commaFirst) else call argwrap#unwrapContainer(l:range, l:container, l:arguments, l:padded) endif