Add support for -buffer <comma separated names> to eval and exec commands

fixes #47
This commit is contained in:
Maxime Coste 2014-02-19 02:59:41 +00:00
parent 15223cba1e
commit 4b9d49d7ab
2 changed files with 15 additions and 0 deletions

View File

@ -415,6 +415,8 @@ Some parameters provide a way to change the context of execution:
* +-itersel+ (requires +-draft+): execute once per selection, in a
context with only the considered selection. This permits to avoid
cases where the selections may get merged.
* +-buffer <names>+: execute in the context of each buffers in the
comma separated list <names>
The execution stops when the last key/command is reached, or an error
is raised.

View File

@ -878,6 +878,7 @@ const CommandDesc map_key_cmd = {
const ParameterDesc context_wrap_params = {
SwitchMap{ { "client", { true, "run in given client context" } },
{ "try-client", { true, "run in given client context if it exists, or else in the current one" } },
{ "buffer", { true, "run in a disposable context for each given buffer in the comma separated list argument" } },
{ "draft", { false, "run in a disposable context" } },
{ "itersel", { false, "run once for each selection with that selection as the only one" } } },
ParameterDesc::Flags::SwitchesOnlyAtStart, 1
@ -887,6 +888,18 @@ template<typename Func>
void context_wrap(const ParametersParser& parser, Context& context, Func func)
{
ClientManager& cm = ClientManager::instance();
if (parser.has_option("buffer"))
{
auto names = split(parser.option_value("buffer"), ',');
for (auto& name : names)
{
Buffer& buffer = BufferManager::instance().get_buffer(name);
InputHandler input_handler(buffer, SelectionList{ {} });
func(parser, input_handler.context());
}
return;
}
Context* real_context = &context;
if (parser.has_option("client"))
real_context = &cm.get_client(parser.option_value("client")).context();