summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <bram@vim.org>2013-05-12 19:00:41 +0200
committerBram Moolenaar <bram@vim.org>2013-05-12 19:00:41 +0200
commita38e2c487431ba6a5cfff3b23fd563fbc8f04256 (patch)
tree8bcde68786802c39b7e4854eba3fd28f8062b993
parent96637f24ed4571748f4b72cc42ac82bec1d0fc68 (diff)
downloadvim-a38e2c487431ba6a5cfff3b23fd563fbc8f04256.tar.gz
updated for version 7.3.938v7.3.938v7-3-938
Problem: Python: not easy to get to window number. Solution: Add vim.window.number. (ZyX)
-rw-r--r--runtime/doc/if_pyth.txt4
-rw-r--r--src/if_py_both.h14
-rw-r--r--src/proto/window.pro1
-rw-r--r--src/version.c2
-rw-r--r--src/window.c17
5 files changed, 30 insertions, 8 deletions
diff --git a/runtime/doc/if_pyth.txt b/runtime/doc/if_pyth.txt
index a6bb55c8..bf21f8cc 100644
--- a/runtime/doc/if_pyth.txt
+++ b/runtime/doc/if_pyth.txt
@@ -396,6 +396,10 @@ Window attributes are:
|python-options|. If option is |global-local|
and local value is missing getting it will
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 width attribute is writable only if the screen is split vertically.
diff --git a/src/if_py_both.h b/src/if_py_both.h
index cf0f50b0..f8b51b7a 100644
--- a/src/if_py_both.h
+++ b/src/if_py_both.h
@@ -1848,9 +1848,11 @@ WindowAttr(WindowObject *this, char *name)
else if (strcmp(name, "options") == 0)
return OptionsNew(SREQ_WIN, this->win, (checkfun) CheckWindow,
(PyObject *) this);
+ else if (strcmp(name, "number") == 0)
+ return PyLong_FromLong((long) get_win_number(this->win));
else if (strcmp(name,"__members__") == 0)
return Py_BuildValue("[ssssss]", "buffer", "cursor", "height", "vars",
- "options");
+ "options", "number");
else
return NULL;
}
@@ -1974,17 +1976,13 @@ WindowRepr(PyObject *self)
}
else
{
- int i = 0;
- win_T *w;
-
- for (w = firstwin; w != NULL && w != this->win; w = W_NEXT(w))
- ++i;
+ int w = get_win_number(this->win);
- if (w == NULL)
+ if (w == 0)
vim_snprintf(repr, 100, _("<window object (unknown) at %p>"),
(self));
else
- vim_snprintf(repr, 100, _("<window %d>"), i);
+ vim_snprintf(repr, 100, _("<window %d>"), w - 1);
return PyString_FromString(repr);
}
diff --git a/src/proto/window.pro b/src/proto/window.pro
index 0a744892..a77da59c 100644
--- a/src/proto/window.pro
+++ b/src/proto/window.pro
@@ -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));
void clear_matches __ARGS((win_T *wp));
matchitem_T *get_match __ARGS((win_T *wp, int id));
+int get_win_number __ARGS((win_T *wp));
/* vim: set ft=c : */
diff --git a/src/version.c b/src/version.c
index 884b5c6c..f6d3840d 100644
--- a/src/version.c
+++ b/src/version.c
@@ -729,6 +729,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 938,
+/**/
937,
/**/
936,
diff --git a/src/window.c b/src/window.c
index 4616c803..03547149 100644
--- a/src/window.c
+++ b/src/window.c
@@ -6731,3 +6731,20 @@ get_match(wp, id)
return cur;
}
#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