From d44ed79ccc43b59fec9ef622f18f543ef1c73263 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 17 Jun 2018 23:05:28 +0200 Subject: startup: go to buffer 2 if stdin is empty If stdin is not a TTY we read it into buffer 1, as text. But if the stdin pipe is empty, Nvim was most likely invoked for some other reason. DWIM: select buffer 2 (if it exists). Example: echo file1 | xargs nvim closes #8560 closes #8561 ref https://github.com/equalsraf/neovim-qt/issues/417 --- src/nvim/main.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src') diff --git a/src/nvim/main.c b/src/nvim/main.c index ea43b93b30..9c9be4aa02 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 + msg_silent++; + do_buffer(DOBUF_GOTO, DOBUF_FIRST, FORWARD, curbuf->b_next->handle, 0); + msg_silent--; + } no_wait_return = false; msg_didany = save_msg_didany; TIME_MSG("reading stdin"); -- cgit From 9625e9da75dbfd2e1925dabe28ec85583dc712b2 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 18 Jun 2018 18:48:28 +0200 Subject: startup: delete empty stdin buffer if other files were opened DWIM: avoid empty buffer 1 when stdin was empty. If other files were specified at startup, we assume that stdin is only accidentally not-a-TTY: user did not intend to send text from it. ref #8560 ref #8561 --- src/nvim/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/nvim/main.c b/src/nvim/main.c index 9c9be4aa02..6aed84aba5 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -1412,9 +1412,9 @@ static void read_stdin(void) (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 - msg_silent++; - do_buffer(DOBUF_GOTO, DOBUF_FIRST, FORWARD, curbuf->b_next->handle, 0); - msg_silent--; + do_cmdline_cmd("silent! bnext"); + // Delete the empty stdin buffer. + do_cmdline_cmd("bwipeout 1"); } no_wait_return = false; msg_didany = save_msg_didany; -- cgit