aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/window.c
diff options
context:
space:
mode:
authorJames McCoy <jamessan@jamessan.com>2016-10-03 23:36:47 -0400
committerJames McCoy <jamessan@jamessan.com>2016-10-04 14:34:35 -0400
commit1ebb75b1ec5b22d7c7dba1c7fdc9e7969b81ad4d (patch)
tree9b2202052b77173d73efcdd7b34a273f25ff5caa /src/nvim/window.c
parentb1edc8abb7e0f11064fde9d4b208fb06f0c16a35 (diff)
downloadrneovim-1ebb75b1ec5b22d7c7dba1c7fdc9e7969b81ad4d.tar.gz
rneovim-1ebb75b1ec5b22d7c7dba1c7fdc9e7969b81ad4d.tar.bz2
rneovim-1ebb75b1ec5b22d7c7dba1c7fdc9e7969b81ad4d.zip
api: Support getting the number of a window/tabpage
In order to provide better compatibility with the classic bindings, the API needs to provide the ability to query the number (really index) of the window/tabpage. This is needed for neovim/python-client#87, as discussed in neovim/neovim#1898. Signed-off-by: James McCoy <jamessan@jamessan.com>
Diffstat (limited to 'src/nvim/window.c')
-rw-r--r--src/nvim/window.c51
1 files changed, 26 insertions, 25 deletions
diff --git a/src/nvim/window.c b/src/nvim/window.c
index e9a66ad907..2cc99b8dfa 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -5716,45 +5716,46 @@ int win_getid(typval_T *argvars)
int win_gotoid(typval_T *argvars)
{
- win_T *wp;
- tabpage_T *tp;
int id = get_tv_number(&argvars[0]);
- for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) {
- for (wp = tp == curtab ? firstwin : tp->tp_firstwin;
- wp != NULL; wp = wp->w_next) {
- if (wp->handle == id) {
- goto_tabpage_win(tp, wp);
- return 1;
- }
+ FOR_ALL_TAB_WINDOWS(tp, wp) {
+ if (wp->handle == id) {
+ goto_tabpage_win(tp, wp);
+ return 1;
}
}
return 0;
}
-void win_id2tabwin(typval_T *argvars, list_T *list)
+void win_get_tabwin(handle_T id, int *tabnr, int *winnr)
{
- win_T *wp;
- tabpage_T *tp;
- int winnr = 1;
- int tabnr = 1;
- int id = get_tv_number(&argvars[0]);
+ *tabnr = 0;
+ *winnr = 0;
- for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) {
- for (wp = tp == curtab ? firstwin : tp->tp_firstwin;
- wp != NULL; wp = wp->w_next) {
+ int tnum = 1, wnum = 1;
+ FOR_ALL_TABS(tp) {
+ FOR_ALL_WINDOWS_IN_TAB(wp, tp) {
if (wp->handle == id) {
- list_append_number(list, tabnr);
- list_append_number(list, winnr);
+ *winnr = wnum;
+ *tabnr = tnum;
return;
}
- winnr++;
+ wnum++;
}
- tabnr++;
- winnr = 1;
+ tnum++;
+ wnum = 1;
}
- list_append_number(list, 0);
- list_append_number(list, 0);
+}
+
+void win_id2tabwin(typval_T *argvars, list_T *list)
+{
+ int winnr = 1;
+ int tabnr = 1;
+ int id = get_tv_number(&argvars[0]);
+
+ win_get_tabwin(id, &tabnr, &winnr);
+ list_append_number(list, tabnr);
+ list_append_number(list, winnr);
}
int win_id2win(typval_T *argvars)