diff options
Diffstat (limited to 'src/nvim/api/window.c')
-rw-r--r-- | src/nvim/api/window.c | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index f4af1632ec..158e149628 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -54,7 +54,7 @@ void nvim_win_set_buf(Window window, Buffer buffer, Error *err) return; } - if (switch_win(&save_curwin, &save_curtab, win, tab, false) == FAIL) { + if (switch_win_noblock(&save_curwin, &save_curtab, win, tab, false) == FAIL) { api_set_error(err, kErrorTypeException, "Failed to switch to window %d", @@ -74,7 +74,7 @@ void nvim_win_set_buf(Window window, Buffer buffer, Error *err) // So do it now. validate_cursor(); - restore_win(save_curwin, save_curtab, false); + restore_win_noblock(save_curwin, save_curtab, false); } /// Gets the (1,0)-indexed cursor position in the window. |api-indexing| @@ -381,7 +381,7 @@ Integer nvim_win_get_number(Window window, Error *err) } int tabnr; - win_get_tabwin(window, &tabnr, &rv); + win_get_tabwin(win->handle, &tabnr, &rv); return rv; } @@ -492,6 +492,35 @@ Dictionary nvim_win_get_config(Window window, Error *err) return rv; } +/// Closes the window and hide the buffer it contains (like |:hide| with a +/// |window-ID|). +/// +/// Like |:hide| the buffer becomes hidden unless another window is editing it, +/// or 'bufhidden' is `unload`, `delete` or `wipe` as opposed to |:close| or +/// |nvim_win_close|, which will close the buffer. +/// +/// @param window Window handle, or 0 for current window +/// @param[out] err Error details, if any +void nvim_win_hide(Window window, Error *err) + FUNC_API_SINCE(7) + FUNC_API_CHECK_TEXTLOCK +{ + win_T *win = find_window_by_handle(window, err); + if (!win) { + return; + } + + tabpage_T *tabpage = win_find_tabpage(win); + TryState tstate; + try_enter(&tstate); + if (tabpage == curtab) { + win_close(win, false); + } else { + win_close_othertab(win, false, tabpage); + } + vim_ignored = try_leave(&tstate, err); +} + /// Closes the window (like |:close| with a |window-ID|). /// /// @param window Window handle, or 0 for current window |