From 98b62304bba2838d53e5f4a37df52e0413d74906 Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Wed, 27 Jun 2018 09:30:11 +0300 Subject: [PATCH] src: Make `!` re-evaluate the command for each selection Fixes #2138 --- src/normal.cc | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/normal.cc b/src/normal.cc index 0fe60ef8..52872db0 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -617,10 +617,26 @@ void insert_output(Context& context, NormalParams) if (cmdline.empty()) return; - auto str = ShellManager::instance().eval( - cmdline, context, {}, ShellManager::Flags::WaitForStdout).first; ScopedEdition edition(context); - context.selections().insert(str, mode); + Buffer& buffer = context.buffer(); + auto& shell_manager = ShellManager::instance(); + auto& selections = context.selections(); + Vector ins; + const size_t old_main = selections.main_index(); + + for (size_t i = 0; i < selections.size(); i++) + { + selections.set_main_index(i); + + auto& sel = selections.main(); + auto str = shell_manager.eval(cmdline, context, content(buffer, sel), + ShellManager::Flags::WaitForStdout).first; + + ins.emplace_back(str); + } + + selections.set_main_index(old_main); + selections.insert(ins, mode); }); }