From 4b9d49d7ab838418ba898963883fbc6900c44e1c Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 19 Feb 2014 02:59:41 +0000 Subject: [PATCH] Add support for -buffer to eval and exec commands fixes #47 --- README.asciidoc | 2 ++ src/commands.cc | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/README.asciidoc b/README.asciidoc index 19aaf445..829e1abb 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -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 +: execute in the context of each buffers in the + comma separated list The execution stops when the last key/command is reached, or an error is raised. diff --git a/src/commands.cc b/src/commands.cc index d17c320d..72ab9f19 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -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 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();