diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2018-12-27 22:49:44 +0100 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2018-12-27 22:49:44 +0100 |
commit | c1015121ec626cab6cb384f544bc0be1a1760c0e (patch) | |
tree | 6cc9a5d1899a4486a24c491e07d17a7dd01f9503 /src/nvim/api/window.c | |
parent | 4f030ec24e0e148bbb83aedaef7dd629e5fef130 (diff) | |
parent | e1876c7ad1b5e30c0a9919e2c4587d11550c8507 (diff) | |
download | rneovim-c1015121ec626cab6cb384f544bc0be1a1760c0e.tar.gz rneovim-c1015121ec626cab6cb384f544bc0be1a1760c0e.tar.bz2 rneovim-c1015121ec626cab6cb384f544bc0be1a1760c0e.zip |
Merge 'upstream/master' into pr-win-erw7
Diffstat (limited to 'src/nvim/api/window.c')
-rw-r--r-- | src/nvim/api/window.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index 5281a7c1f4..cf1d1f5e45 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -10,6 +10,7 @@ #include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" #include "nvim/vim.h" +#include "nvim/buffer.h" #include "nvim/cursor.h" #include "nvim/window.h" #include "nvim/screen.h" @@ -33,6 +34,41 @@ Buffer nvim_win_get_buf(Window window, Error *err) return win->w_buffer->handle; } +/// Sets the current buffer in a window, without side-effects +/// +/// @param window Window handle +/// @param buffer Buffer handle +/// @param[out] err Error details, if any +void nvim_win_set_buf(Window window, Buffer buffer, Error *err) + FUNC_API_SINCE(5) +{ + 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 (switch_win(&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); + } + + restore_win(save_curwin, save_curtab, false); +} + /// Gets the cursor position in the window /// /// @param window Window handle |