fix: prefix ending with spaces

For example in VimL with the following declaration:
autocmd FileType vim let b:argwrap_line_prefix = '\ '

The following line will be properly wrapped:
let t = {'one': 'whatever', 'two': 'whatever'}

Into:
let t = {
  \ 'one': 'whatever',
  \ 'two': 'whatever',
\ }

But when trying to unwrap it will do:
let t = {'one': 'whatever', 'two': 'whatever', \}

This is caused by the "trim" done for each "extracted" piece of text,
which result in having '\' instead of '\ ' for the last line.
This commit is contained in:
Camille Dejoye 2020-06-06 15:16:27 +02:00
parent 7e3db5f517
commit 6c240beb01

View File

@ -68,6 +68,7 @@ endfunction
function! argwrap#extractContainerArgText(range, linePrefix) function! argwrap#extractContainerArgText(range, linePrefix)
let l:text = '' let l:text = ''
let l:trimPattern = printf('\m^\s*\(.\{-}\%%(%s\)\?\)\s*$', escape(a:linePrefix, '\$.*^['))
for l:lineIndex in range(a:range.lineStart, a:range.lineEnd) for l:lineIndex in range(a:range.lineStart, a:range.lineEnd)
let l:lineText = getline(l:lineIndex) let l:lineText = getline(l:lineIndex)
@ -84,7 +85,7 @@ function! argwrap#extractContainerArgText(range, linePrefix)
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, l:trimPattern, '\1', '')
if stridx(l:extract, a:linePrefix) == 0 if stridx(l:extract, a:linePrefix) == 0
let l:extract = l:extract[len(a:linePrefix):] let l:extract = l:extract[len(a:linePrefix):]
endif endif