From 1ebb75b1ec5b22d7c7dba1c7fdc9e7969b81ad4d Mon Sep 17 00:00:00 2001 From: James McCoy Date: Mon, 3 Oct 2016 23:36:47 -0400 Subject: 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 --- src/nvim/window.c | 51 ++++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 25 deletions(-) (limited to 'src/nvim/window.c') 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) -- cgit