diff options
-rw-r--r-- | src/nvim/ex_docmd.c | 7 | ||||
-rw-r--r-- | src/nvim/ex_getln.c | 7 | ||||
-rw-r--r-- | src/nvim/main.c | 6 | ||||
-rw-r--r-- | src/nvim/option.c | 2 | ||||
-rw-r--r-- | test/functional/core/startup_spec.lua | 12 |
5 files changed, 27 insertions, 7 deletions
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index b7863402d5..b59f852c2d 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -6033,10 +6033,11 @@ static void ex_cquit(exarg_T *eap) static void ex_quit_all(exarg_T *eap) { if (cmdwin_type != 0) { - if (eap->forceit) - cmdwin_result = K_XF1; /* ex_window() takes care of this */ - else + if (eap->forceit) { + cmdwin_result = K_XF1; // open_cmdwin() takes care of this + } else { cmdwin_result = K_XF2; + } return; } diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 9b1dcfcafb..774007c66e 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -861,7 +861,7 @@ static int command_line_execute(VimState *state, int key) if (s->c == cedit_key || s->c == K_CMDWIN) { if (ex_normal_busy == 0 && got_int == false) { // Open a window to edit the command line (and history). - s->c = ex_window(); + s->c = open_cmdwin(); s->some_key_typed = true; } } else { @@ -1444,7 +1444,7 @@ static int command_line_handle_key(CommandLineState *s) return command_line_not_changed(s); case K_IGNORE: - // Ignore mouse event or ex_window() result. + // Ignore mouse event or open_cmdwin() result. return command_line_not_changed(s); @@ -6001,7 +6001,7 @@ int cmd_gchar(int offset) * Ctrl_C if it is to be abandoned * K_IGNORE if editing continues */ -static int ex_window(void) +static int open_cmdwin(void) { struct cmdline_info save_ccline; bufref_T old_curbuf; @@ -6034,6 +6034,7 @@ static int ex_window(void) block_autocmds(); /* don't use a new tab page */ cmdmod.tab = 0; + cmdmod.noswapfile = 1; /* Create a window for the command-line buffer. */ if (win_split((int)p_cwh, WSP_BOT) == FAIL) { diff --git a/src/nvim/main.c b/src/nvim/main.c index ea43b93b30..6aed84aba5 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -1410,6 +1410,12 @@ static void read_stdin(void) int save_msg_didany = msg_didany; set_buflisted(true); (void)open_buffer(true, NULL, 0); // create memfile and read file + if (BUFEMPTY() && curbuf->b_next != NULL) { + // stdin was empty, go to buffer 2 (e.g. "echo file1 | xargs nvim"). #8561 + do_cmdline_cmd("silent! bnext"); + // Delete the empty stdin buffer. + do_cmdline_cmd("bwipeout 1"); + } no_wait_return = false; msg_didany = save_msg_didany; TIME_MSG("reading stdin"); diff --git a/src/nvim/option.c b/src/nvim/option.c index 0851e6cc5f..68b0a525f1 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -5811,7 +5811,7 @@ void buf_copy_options(buf_T *buf, int flags) buf->b_p_ml = p_ml; buf->b_p_ml_nobin = p_ml_nobin; buf->b_p_inf = p_inf; - buf->b_p_swf = p_swf; + buf->b_p_swf = cmdmod.noswapfile ? false : p_swf; buf->b_p_cpt = vim_strsave(p_cpt); buf->b_p_cfu = vim_strsave(p_cfu); buf->b_p_ofu = vim_strsave(p_ofu); diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index ae5e2b4115..2a67453bce 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -122,6 +122,18 @@ describe('startup', function() { 'ohyeah', '' })) end) + it('if stdin is empty: selects buffer 2, deletes buffer 1 #8561', function() + eq('\r\n 2 %a "file1" line 0\r\n 3 "file2" line 0', + funcs.system({nvim_prog, '-n', '-u', 'NONE', '-i', 'NONE', '--headless', + '+ls!', + '+qall!', + '-', + 'file1', + 'file2', + }, + { '' })) + end) + it('-e/-E interactive #7679', function() clear('-e') local screen = Screen.new(25, 3) |