From 6c240beb011fa7c245f9039701a48c4b3859c04e Mon Sep 17 00:00:00 2001 From: Camille Dejoye Date: Sat, 6 Jun 2020 15:16:27 +0200 Subject: [PATCH] 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. --- autoload/argwrap.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/autoload/argwrap.vim b/autoload/argwrap.vim index 21cabae..3693b85 100644 --- a/autoload/argwrap.vim +++ b/autoload/argwrap.vim @@ -68,6 +68,7 @@ endfunction function! argwrap#extractContainerArgText(range, linePrefix) 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) let l:lineText = getline(l:lineIndex) @@ -84,7 +85,7 @@ function! argwrap#extractContainerArgText(range, linePrefix) if l:extractStart < l:extractEnd 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 let l:extract = l:extract[len(a:linePrefix):] endif