summaryrefslogtreecommitdiff
path: root/src/window.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2019-08-30 15:46:30 +0200
committerBram Moolenaar <Bram@vim.org>2019-08-30 15:46:30 +0200
commit8d71b54409ca6cf989dfb7d7fe265768fb7fe062 (patch)
tree31f394027b56f1dbd68f7723320384e2594c541c /src/window.c
parent58a297b28d2a8127c72bd860c4a7175a5e9c97f3 (diff)
downloadvim-git-8d71b54409ca6cf989dfb7d7fe265768fb7fe062.tar.gz
patch 8.1.1943: more code can be moved to evalvars.cv8.1.1943
Problem: More code can be moved to evalvars.c. Solution: Move it, clean up comments. Also move some window related functions to window.c. (Yegappan Lakshmanan, closes #4874)
Diffstat (limited to 'src/window.c')
-rw-r--r--src/window.c103
1 files changed, 103 insertions, 0 deletions
diff --git a/src/window.c b/src/window.c
index 0507cee66..6f27c5c14 100644
--- a/src/window.c
+++ b/src/window.c
@@ -6970,6 +6970,109 @@ win_findbuf(typval_T *argvars, list_T *list)
}
/*
+ * Find window specified by "vp" in tabpage "tp".
+ */
+ win_T *
+find_win_by_nr(
+ typval_T *vp,
+ tabpage_T *tp) // NULL for current tab page
+{
+ win_T *wp;
+ int nr = (int)tv_get_number_chk(vp, NULL);
+
+ if (nr < 0)
+ return NULL;
+ if (nr == 0)
+ return curwin;
+
+ FOR_ALL_WINDOWS_IN_TAB(tp, wp)
+ {
+ if (nr >= LOWEST_WIN_ID)
+ {
+ if (wp->w_id == nr)
+ return wp;
+ }
+ else if (--nr <= 0)
+ break;
+ }
+ if (nr >= LOWEST_WIN_ID)
+ {
+#ifdef FEAT_TEXT_PROP
+ // check tab-local popup windows
+ for (wp = tp->tp_first_popupwin; wp != NULL; wp = wp->w_next)
+ if (wp->w_id == nr)
+ return wp;
+ // check global popup windows
+ for (wp = first_popupwin; wp != NULL; wp = wp->w_next)
+ if (wp->w_id == nr)
+ return wp;
+#endif
+ return NULL;
+ }
+ return wp;
+}
+
+/*
+ * Find a window: When using a Window ID in any tab page, when using a number
+ * in the current tab page.
+ */
+ win_T *
+find_win_by_nr_or_id(typval_T *vp)
+{
+ int nr = (int)tv_get_number_chk(vp, NULL);
+
+ if (nr >= LOWEST_WIN_ID)
+ return win_id2wp(tv_get_number(vp));
+ return find_win_by_nr(vp, NULL);
+}
+
+/*
+ * Find window specified by "wvp" in tabpage "tvp".
+ * Returns the tab page in 'ptp'
+ */
+ win_T *
+find_tabwin(
+ typval_T *wvp, // VAR_UNKNOWN for current window
+ typval_T *tvp, // VAR_UNKNOWN for current tab page
+ tabpage_T **ptp)
+{
+ win_T *wp = NULL;
+ tabpage_T *tp = NULL;
+ long n;
+
+ if (wvp->v_type != VAR_UNKNOWN)
+ {
+ if (tvp->v_type != VAR_UNKNOWN)
+ {
+ n = (long)tv_get_number(tvp);
+ if (n >= 0)
+ tp = find_tabpage(n);
+ }
+ else
+ tp = curtab;
+
+ if (tp != NULL)
+ {
+ wp = find_win_by_nr(wvp, tp);
+ if (wp == NULL && wvp->v_type == VAR_NUMBER
+ && wvp->vval.v_number != -1)
+ // A window with the specified number is not found
+ tp = NULL;
+ }
+ }
+ else
+ {
+ wp = curwin;
+ tp = curtab;
+ }
+
+ if (ptp != NULL)
+ *ptp = tp;
+
+ return wp;
+}
+
+/*
* Get the layout of the given tab page for winlayout().
*/
void