From 5238c2d93d7068d64a29e0a0956652757720e0f1 Mon Sep 17 00:00:00 2001 From: Shachaf Ben-Kiki Date: Wed, 23 May 2018 14:22:40 -0700 Subject: [PATCH] Extend `source` command to support parameters. Parameters are accessible in %arg{n}, as with define-command. --- doc/pages/commands.asciidoc | 3 ++- src/commands.cc | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/doc/pages/commands.asciidoc b/doc/pages/commands.asciidoc index b35b5d82..285610aa 100644 --- a/doc/pages/commands.asciidoc +++ b/doc/pages/commands.asciidoc @@ -67,8 +67,9 @@ command *q!* has to be used). Aliases are mentionned below each commands. *rename-buffer* :: set current buffer name -*source* :: +*source* ...:: execute commands in + parameters are avilable in the sourced script through the `arg` values == Clients and Sessions diff --git a/src/commands.cc b/src/commands.cc index a63bc71a..d81be634 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -1284,8 +1284,8 @@ const CommandDesc debug_cmd = { const CommandDesc source_cmd = { "source", nullptr, - "source : execute commands contained in ", - single_param, + "source ...: execute commands contained in ", + ParameterDesc{ {}, ParameterDesc::Flags::None, 1, (size_t)-1 }, CommandFlags::None, CommandHelper{}, filename_completer, @@ -1299,8 +1299,9 @@ const CommandDesc source_cmd = { MappedFile file_content{path}; try { + auto params = parser | skip(1) | gather>(); CommandManager::instance().execute(file_content, context, - {{}, {{"source", path}}}); + {params, {{"source", path}}}); } catch (Kakoune::runtime_error& err) {