OK, sounds good!
>> "This does not work recursively: a substitute() function inside the
>> expression cannot use "\=" for the substitute string."
>>
>> This suggests you can't really expect \= to work as the substitute
>> string in a substitute() function call.
>
> I think that you misunderstand the help above. I think that it means,
> for example, the following code does not work.
>
> let y = substitute(str, '.', "\=substitute(v:val, 'x', 'X', '')",
> 'g')
I don't think that's the correct interpretation of the help, either.
Actually, I think it means you can't do
:s/./\=substitute(submatch(0),'x','\=whatever','')
My main point, though, which has basically just been proven, is that
it's hard to know exactly what the help means, or was intended to
describe; that fact merely suggests there might be problems if you have
\= inside a substitute() call.
> The attached patch is the example which works around this problem. It
> is assumed that the variable reg_line_lbr is true if the function
> vim_regsub_both is called from the substitute(), vice versa if it is
> called from the :substitute command as the current implementation is.
>
> The result of the code above;
>
> ^@
> ^@
> 1
> 1
> 0
>
> It seems OK. Next test :substitute command with the pattern
> written at the comment of the function vim_regsub_both. On text;
>
> abc\
> def
>
> execute ':%s/abc\\\ndef/\="aaa\\\nbbb"/'.
>
> aaa\
> bbb
>
> It seems OK, too.
>
> In summary, I think that this issue is a bug and it should be fixed
> so that the result is as same as my patch works around. Otherwise,
> Vim should inform us of illegal usage by generating error.
Your workaround seems sensible to me, though yes, of course, it should
either be ensured that reg_line_lbr is always set as you expect, and
documented in a code comment to be that way, or another variable should
be introduced to give the distinction you need.
Also, there may be other issues that are probably worth
checking/addressing at the same time. As :help sub-replace-expression
notes, using \n to break lines is a convenience. The 'proper' way to do
it is to use \r. Does \r currently 'do the right thing', or does it
result in \r in the string? Also, does \\\r do the right thing (insert a
\r), and how about \\\n--does it insert a null (i.e. probably end the
string) as it should if the documentation is followed?
>> I'm not sure how much, if any, of this could be regarded as bugs, and
>> how much, if any, would be fixed, given backwards-compatibility issues.
I still stand by this, though. We'll need to hear from Bram whether he's
willing to change this.
Ben.
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
No comments:
Post a Comment