Skip to content

Commit 8e876c9

Browse files
committed
Support '*' and comma separated list for exec/eval -client switch
Closes #5326
1 parent 9631644 commit 8e876c9

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

doc/pages/execeval.asciidoc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ are then restored when the keys have been executed: */*, *"*, *|*, *^*,
1818

1919
== Switches for both commands
2020

21-
*-client* <name>::
22-
Execute in the context of the client *name*.
21+
*-client* <names>::
22+
Execute in the context of each client specified in the comma separated
23+
list *names*. '\*' can be used as *names* to iterate overall clients.
2324

2425
*-try-client* <name>::
2526
Execute in the context of the client *name* if such client exists,
@@ -37,7 +38,7 @@ are then restored when the keys have been executed: */*, *"*, *|*, *^*,
3738

3839
*-buffer* <names>::
3940
Execute in the context of each buffer specified in the comma separated
40-
list *names*. '\*' can be used as a *name* to iterate over all non-debug
41+
list *names*. '\*' can be used as *names* to iterate over all non-debug
4142
buffers.
4243
(See <<buffers#debug-buffers, `:doc buffers`>>)
4344

src/commands.cc

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2038,7 +2038,7 @@ template<size_t... P>
20382038
ParameterDesc make_context_wrap_params_impl(Array<HashItem<String, SwitchDesc>, sizeof...(P)>&& additional_params,
20392039
std::index_sequence<P...>)
20402040
{
2041-
return { { { "client", { {client_arg_completer}, "run in given client context" } },
2041+
return { { { "client", { {client_arg_completer}, "run in the client context for each client in the given comma separatd list" } },
20422042
{ "try-client", { {client_arg_completer}, "run in given client context if it exists, or else in the current one" } },
20432043
{ "buffer", { {complete_buffer_name<false>}, "run in a disposable context for each given buffer in the comma separated list argument" } },
20442044
{ "draft", { {}, "run in a disposable context" } },
@@ -2188,14 +2188,25 @@ void context_wrap(const ParametersParser& parser, Context& context, StringView d
21882188
};
21892189

21902190
ClientManager& cm = ClientManager::instance();
2191-
if (auto client_name = parser.get_switch("client"))
2192-
context_wrap_for_context(cm.get_client(*client_name).context());
2193-
else if (auto client_name = parser.get_switch("try-client"))
2191+
if (auto client_names = parser.get_switch("client"))
21942192
{
2195-
if (Client* client = cm.get_client_ifp(*client_name))
2196-
context_wrap_for_context(client->context());
2193+
if (*client_names == "*")
2194+
{
2195+
for (auto&& client : ClientManager::instance()
2196+
| transform(&std::unique_ptr<Client>::get)
2197+
| gather<Vector<SafePtr<Client>>>()) // gather as we might be mutating the client list in the loop.
2198+
context_wrap_for_context(client->context());
2199+
}
21972200
else
2198-
context_wrap_for_context(context);
2201+
for (auto&& name : *client_names
2202+
| split<StringView>(',', '\\')
2203+
| transform(unescape<',', '\\'>))
2204+
context_wrap_for_context(ClientManager::instance().get_client(name).context());
2205+
}
2206+
else if (auto client_name = parser.get_switch("try-client"))
2207+
{
2208+
Client* client = cm.get_client_ifp(*client_name);
2209+
context_wrap_for_context(client ? client->context() : context);
21992210
}
22002211
else
22012212
context_wrap_for_context(context);

0 commit comments

Comments
 (0)