Add support for -buffer <comma separated names> to eval and exec commands
fixes #47
This commit is contained in:
parent
15223cba1e
commit
4b9d49d7ab
|
@ -415,6 +415,8 @@ Some parameters provide a way to change the context of execution:
|
||||||
* +-itersel+ (requires +-draft+): execute once per selection, in a
|
* +-itersel+ (requires +-draft+): execute once per selection, in a
|
||||||
context with only the considered selection. This permits to avoid
|
context with only the considered selection. This permits to avoid
|
||||||
cases where the selections may get merged.
|
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
|
The execution stops when the last key/command is reached, or an error
|
||||||
is raised.
|
is raised.
|
||||||
|
|
|
@ -878,6 +878,7 @@ const CommandDesc map_key_cmd = {
|
||||||
const ParameterDesc context_wrap_params = {
|
const ParameterDesc context_wrap_params = {
|
||||||
SwitchMap{ { "client", { true, "run in given client context" } },
|
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" } },
|
{ "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" } },
|
{ "draft", { false, "run in a disposable context" } },
|
||||||
{ "itersel", { false, "run once for each selection with that selection as the only one" } } },
|
{ "itersel", { false, "run once for each selection with that selection as the only one" } } },
|
||||||
ParameterDesc::Flags::SwitchesOnlyAtStart, 1
|
ParameterDesc::Flags::SwitchesOnlyAtStart, 1
|
||||||
|
@ -887,6 +888,18 @@ template<typename Func>
|
||||||
void context_wrap(const ParametersParser& parser, Context& context, Func func)
|
void context_wrap(const ParametersParser& parser, Context& context, Func func)
|
||||||
{
|
{
|
||||||
ClientManager& cm = ClientManager::instance();
|
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;
|
Context* real_context = &context;
|
||||||
if (parser.has_option("client"))
|
if (parser.has_option("client"))
|
||||||
real_context = &cm.get_client(parser.option_value("client")).context();
|
real_context = &cm.get_client(parser.option_value("client")).context();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user