mirror of
https://github.com/neovim/neovim.git
synced 2025-10-15 22:36:09 +00:00
feat: ":restart [cmd]" can run commands #35045
Problem: Not easy for a user to tell ":restart" to "run this command(s) after restarting". Solution: All ":restart" args following the optional +cmd arg are treated as a big cmdline that is passed as a "-c" CLI arg when restarting nvim.
This commit is contained in:
@@ -286,15 +286,31 @@ bool remote_ui_restart(uint64_t channel_id, Error *err)
|
||||
assert(argc > 0);
|
||||
Array argv = arena_array(&arena, (size_t)argc + 1);
|
||||
bool had_minmin = false;
|
||||
bool skipping_minc = false; // Skip -c <cmd> from argv.
|
||||
bool first_minc = true; // Avoid skipping the first -c <cmd> from argv.
|
||||
TV_LIST_ITER_CONST(l, li, {
|
||||
const char *arg = tv_get_string(TV_LIST_ITEM_TV(li));
|
||||
if (argv.size > 0 && !had_minmin && strequal(arg, "--")) {
|
||||
had_minmin = true;
|
||||
skipping_minc = false;
|
||||
}
|
||||
// Exclude --embed/--headless from `argv`, as the client may start the server in a
|
||||
bool startswith_min = strlen(arg) > 0 && arg[0] == '-';
|
||||
bool startswith_minmin = strlen(arg) > 1 && arg[0] == '-' && arg[1] == '-';
|
||||
if (skipping_minc && (startswith_min || startswith_minmin)) {
|
||||
skipping_minc = false;
|
||||
}
|
||||
if (!had_minmin && !skipping_minc && strequal(arg, "-c")) {
|
||||
if (!first_minc) {
|
||||
skipping_minc = true;
|
||||
continue;
|
||||
}
|
||||
first_minc = false;
|
||||
}
|
||||
// Exclude --embed/--headless/-c <cmd> from `argv`, as the client may start the server in a
|
||||
// different way than how the server was originally started.
|
||||
// Eg: 'nvim -c foo -c bar --embed --headless -- example.txt' would be parsed as { 'nvim', '-c', 'foo', '--', 'example.txt' }.
|
||||
if (argv.size == 0 || had_minmin
|
||||
|| (!strequal(arg, "--embed") && !strequal(arg, "--headless"))) {
|
||||
|| (!strequal(arg, "--embed") && !strequal(arg, "--headless") && !skipping_minc)) {
|
||||
ADD_C(argv, CSTR_AS_OBJ(arg));
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user