diff options
author | Sean Dewar <seandewar@users.noreply.github.com> | 2021-05-27 22:10:42 +0100 |
---|---|---|
committer | Sean Dewar <seandewar@users.noreply.github.com> | 2021-06-01 03:05:04 +0100 |
commit | 802f8429d5d908457658e4b9859d8ed110bc0247 (patch) | |
tree | 7436cfb300621c512d8580ca07e3cb591837831d /src/nvim/window.c | |
parent | 27c616d688c73c406726c949a3b664f52d4e4f04 (diff) | |
download | rneovim-802f8429d5d908457658e4b9859d8ed110bc0247.tar.gz rneovim-802f8429d5d908457658e4b9859d8ed110bc0247.tar.bz2 rneovim-802f8429d5d908457658e4b9859d8ed110bc0247.zip |
api(nvim_open_win): add "noautocmd" option
This option, when set, stops nvim_open_win() from potentially firing
buffer-related autocmd events
(BufEnter, BufLeave and BufWinEnter in the case of nvim_open_win()).
Diffstat (limited to 'src/nvim/window.c')
-rw-r--r-- | src/nvim/window.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/nvim/window.c b/src/nvim/window.c index 936bfa8c5b..cdeae2e294 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -570,6 +570,45 @@ static void cmd_with_count(char *cmd, char_u *bufp, size_t bufsize, } } +void win_set_buf(Window window, Buffer buffer, bool noautocmd, Error *err) +{ + win_T *win = find_window_by_handle(window, err), *save_curwin = curwin; + buf_T *buf = find_buffer_by_handle(buffer, err); + tabpage_T *tab = win_find_tabpage(win), *save_curtab = curtab; + + if (!win || !buf) { + return; + } + + if (noautocmd) { + block_autocmds(); + } + if (switch_win_noblock(&save_curwin, &save_curtab, win, tab, false) == FAIL) { + api_set_error(err, + kErrorTypeException, + "Failed to switch to window %d", + window); + } + + try_start(); + int result = do_buffer(DOBUF_GOTO, DOBUF_FIRST, FORWARD, buf->b_fnum, 0); + if (!try_end(err) && result == FAIL) { + api_set_error(err, + kErrorTypeException, + "Failed to set buffer %d", + buffer); + } + + // If window is not current, state logic will not validate its cursor. + // So do it now. + validate_cursor(); + + restore_win_noblock(save_curwin, save_curtab, false); + if (noautocmd) { + unblock_autocmds(); + } +} + /// Create a new float. /// /// if wp == NULL allocate a new window, otherwise turn existing window into a |