forked from aniani/vim
updated for version 7.3.938
Problem: Python: not easy to get to window number. Solution: Add vim.window.number. (ZyX)
This commit is contained in:
@@ -396,6 +396,10 @@ Window attributes are:
|
|||||||
|python-options|. If option is |global-local|
|
|python-options|. If option is |global-local|
|
||||||
and local value is missing getting it will
|
and local value is missing getting it will
|
||||||
return None.
|
return None.
|
||||||
|
number (read-only) Window number. The first window has number 1.
|
||||||
|
This is zero in case it cannot be determined
|
||||||
|
(e.g. when the window object belongs to other
|
||||||
|
tab page).
|
||||||
The height attribute is writable only if the screen is split horizontally.
|
The height attribute is writable only if the screen is split horizontally.
|
||||||
The width attribute is writable only if the screen is split vertically.
|
The width attribute is writable only if the screen is split vertically.
|
||||||
|
|
||||||
|
@@ -1848,9 +1848,11 @@ WindowAttr(WindowObject *this, char *name)
|
|||||||
else if (strcmp(name, "options") == 0)
|
else if (strcmp(name, "options") == 0)
|
||||||
return OptionsNew(SREQ_WIN, this->win, (checkfun) CheckWindow,
|
return OptionsNew(SREQ_WIN, this->win, (checkfun) CheckWindow,
|
||||||
(PyObject *) this);
|
(PyObject *) this);
|
||||||
|
else if (strcmp(name, "number") == 0)
|
||||||
|
return PyLong_FromLong((long) get_win_number(this->win));
|
||||||
else if (strcmp(name,"__members__") == 0)
|
else if (strcmp(name,"__members__") == 0)
|
||||||
return Py_BuildValue("[ssssss]", "buffer", "cursor", "height", "vars",
|
return Py_BuildValue("[ssssss]", "buffer", "cursor", "height", "vars",
|
||||||
"options");
|
"options", "number");
|
||||||
else
|
else
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -1974,17 +1976,13 @@ WindowRepr(PyObject *self)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int i = 0;
|
int w = get_win_number(this->win);
|
||||||
win_T *w;
|
|
||||||
|
|
||||||
for (w = firstwin; w != NULL && w != this->win; w = W_NEXT(w))
|
if (w == 0)
|
||||||
++i;
|
|
||||||
|
|
||||||
if (w == NULL)
|
|
||||||
vim_snprintf(repr, 100, _("<window object (unknown) at %p>"),
|
vim_snprintf(repr, 100, _("<window object (unknown) at %p>"),
|
||||||
(self));
|
(self));
|
||||||
else
|
else
|
||||||
vim_snprintf(repr, 100, _("<window %d>"), i);
|
vim_snprintf(repr, 100, _("<window %d>"), w - 1);
|
||||||
|
|
||||||
return PyString_FromString(repr);
|
return PyString_FromString(repr);
|
||||||
}
|
}
|
||||||
|
@@ -74,4 +74,5 @@ int match_add __ARGS((win_T *wp, char_u *grp, char_u *pat, int prio, int id));
|
|||||||
int match_delete __ARGS((win_T *wp, int id, int perr));
|
int match_delete __ARGS((win_T *wp, int id, int perr));
|
||||||
void clear_matches __ARGS((win_T *wp));
|
void clear_matches __ARGS((win_T *wp));
|
||||||
matchitem_T *get_match __ARGS((win_T *wp, int id));
|
matchitem_T *get_match __ARGS((win_T *wp, int id));
|
||||||
|
int get_win_number __ARGS((win_T *wp));
|
||||||
/* vim: set ft=c : */
|
/* vim: set ft=c : */
|
||||||
|
@@ -728,6 +728,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
938,
|
||||||
/**/
|
/**/
|
||||||
937,
|
937,
|
||||||
/**/
|
/**/
|
||||||
|
17
src/window.c
17
src/window.c
@@ -6731,3 +6731,20 @@ get_match(wp, id)
|
|||||||
return cur;
|
return cur;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
|
||||||
|
int
|
||||||
|
get_win_number(win_T *wp)
|
||||||
|
{
|
||||||
|
int i = 1;
|
||||||
|
win_T *w;
|
||||||
|
|
||||||
|
for (w = firstwin; w != NULL && w != wp; w = W_NEXT(w))
|
||||||
|
++i;
|
||||||
|
|
||||||
|
if (w == NULL)
|
||||||
|
return 0;
|
||||||
|
else
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
Reference in New Issue
Block a user