Re: [dev] [vis][RFC][PATCH 1/2] Replace first '/' of substitute command with \0

From: Silvan Jegen <s.jegen_AT_gmail.com>
Date: Thu, 7 May 2015 09:43:10 +0200

On Wed, May 6, 2015 at 9:03 PM, Marc André Tanner <mat_AT_brain-dump.org> wrote:
> On Tue, May 05, 2015 at 06:25:29PM +0200, Silvan Jegen wrote:
>> Replacing the first '/' allows the 's' command name to be correctly
>> identified even though it is part of its own argument.
>
> Special casing '/' seems wrong, an arbitrary delimiter can be used
>
> :s,foo,bar
>
> is perfectly valid. The end of the command name should probably be

I was aware that sed allows for different delimiters but I thought vim doesn't.


> detected by isalpha(3) or similar. Hence instead of doing a strdup(...)
> we should probably do a malloc(strlen(...)+2) in combination with
> a strcpy/memcpy and then memmove(...) the arguments one position to
> the right and NUL-terminate the name.
>
>> This is hacky because afterwards we will add the '/' back in before
>> calling the 'sed' program.
>
> Relying on the fact that cmd_set was called with (i.e. that argv[0]
> was set to) ':s/' is wrong, it could also be ':substitute/'.
>
> With the strategy outlined above argv[1] would contain the argument
> (= search pattern) which could be prefixed by 's'. Furthermore if
> the pattern doesn't contain the delimiter at the end, it should
> be appended.
>
> Please send an updated patch if you think this makes sense ...

It makes sense to me. The current approach was just a quick hack to
make it work. I will rewrite it at the next opportunity.
Received on Thu May 07 2015 - 09:43:10 CEST

This archive was generated by hypermail 2.3.0 : Thu May 07 2015 - 09:48:13 CEST