Merge pull request #9667 from bfredl/winclose

api: add nvim_win_close() to close window by id
This commit is contained in:
Björn Linse
2019-03-03 17:30:58 +01:00
committed by GitHub
4 changed files with 96 additions and 1 deletions

View File

@@ -9,6 +9,7 @@
#include "nvim/api/window.h"
#include "nvim/api/private/defs.h"
#include "nvim/api/private/helpers.h"
#include "nvim/ex_docmd.h"
#include "nvim/vim.h"
#include "nvim/buffer.h"
#include "nvim/cursor.h"
@@ -470,3 +471,29 @@ void nvim_win_config(Window window, Integer width, Integer height,
win->w_pos_changed = true;
}
}
/// Close a window.
///
/// This is equivalent to |:close| with count except that it takes a window id.
///
/// @param window Window handle
/// @param force Behave like `:close!` The last window of a buffer with
/// unwritten changes can be closed. The buffer will become
/// hidden, even if 'hidden' is not set.
///
/// @param[out] err Error details, if any
/// @return Window number
void nvim_win_close(Window window, Boolean force, Error *err)
FUNC_API_SINCE(6)
{
win_T *win = find_window_by_handle(window, err);
if (!win) {
return;
}
tabpage_T *tabpage = win_find_tabpage(win);
TryState tstate;
try_enter(&tstate);
ex_win_close(force, win, tabpage == curtab ? NULL : tabpage);
vim_ignored = try_leave(&tstate, err);
}

View File

@@ -6170,7 +6170,7 @@ static void ex_pclose(exarg_T *eap)
* Close window "win" and take care of handling closing the last window for a
* modified buffer.
*/
static void
void
ex_win_close(
int forceit,
win_T *win,