aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api/window.c
diff options
context:
space:
mode:
authorBjörn Linse <bjorn.linse@gmail.com>2019-03-03 10:26:11 +0100
committerBjörn Linse <bjorn.linse@gmail.com>2019-03-03 13:09:43 +0100
commitc8f310825cf92da2feb25a7298998fcd1da5a769 (patch)
treeab7ef5b75a2206f038d428798a788b5f7d6cc848 /src/nvim/api/window.c
parent7a6da502b9d8deecfc89d1497a8e8da15e65f31e (diff)
downloadrneovim-c8f310825cf92da2feb25a7298998fcd1da5a769.tar.gz
rneovim-c8f310825cf92da2feb25a7298998fcd1da5a769.tar.bz2
rneovim-c8f310825cf92da2feb25a7298998fcd1da5a769.zip
api: add nvim_win_close() to close window by id
Diffstat (limited to 'src/nvim/api/window.c')
-rw-r--r--src/nvim/api/window.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c
index e1d84cfc9e..157f73c9fa 100644
--- a/src/nvim/api/window.c
+++ b/src/nvim/api/window.c
@@ -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);
+}