diff --git a/runtime/doc/gui.txt b/runtime/doc/gui.txt index 44892a39be..1314574278 100644 --- a/runtime/doc/gui.txt +++ b/runtime/doc/gui.txt @@ -83,7 +83,7 @@ Restart Nvim 1. Saves the current session (unless [!] was given). 2. Stops Nvim using `:qall` (or |+cmd|, if given). 3. Starts a new Nvim server using the same |v:argv| (except - `-- [file…]` files), and sets |v:startreason|. + `-- [file…]` files and `-S [file]`), and sets |v:startreason|. 4. Restores the saved session (unless [!] was given). 5. Attaches all UIs to the new Nvim server and runs `[command]` on it. diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 238f70fd14..8f5a2ac362 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -5012,6 +5012,16 @@ static void ex_restart(exarg_T *eap) if (i > 0 && strequal(arg, "--")) { break; } + // Drop "-S [file]". It conflicts with :restart and usually isn't wanted for :restart! + if (i > 0 && strequal(arg, "-S")) { + if (li->li_next != NULL) { + const char *next_arg = tv_get_string(TV_LIST_ITEM_TV(li->li_next)); + if (next_arg[0] != '-') { + li = li->li_next; + } + } + continue; + } // Drop "-s ": skip the scriptfile arg too. if (i > 0 && strequal(arg, "-s")) { li = li->li_next; diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index fc54c1ca64..25274cd371 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -610,6 +610,11 @@ describe('TUI :restart', function() it('drops "-" and "-- [files…]" from v:argv #34417', function() t.skip(is_os('win'), 'stdin behavior differs on Windows') + local file = 'file.lua' + write_file(file, "print('-S works')\n") + finally(function() + os.remove(file) + end) local server_session finally(function() if server_session then @@ -626,6 +631,8 @@ describe('TUI :restart', function() server_pipe, '--cmd', 'set notermguicolors', + '-S', + file, '-s', '-', '-', @@ -637,14 +644,16 @@ describe('TUI :restart', function() ^ | ~ |*3 {2:Xtest-file1 0,0-1 All}| - | + -S works | {5:-- TERMINAL --} | ]]) server_session = n.connect(server_pipe) local expr = 'index(v:argv, "-") >= 0 || index(v:argv, "--") >= 0 ? v:true : v:false' local has_s = 'index(v:argv, "-s") >= 0 ? v:true : v:false' + local has_S = 'index(v:argv, "-S") >= 0 ? v:true : v:false' eq({ true, true }, { server_session:request('nvim_eval', expr) }) eq({ true, true }, { server_session:request('nvim_eval', has_s) }) + eq({ true, true }, { server_session:request('nvim_eval', has_S) }) tt.feed_data(":restart! put='foo'\013") screen:expect([[ @@ -660,6 +669,7 @@ describe('TUI :restart', function() eq({ true, false }, { server_session:request('nvim_eval', expr) }) eq({ true, false }, { server_session:request('nvim_eval', has_s) }) + eq({ true, false }, { server_session:request('nvim_eval', has_S) }) -- local argv = ({ server_session:request('nvim_eval', 'v:argv') })[2] --[[@type table]] -- eq(13, #argv)