# HG changeset patch
# User ZyX <[email protected]>
# Date 1366995726 -14400
# Branch python-extended-2
# Node ID 4f40c3dc35eaf077a6154a41fa55eacb0a3a3616
# Parent 3b334f36227b3be63fcb73f9ac09723e3740243a
Add vim.window.number attribute
diff -r 3b334f36227b -r 4f40c3dc35ea runtime/doc/if_pyth.txt
--- a/runtime/doc/if_pyth.txt Fri Apr 26 20:29:53 2013 +0400
+++ b/runtime/doc/if_pyth.txt Fri Apr 26 21:02:06 2013 +0400
@@ -396,6 +396,9 @@
|python-options|. If option is |global-local|
and local value is missing getting it will
return None.
+ number (read-only) Window number or zero in case it cannot be
+ determined (e.g. when 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 -r 3b334f36227b -r 4f40c3dc35ea src/if_py_both.h
--- a/src/if_py_both.h Fri Apr 26 20:29:53 2013 +0400
+++ b/src/if_py_both.h Fri Apr 26 21:02:06 2013 +0400
@@ -1848,9 +1848,11 @@
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 @@
}
else
{
- int i = 0;
- win_T *w;
-
- for (w = firstwin; w != NULL && w != this->win; w = W_NEXT(w))
- ++i;
-
- if (w == NULL)
+ int w = get_win_number(this->win);
+
+ 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 -r 3b334f36227b -r 4f40c3dc35ea src/proto/window.pro
--- a/src/proto/window.pro Fri Apr 26 20:29:53 2013 +0400
+++ b/src/proto/window.pro Fri Apr 26 21:02:06 2013 +0400
@@ -74,4 +74,5 @@
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 -r 3b334f36227b -r 4f40c3dc35ea src/window.c
--- a/src/window.c Fri Apr 26 20:29:53 2013 +0400
+++ b/src/window.c Fri Apr 26 21:02:06 2013 +0400
@@ -6731,3 +6731,20 @@
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
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.
diff -cr vim.3b334f36227b/runtime/doc/if_pyth.txt vim.4f40c3dc35ea/runtime/doc/if_pyth.txt
*** vim.3b334f36227b/runtime/doc/if_pyth.txt 2013-04-26 21:02:40.322672064 +0400
--- vim.4f40c3dc35ea/runtime/doc/if_pyth.txt 2013-04-26 21:02:40.328675010 +0400
***************
*** 396,401 ****
--- 396,404 ----
|python-options|. If option is |global-local|
and local value is missing getting it will
return None.
+ number (read-only) Window number or zero in case it cannot be
+ determined (e.g. when 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 -cr vim.3b334f36227b/src/if_py_both.h vim.4f40c3dc35ea/src/if_py_both.h
*** vim.3b334f36227b/src/if_py_both.h 2013-04-26 21:02:40.321671573 +0400
--- vim.4f40c3dc35ea/src/if_py_both.h 2013-04-26 21:02:40.330675992 +0400
***************
*** 1848,1856 ****
else if (strcmp(name, "options") == 0)
return OptionsNew(SREQ_WIN, this->win, (checkfun) CheckWindow,
(PyObject *) this);
else if (strcmp(name,"__members__") == 0)
return Py_BuildValue("[ssssss]", "buffer", "cursor", "height", "vars",
! "options");
else
return NULL;
}
--- 1848,1858 ----
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", "number");
else
return NULL;
}
***************
*** 1974,1990 ****
}
else
{
! int i = 0;
! win_T *w;
! for (w = firstwin; w != NULL && w != this->win; w = W_NEXT(w))
! ++i;
!
! if (w == NULL)
vim_snprintf(repr, 100, _("<window object (unknown) at %p>"),
(self));
else
! vim_snprintf(repr, 100, _("<window %d>"), i);
return PyString_FromString(repr);
}
--- 1976,1988 ----
}
else
{
! int w = get_win_number(this->win);
! if (w == 0)
vim_snprintf(repr, 100, _("<window object (unknown) at %p>"),
(self));
else
! vim_snprintf(repr, 100, _("<window %d>"), w - 1);
return PyString_FromString(repr);
}
diff -cr vim.3b334f36227b/src/proto/window.pro vim.4f40c3dc35ea/src/proto/window.pro
*** vim.3b334f36227b/src/proto/window.pro 2013-04-26 21:02:40.318670100 +0400
--- vim.4f40c3dc35ea/src/proto/window.pro 2013-04-26 21:02:40.327674519 +0400
***************
*** 74,77 ****
--- 74,78 ----
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 -cr vim.3b334f36227b/src/window.c vim.4f40c3dc35ea/src/window.c
*** vim.3b334f36227b/src/window.c 2013-04-26 21:02:40.318670100 +0400
--- vim.4f40c3dc35ea/src/window.c 2013-04-26 21:02:40.326674028 +0400
***************
*** 6731,6733 ****
--- 6731,6750 ----
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