On Wed, May 6, 2015 at 9:03 PM, Marc André Tanner <m...@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.