diff options
-rw-r--r-- | src/nvim/api/vim.c | 24 | ||||
-rw-r--r-- | src/nvim/ex_getln.c | 5 | ||||
-rw-r--r-- | src/nvim/message.c | 7 | ||||
-rw-r--r-- | test/functional/api/vim_spec.lua | 16 | ||||
-rw-r--r-- | test/functional/ui/messages_spec.lua | 7 | ||||
-rw-r--r-- | test/functional/ui/wildmode_spec.lua | 53 |
6 files changed, 85 insertions, 27 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 9b5e0fc40b..2e8ca384b4 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -27,6 +27,7 @@ #include "nvim/types.h" #include "nvim/ex_docmd.h" #include "nvim/screen.h" +#include "nvim/memline.h" #include "nvim/memory.h" #include "nvim/message.h" #include "nvim/edit.h" @@ -977,11 +978,20 @@ Buffer nvim_create_buf(Boolean listed, Boolean scratch, Error *err) BLN_NOOPT | BLN_NEW | (listed ? BLN_LISTED : 0)); try_end(err); if (buf == NULL) { - if (!ERROR_SET(err)) { - api_set_error(err, kErrorTypeException, "Failed to create buffer"); - } - return 0; + goto fail; } + + // Open the memline for the buffer. This will avoid spurious autocmds when + // a later nvim_buf_set_lines call would have needed to "open" the buffer. + try_start(); + block_autocmds(); + int status = ml_open(buf); + unblock_autocmds(); + try_end(err); + if (status == FAIL) { + goto fail; + } + if (scratch) { aco_save_T aco; aucmd_prepbuf(&aco, buf); @@ -991,6 +1001,12 @@ Buffer nvim_create_buf(Boolean listed, Boolean scratch, Error *err) aucmd_restbuf(&aco); } return buf->b_fnum; + +fail: + if (!ERROR_SET(err)) { + api_set_error(err, kErrorTypeException, "Failed to create buffer"); + } + return 0; } /// Open a new window. diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index ce46408872..3bfda1f9f0 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -656,10 +656,13 @@ static int command_line_execute(VimState *state, int key) redrawcmd(); save_p_ls = -1; wild_menu_showing = 0; - } else { + // don't redraw statusline if WM_LIST is showing + } else if (wild_menu_showing != WM_LIST) { win_redraw_last_status(topframe); wild_menu_showing = 0; // must be before redraw_statuslines #8385 redraw_statuslines(); + } else { + wild_menu_showing = 0; } KeyTyped = skt; if (ccline.input_fn) { diff --git a/src/nvim/message.c b/src/nvim/message.c index a597fb4866..5188824901 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -1806,8 +1806,13 @@ void msg_puts_attr_len(const char *const str, const ptrdiff_t len, int attr) // different, e.g. for Win32 console) or we just don't know where the // cursor is. if (msg_use_printf()) { + int saved_msg_col = msg_col; msg_puts_printf(str, len); - } else { + if (headless_mode) { + msg_col = saved_msg_col; + } + } + if (!msg_use_printf() || (headless_mode && default_grid.chars)) { msg_puts_display((const char_u *)str, len, attr, false); } } diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 69bd584ab4..4279a5d420 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -1336,7 +1336,7 @@ describe('API', function() eq({id=2}, meths.create_buf(true, false)) eq({id=3}, meths.create_buf(false, false)) eq(' 1 %a "[No Name]" line 1\n'.. - ' 2 "[No Name]" line 0', + ' 2 h "[No Name]" line 0', meths.command_output("ls")) -- current buffer didn't change eq({id=1}, meths.get_current_buf()) @@ -1367,14 +1367,24 @@ describe('API', function() eq({id=1}, meths.get_current_buf()) end) + it("doesn't cause BufEnter or BufWinEnter autocmds", function() + command("let g:fired = v:false") + command("au BufEnter,BufWinEnter * let g:fired = v:true") + + eq({id=2}, meths.create_buf(true, false)) + meths.buf_set_lines(2, 0, -1, true, {"test", "text"}) + + eq(false, eval('g:fired')) + end) + it('|scratch-buffer|', function() eq({id=2}, meths.create_buf(false, true)) eq({id=3}, meths.create_buf(true, true)) eq({id=4}, meths.create_buf(true, true)) local scratch_bufs = { 2, 3, 4 } eq(' 1 %a "[No Name]" line 1\n'.. - ' 3 "[Scratch]" line 0\n'.. - ' 4 "[Scratch]" line 0', + ' 3 h "[Scratch]" line 0\n'.. + ' 4 h "[Scratch]" line 0', meths.command_output("ls")) -- current buffer didn't change eq({id=1}, meths.get_current_buf()) diff --git a/test/functional/ui/messages_spec.lua b/test/functional/ui/messages_spec.lua index 42a70c9f6a..7d21f40ce9 100644 --- a/test/functional/ui/messages_spec.lua +++ b/test/functional/ui/messages_spec.lua @@ -705,11 +705,8 @@ describe('ui/ext_messages', function() end) it('wildmode=list', function() - local default_attr = screen:get_default_attr_ids() - screen:detach() - screen = Screen.new(25, 7) - screen:attach({rgb=true, ext_messages=true}) - screen:set_default_attr_ids(default_attr) + screen:try_resize(25, 7) + screen:set_option('ext_popupmenu', false) command('set wildmenu wildmode=list') feed(':set wildm<tab>') diff --git a/test/functional/ui/wildmode_spec.lua b/test/functional/ui/wildmode_spec.lua index 75b5ea9476..914256224f 100644 --- a/test/functional/ui/wildmode_spec.lua +++ b/test/functional/ui/wildmode_spec.lua @@ -15,9 +15,6 @@ describe("'wildmenu'", function() screen = Screen.new(25, 5) screen:attach() end) - after_each(function() - screen:detach() - end) -- expect the screen stayed unchanged some time after first seen success local function expect_stay_unchanged(args) @@ -170,9 +167,7 @@ describe("'wildmenu'", function() it('wildmode=list,full and display+=msgsep interaction #10092', function() -- Need more than 5 rows, else tabline is covered and will be redrawn. - screen:detach() - screen = Screen.new(25, 7) - screen:attach() + screen:try_resize(25, 7) command('set display+=msgsep') command('set wildmenu wildmode=list,full') @@ -211,9 +206,7 @@ describe("'wildmenu'", function() it('wildmode=list,full and display-=msgsep interaction', function() -- Need more than 5 rows, else tabline is covered and will be redrawn. - screen:detach() - screen = Screen.new(25, 7) - screen:attach() + screen:try_resize(25, 7) command('set display-=msgsep') command('set wildmenu wildmode=list,full') @@ -248,6 +241,44 @@ describe("'wildmenu'", function() | ]]) end) + + it('multiple <C-D> renders correctly', function() + screen:try_resize(25, 7) + + command('set laststatus=2') + command('set display+=msgsep') + feed(':set wildm') + feed('<c-d>') + screen:expect([[ + | + ~ | + ~ | + | + :set wildm | + wildmenu wildmode | + :set wildm^ | + ]]) + feed('<c-d>') + screen:expect([[ + | + | + :set wildm | + wildmenu wildmode | + :set wildm | + wildmenu wildmode | + :set wildm^ | + ]]) + feed('<Esc>') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + ~ | + [No Name] | + | + ]]) + end) end) describe('command line completion', function() @@ -324,10 +355,6 @@ describe('ui/ext_wildmenu', function() screen:attach({rgb=true, ext_wildmenu=true}) end) - after_each(function() - screen:detach() - end) - it('works with :sign <tab>', function() local expected = { 'define', |