Remove support for %arg{#}, can be added back if we got a use case

It is very unlikely we need %arg{#} without needing a %sh anyway.
This commit is contained in:
Maxime Coste 2015-12-02 01:08:41 +00:00
parent a02ad38fb4
commit 2a8a329b83
2 changed files with 5 additions and 9 deletions

View File

@ -630,8 +630,7 @@ Supported types are:
* `val`: value expansion, gives access to the environment variable available
to the Shell expansion. The `kak_` prefix is not used there.
* `arg`: argument expansion, gives access to the arguments of the current
command, the content can be a number, or `#` for the argument count,
or `@` for all arguments concatenated.
command, the content can be a number, or `@` for all arguments.
for example you can display last search pattern with

View File

@ -348,17 +348,14 @@ String expand_token(const Token& token, const Context& context,
}
case Token::Type::ArgExpand:
{
if (content == "#")
return to_string(shell_context.params.size());
else if (content == "@")
return join(shell_context.params, ' ');
auto& params = shell_context.params;
if (content == '@')
return join(params, ' ');
const int arg = str_to_int(content)-1;
if (arg < 0)
throw runtime_error("invalid argument index");
if (arg < shell_context.params.size())
return shell_context.params[arg];
return {};
return arg < params.size() ? params[arg] : String{};
}
case Token::Type::RawEval:
return expand(content, context, shell_context);