diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2018-06-17 23:05:28 +0200 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2018-06-18 17:51:38 +0200 |
commit | d44ed79ccc43b59fec9ef622f18f543ef1c73263 (patch) | |
tree | e97e3802b1dccbae1498d8d0b3ce88950d134842 | |
parent | 63b5f05d4724bba9aa33fd813ac1f4f93c891260 (diff) | |
download | rneovim-d44ed79ccc43b59fec9ef622f18f543ef1c73263.tar.gz rneovim-d44ed79ccc43b59fec9ef622f18f543ef1c73263.tar.bz2 rneovim-d44ed79ccc43b59fec9ef622f18f543ef1c73263.zip |
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
-rw-r--r-- | src/nvim/main.c | 6 | ||||
-rw-r--r-- | test/functional/core/startup_spec.lua | 12 |
2 files changed, 18 insertions, 0 deletions
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"); diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index ae5e2b4115..5f18b902fb 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('goes to buffer 2 if stdin is empty #8561', function() + eq('\r\n 1u# "[No Name]" line 1\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) |