summaryrefslogtreecommitdiff
path: root/src/window.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2016-03-13 18:07:30 +0100
committerBram Moolenaar <Bram@vim.org>2016-03-13 18:07:30 +0100
commit86edef664efccbfe685906c854b9cdd04e56f2d5 (patch)
tree8c60cfa3d606624d81812b058124a4eac774fab8 /src/window.c
parenta3442cb5056ca62fc71fa03f68a9395e4391caf4 (diff)
downloadvim-git-86edef664efccbfe685906c854b9cdd04e56f2d5.tar.gz
patch 7.4.1557v7.4.1557
Problem: Windows cannot be identified. Solution: Add a unique window number to each window and functions to use it.
Diffstat (limited to 'src/window.c')
-rw-r--r--src/window.c100
1 files changed, 100 insertions, 0 deletions
diff --git a/src/window.c b/src/window.c
index 7dfbe5a99..b6111bd15 100644
--- a/src/window.c
+++ b/src/window.c
@@ -4541,6 +4541,8 @@ buf_jump_open_tab(buf_T *buf)
}
#endif
+static int last_win_id = 0;
+
/*
* Allocate a window structure and link it in the window list when "hidden" is
* FALSE.
@@ -4563,6 +4565,8 @@ win_alloc(win_T *after UNUSED, int hidden UNUSED)
return NULL;
}
+ new_wp->w_id = ++last_win_id;
+
#ifdef FEAT_EVAL
/* init w: variables */
new_wp->w_vars = dict_alloc();
@@ -7198,3 +7202,99 @@ frame_check_width(frame_T *topfrp, int width)
}
#endif
+#if defined(FEAT_EVAL) || defined(PROTO)
+ int
+win_getid(typval_T *argvars)
+{
+ int winnr;
+ win_T *wp;
+
+ if (argvars[0].v_type == VAR_UNKNOWN)
+ return curwin->w_id;
+ winnr = get_tv_number(&argvars[0]);
+ if (winnr > 0)
+ {
+ if (argvars[1].v_type == VAR_UNKNOWN)
+ wp = firstwin;
+ else
+ {
+ tabpage_T *tp;
+ int tabnr = get_tv_number(&argvars[1]);
+
+ for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
+ if (--tabnr == 0)
+ break;
+ if (tp == NULL)
+ return -1;
+ wp = tp->tp_firstwin;
+ }
+ for ( ; wp != NULL; wp = wp->w_next)
+ if (--winnr == 0)
+ return wp->w_id;
+ }
+ return 0;
+}
+
+ 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->w_id == id)
+ {
+ goto_tabpage_win(tp, wp);
+ return 1;
+ }
+ return 0;
+}
+
+ void
+win_id2tabwin(typval_T *argvars, list_T *list)
+{
+ win_T *wp;
+ tabpage_T *tp;
+ int winnr = 1;
+ int tabnr = 1;
+ 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->w_id == id)
+ {
+ list_append_number(list, tabnr);
+ list_append_number(list, winnr);
+ return;
+ }
+ ++winnr;
+ }
+ ++tabnr;
+ winnr = 1;
+ }
+ list_append_number(list, 0);
+ list_append_number(list, 0);
+}
+
+ int
+win_id2win(typval_T *argvars)
+{
+ win_T *wp;
+ int nr = 1;
+ int id = get_tv_number(&argvars[0]);
+
+ for (wp = firstwin; wp != NULL; wp = wp->w_next)
+ {
+ if (wp->w_id == id)
+ return nr;
+ ++nr;
+ }
+ return 0;
+}
+#endif