Extend source command to support parameters.

Parameters are accessible in %arg{n}, as with define-command.
This commit is contained in:
Shachaf Ben-Kiki 2018-05-23 14:22:40 -07:00 committed by Olivier Perret
parent 373858f9bf
commit 5238c2d93d
2 changed files with 6 additions and 4 deletions

View File

@ -67,8 +67,9 @@ command *q!* has to be used). Aliases are mentionned below each commands.
*rename-buffer* <name>:: *rename-buffer* <name>::
set current buffer name set current buffer name
*source* <filename>:: *source* <filename> <param>...::
execute commands in <filename> execute commands in <filename>
parameters are avilable in the sourced script through the `arg` values
== Clients and Sessions == Clients and Sessions

View File

@ -1284,8 +1284,8 @@ const CommandDesc debug_cmd = {
const CommandDesc source_cmd = { const CommandDesc source_cmd = {
"source", "source",
nullptr, nullptr,
"source <filename>: execute commands contained in <filename>", "source <filename> <params>...: execute commands contained in <filename>",
single_param, ParameterDesc{ {}, ParameterDesc::Flags::None, 1, (size_t)-1 },
CommandFlags::None, CommandFlags::None,
CommandHelper{}, CommandHelper{},
filename_completer, filename_completer,
@ -1299,8 +1299,9 @@ const CommandDesc source_cmd = {
MappedFile file_content{path}; MappedFile file_content{path};
try try
{ {
auto params = parser | skip(1) | gather<Vector<String>>();
CommandManager::instance().execute(file_content, context, CommandManager::instance().execute(file_content, context,
{{}, {{"source", path}}}); {params, {{"source", path}}});
} }
catch (Kakoune::runtime_error& err) catch (Kakoune::runtime_error& err)
{ {