From 97abf8ee63994c19c2119e34bc7a7aa66457a7f2 Mon Sep 17 00:00:00 2001 From: jing Date: Sat, 1 May 2021 10:00:41 +0800 Subject: [PATCH] vim-patch:8.1.1425: win_execute() does not set window pointers properly Problem: Win_execute() does not set window pointers properly. Solution: Use switch_win_noblock(). Also execute autocommands in a popup window. https://github.com/vim/vim/commit/89adc3a1371d211f7766f3dbc0975ecb2f862327 --- src/nvim/eval/funcs.c | 15 +++++++-------- src/nvim/window.c | 16 +++++++++++++++- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index fe0a4c29a2..3a202759b6 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -2042,17 +2042,16 @@ static void f_execute(typval_T *argvars, typval_T *rettv, FunPtr fptr) static void f_win_execute(typval_T *argvars, typval_T *rettv, FunPtr fptr) { win_T *wp = win_id2wp(argvars); - win_T *save_curwin = curwin; + win_T *save_curwin; + tabpage_T *save_curtab; if (wp != NULL) { - curwin = wp; - curbuf = curwin->w_buffer; - check_cursor(); - execute_common(argvars, rettv, fptr, 1); - if (win_valid(save_curwin)) { - curwin = save_curwin; - curbuf = curwin->w_buffer; + if (switch_win_noblock(&save_curwin, &save_curtab, wp, curtab, true) == + OK) { + check_cursor(); + execute_common(argvars, rettv, fptr, 1); } + restore_win_noblock(save_curwin, save_curtab, true); } } diff --git a/src/nvim/window.c b/src/nvim/window.c index c482d265ff..ddfb4e6ef3 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -6335,6 +6335,13 @@ static win_T *get_snapshot_focus(int idx) int switch_win(win_T **save_curwin, tabpage_T **save_curtab, win_T *win, tabpage_T *tp, int no_display) { block_autocmds(); + return switch_win_noblock(save_curwin, save_curtab, win, tp, no_display); +} + +// As switch_win() but without blocking autocommands. +int switch_win_noblock(win_T **save_curwin, tabpage_T **save_curtab, + win_T *win, tabpage_T *tp, int no_display) +{ *save_curwin = curwin; if (tp != NULL) { *save_curtab = curtab; @@ -6359,6 +6366,14 @@ int switch_win(win_T **save_curwin, tabpage_T **save_curtab, win_T *win, tabpage // When "no_display" is true the display won't be affected, no redraw is // triggered. void restore_win(win_T *save_curwin, tabpage_T *save_curtab, bool no_display) +{ + restore_win_noblock(save_curwin, save_curtab, no_display); + unblock_autocmds(); +} + +// As restore_win() but without unblocking autocommands. +void restore_win_noblock(win_T *save_curwin, tabpage_T *save_curtab, + bool no_display) { if (save_curtab != NULL && valid_tabpage(save_curtab)) { if (no_display) { @@ -6374,7 +6389,6 @@ void restore_win(win_T *save_curwin, tabpage_T *save_curtab, bool no_display) curwin = save_curwin; curbuf = curwin->w_buffer; } - unblock_autocmds(); } /// Make "buf" the current buffer.