summaryrefslogtreecommitdiff
path: root/src/if_python.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2013-05-15 15:12:29 +0200
committerBram Moolenaar <Bram@vim.org>2013-05-15 15:12:29 +0200
commit5e538ecd5e68b90f630be7bb177ab64e1285e40b (patch)
treea2de7e503d39d22f9edb40253bb8cfb15d6f9a8e /src/if_python.c
parent03db85b398746a252345ed8a7da69f0f2591e932 (diff)
downloadvim-5e538ecd5e68b90f630be7bb177ab64e1285e40b.zip
updated for version 7.3.949
Problem: Python: no easy access to tabpages. Solution: Add vim.tabpages and vim.current.tabpage. (ZyX)
Diffstat (limited to 'src/if_python.c')
-rw-r--r--src/if_python.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/if_python.c b/src/if_python.c
index 575f82200..b756c3c6a 100644
--- a/src/if_python.c
+++ b/src/if_python.c
@@ -624,10 +624,12 @@ static int initialised = 0;
#define WIN_PYTHON_REF(win) win->w_python_ref
#define BUF_PYTHON_REF(buf) buf->b_python_ref
+#define TAB_PYTHON_REF(tab) tab->tp_python_ref
static PyObject *OutputGetattr(PyObject *, char *);
static PyObject *BufferGetattr(PyObject *, char *);
static PyObject *WindowGetattr(PyObject *, char *);
+static PyObject *TabPageGetattr(PyObject *, char *);
static PyObject *RangeGetattr(PyObject *, char *);
static PyObject *DictionaryGetattr(PyObject *, char*);
static PyObject *ListGetattr(PyObject *, char *);
@@ -1137,6 +1139,24 @@ RangeAssSlice(PyObject *self, PyInt lo, PyInt hi, PyObject *val)
&((RangeObject *)(self))->end);
}
+/* TabPage object - Implementation
+ */
+
+ static PyObject *
+TabPageGetattr(PyObject *self, char *name)
+{
+ PyObject *r;
+
+ if (CheckTabPage((TabPageObject *)(self)))
+ return NULL;
+
+ r = TabPageAttr((TabPageObject *)(self), name);
+ if (r || PyErr_Occurred())
+ return r;
+ else
+ return Py_FindMethod(TabPageMethods, self, name);
+}
+
/* Window object - Implementation
*/
@@ -1155,6 +1175,24 @@ WindowGetattr(PyObject *self, char *name)
return Py_FindMethod(WindowMethods, self, name);
}
+/* Tab page list object - Definitions
+ */
+
+static PySequenceMethods TabListAsSeq = {
+ (PyInquiry) TabListLength, /* sq_length, len(x) */
+ (binaryfunc) 0, /* sq_concat, x+y */
+ (PyIntArgFunc) 0, /* sq_repeat, x*n */
+ (PyIntArgFunc) TabListItem, /* sq_item, x[i] */
+ (PyIntIntArgFunc) 0, /* sq_slice, x[i:j] */
+ (PyIntObjArgProc) 0, /* sq_ass_item, x[i]=v */
+ (PyIntIntObjArgProc) 0, /* sq_ass_slice, x[i:j]=v */
+ (objobjproc) 0,
+#if PY_MAJOR_VERSION >= 2
+ (binaryfunc) 0,
+ 0,
+#endif
+};
+
/* Window list object - Definitions
*/
@@ -1198,6 +1236,17 @@ python_window_free(win_T *win)
WIN_PYTHON_REF(win) = NULL;
}
}
+
+ void
+python_tabpage_free(tabpage_T *tab)
+{
+ if (TAB_PYTHON_REF(tab) != NULL)
+ {
+ TabPageObject *tp = TAB_PYTHON_REF(tab);
+ tp->tab = INVALID_TABPAGE_VALUE;
+ TAB_PYTHON_REF(tab) = NULL;
+ }
+}
#endif
static BufMapObject TheBufferMap =
@@ -1208,6 +1257,7 @@ static BufMapObject TheBufferMap =
static WinListObject TheWindowList =
{
PyObject_HEAD_INIT(&WinListType)
+ NULL
};
static CurrentObject TheCurrent =
@@ -1215,6 +1265,11 @@ static CurrentObject TheCurrent =
PyObject_HEAD_INIT(&CurrentType)
};
+static TabListObject TheTabPageList =
+{
+ PyObject_HEAD_INIT(&TabListType)
+};
+
static int
PythonMod_Init(void)
{
@@ -1229,8 +1284,10 @@ PythonMod_Init(void)
PyType_Ready(&BufferType);
PyType_Ready(&RangeType);
PyType_Ready(&WindowType);
+ PyType_Ready(&TabPageType);
PyType_Ready(&BufMapType);
PyType_Ready(&WinListType);
+ PyType_Ready(&TabListType);
PyType_Ready(&CurrentType);
PyType_Ready(&OptionsType);
@@ -1246,6 +1303,7 @@ PythonMod_Init(void)
PyDict_SetItemString(dict, "buffers", (PyObject *)(void *)&TheBufferMap);
PyDict_SetItemString(dict, "current", (PyObject *)(void *)&TheCurrent);
PyDict_SetItemString(dict, "windows", (PyObject *)(void *)&TheWindowList);
+ PyDict_SetItemString(dict, "tabpages", (PyObject *)(void *)&TheTabPageList);
tmp = DictionaryNew(&globvardict);
PyDict_SetItemString(dict, "vars", tmp);
Py_DECREF(tmp);