From a49ae162f4f34761eca5059332d36eef6153a0e1 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 23 Oct 2019 22:23:59 +1100 Subject: [PATCH] Add a -verbatim switch to evaluate-commands for perfect forwarding -verbatim will disable argument parsing in evaluate-commands, making it possible to forward a single command to a different context without triggering a reparsing of the arguments. Fixes -try-client support in grep.kak Closes #3153 --- doc/pages/changelog.asciidoc | 3 +++ doc/pages/execeval.asciidoc | 4 ++++ rc/tools/grep.kak | 2 +- src/command_manager.hh | 11 ++++++----- src/commands.cc | 10 ++++++++-- 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/doc/pages/changelog.asciidoc b/doc/pages/changelog.asciidoc index d30d3016..0cdcbf94 100644 --- a/doc/pages/changelog.asciidoc +++ b/doc/pages/changelog.asciidoc @@ -12,6 +12,9 @@ released versions. `InsertBegin`, `InsertEnd`, `NormalBegin` and `NormalEnd` were removed. +* `-verbatim` switch in `evaluate-commands` for perfect command + forwarding to another context. + == Kakoune 2019.07.01 * Re-organized bundled script files directory hierarchy. diff --git a/doc/pages/execeval.asciidoc b/doc/pages/execeval.asciidoc index e2346019..f7b8db1e 100644 --- a/doc/pages/execeval.asciidoc +++ b/doc/pages/execeval.asciidoc @@ -55,6 +55,10 @@ when the commands have been executed: */*, *"*, *|*, *^*, *@*. disable hook execution while executing the keys/commands (See <>) +*-verbatim*:: + do not reparse and split positional arguments. Forward them + exactly as given to the `evaluate-commands` command. + == execute-keys specific switches *-with-maps*:: diff --git a/rc/tools/grep.kak b/rc/tools/grep.kak index b024444c..25062f38 100644 --- a/rc/tools/grep.kak +++ b/rc/tools/grep.kak @@ -44,7 +44,7 @@ define-command -hidden grep-jump %{ try %{ execute-keys 's^((?:\w:)?[^:]+):(\d+):(\d+)?' set-option buffer grep_current_line %val{cursor_line} - evaluate-commands -try-client %opt{jumpclient} %{ edit -existing %reg{1} %reg{2} %reg{3} } + evaluate-commands -try-client %opt{jumpclient} -verbatim -- edit -existing %reg{1} %reg{2} %reg{3} try %{ focus %opt{jumpclient} } } } diff --git a/src/command_manager.hh b/src/command_manager.hh index 8a3a9f23..0545a27c 100644 --- a/src/command_manager.hh +++ b/src/command_manager.hh @@ -100,6 +100,12 @@ public: void execute(StringView command_line, Context& context, const ShellContext& shell_context = ShellContext{}); + void execute_single_command(CommandParameters params, + Context& context, + const ShellContext& shell_context, + BufferCoord pos = {}); + + Completions complete(const Context& context, CompletionFlags flags, StringView command_line, ByteCount cursor_pos); @@ -132,11 +138,6 @@ public: Completions complete_module_name(StringView query) const; private: - void execute_single_command(CommandParameters params, - Context& context, - const ShellContext& shell_context, - BufferCoord pos); - struct Command { CommandFunc func; diff --git a/src/commands.cc b/src/commands.cc index 443e4b62..07abc4ab 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -1910,7 +1910,10 @@ const CommandDesc eval_string_cmd = { "evaluate-commands", "eval", "evaluate-commands [] ...: execute commands as if entered by user", - make_context_wrap_params<1>({{{"no-hooks", { false, "disable hooks while executing commands" }}}}), + make_context_wrap_params<2>({{ + {"no-hooks", { false, "disable hooks while executing commands" }}, + {"verbatim", { false, "do not reparse argument" }} + }}), CommandFlags::None, CommandHelper{}, CommandCompleter{}, @@ -1920,7 +1923,10 @@ const CommandDesc eval_string_cmd = { const bool no_hooks = context.hooks_disabled() or parser.get_switch("no-hooks"); ScopedSetBool disable_hoooks(context.hooks_disabled(), no_hooks); - CommandManager::instance().execute(join(parser, ' ', false), context, shell_context); + if (parser.get_switch("verbatim")) + CommandManager::instance().execute_single_command(parser | gather(), context, shell_context); + else + CommandManager::instance().execute(join(parser, ' ', false), context, shell_context); }); } };