annotate src/if_py_both.h @ 4496:ebd94eabfd80 v7.3.996

updated for version 7.3.996 Problem: Python: Can't check types of what is returned by bindeval(). Solution: Add vim.List, vim.Dictionary and vim.Function types. (ZyX)
author Bram Moolenaar <bram@vim.org>
date Tue, 21 May 2013 19:50:34 +0200
parents 6d517f6e5f0b
children ef02f32d8e53
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
2399
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2 *
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4 *
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
8 */
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
9 /*
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
10 * Python extensions by Paul Moore, David Leonard, Roland Puntaier, Nikolay
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
11 * Pavlov.
2399
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
12 *
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
13 * Common code for if_python.c and if_python3.c.
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
14 */
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
15
3734
956b1ed19282 updated for version 7.3.626
Bram Moolenaar <bram@vim.org>
parents: 3703
diff changeset
16 #if PY_VERSION_HEX < 0x02050000
956b1ed19282 updated for version 7.3.626
Bram Moolenaar <bram@vim.org>
parents: 3703
diff changeset
17 typedef int Py_ssize_t; /* Python 2.4 and earlier don't have this type. */
956b1ed19282 updated for version 7.3.626
Bram Moolenaar <bram@vim.org>
parents: 3703
diff changeset
18 #endif
956b1ed19282 updated for version 7.3.626
Bram Moolenaar <bram@vim.org>
parents: 3703
diff changeset
19
2919
b67d3a44262a updated for version 7.3.232
Bram Moolenaar <bram@vim.org>
parents: 2894
diff changeset
20 #ifdef FEAT_MBYTE
b67d3a44262a updated for version 7.3.232
Bram Moolenaar <bram@vim.org>
parents: 2894
diff changeset
21 # define ENC_OPT p_enc
b67d3a44262a updated for version 7.3.232
Bram Moolenaar <bram@vim.org>
parents: 2894
diff changeset
22 #else
b67d3a44262a updated for version 7.3.232
Bram Moolenaar <bram@vim.org>
parents: 2894
diff changeset
23 # define ENC_OPT "latin1"
b67d3a44262a updated for version 7.3.232
Bram Moolenaar <bram@vim.org>
parents: 2894
diff changeset
24 #endif
4435
9b800f0a757f updated for version 7.3.966
Bram Moolenaar <bram@vim.org>
parents: 4433
diff changeset
25 #define DOPY_FUNC "_vim_pydo"
2919
b67d3a44262a updated for version 7.3.232
Bram Moolenaar <bram@vim.org>
parents: 2894
diff changeset
26
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
27 #define PyErr_SetVim(str) PyErr_SetString(VimError, str)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
28
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
29 #define INVALID_BUFFER_VALUE ((buf_T *)(-1))
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
30 #define INVALID_WINDOW_VALUE ((win_T *)(-1))
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
31 #define INVALID_TABPAGE_VALUE ((tabpage_T *)(-1))
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
32
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
33 typedef void (*rangeinitializer)(void *);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
34 typedef void (*runner)(const char *, void *, PyGILState_STATE *);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
35
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
36 static int ConvertFromPyObject(PyObject *, typval_T *);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
37 static int _ConvertFromPyObject(PyObject *, typval_T *, PyObject *);
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
38 static PyObject *WindowNew(win_T *, tabpage_T *);
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
39 static PyObject *BufferNew (buf_T *);
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
40 static PyObject *LineToString(const char *);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
41
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
42 static PyInt RangeStart;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
43 static PyInt RangeEnd;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
44
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
45 static PyObject *globals;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
46
2399
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
47 /*
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
48 * obtain a lock on the Vim data structures
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
49 */
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
50 static void
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
51 Python_Lock_Vim(void)
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
52 {
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
53 }
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
54
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
55 /*
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
56 * release a lock on the Vim data structures
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
57 */
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
58 static void
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
59 Python_Release_Vim(void)
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
60 {
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
61 }
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
62
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
63 /* Output buffer management
2399
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
64 */
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
65
2582
2cdbc91795ca updated for version 7.3.007
Bram Moolenaar <bram@vim.org>
parents: 2520
diff changeset
66 /* Function to write a line, points to either msg() or emsg(). */
2399
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
67 typedef void (*writefn)(char_u *);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
68
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
69 static PyTypeObject OutputType;
2399
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
70
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
71 typedef struct
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
72 {
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
73 PyObject_HEAD
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
74 long softspace;
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
75 long error;
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
76 } OutputObject;
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
77
3826
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
78 static int
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
79 OutputSetattr(OutputObject *self, char *name, PyObject *val)
3826
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
80 {
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
81 if (val == NULL)
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
82 {
4405
907b1f035ee7 updated for version 7.3.951
Bram Moolenaar <bram@vim.org>
parents: 4403
diff changeset
83 PyErr_SetString(PyExc_AttributeError,
907b1f035ee7 updated for version 7.3.951
Bram Moolenaar <bram@vim.org>
parents: 4403
diff changeset
84 _("can't delete OutputObject attributes"));
3826
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
85 return -1;
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
86 }
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
87
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
88 if (strcmp(name, "softspace") == 0)
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
89 {
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
90 if (!PyInt_Check(val))
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
91 {
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
92 PyErr_SetString(PyExc_TypeError, _("softspace must be an integer"));
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
93 return -1;
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
94 }
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
95
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
96 self->softspace = PyInt_AsLong(val);
3826
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
97 return 0;
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
98 }
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
99
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
100 PyErr_SetString(PyExc_AttributeError, _("invalid attribute"));
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
101 return -1;
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
102 }
530f5a903031 updated for version 7.3.671
Bram Moolenaar <bram@vim.org>
parents: 3824
diff changeset
103
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
104 /* Buffer IO, we write one whole line at a time. */
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
105 static garray_T io_ga = {0, 0, 1, 80, NULL};
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
106 static writefn old_fn = NULL;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
107
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
108 static void
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
109 PythonIO_Flush(void)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
110 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
111 if (old_fn != NULL && io_ga.ga_len > 0)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
112 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
113 ((char_u *)io_ga.ga_data)[io_ga.ga_len] = NUL;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
114 old_fn((char_u *)io_ga.ga_data);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
115 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
116 io_ga.ga_len = 0;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
117 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
118
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
119 static void
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
120 writer(writefn fn, char_u *str, PyInt n)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
121 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
122 char_u *ptr;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
123
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
124 /* Flush when switching output function. */
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
125 if (fn != old_fn)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
126 PythonIO_Flush();
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
127 old_fn = fn;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
128
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
129 /* Write each NL separated line. Text after the last NL is kept for
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
130 * writing later. */
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
131 while (n > 0 && (ptr = memchr(str, '\n', n)) != NULL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
132 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
133 PyInt len = ptr - str;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
134
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
135 if (ga_grow(&io_ga, (int)(len + 1)) == FAIL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
136 break;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
137
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
138 mch_memmove(((char *)io_ga.ga_data) + io_ga.ga_len, str, (size_t)len);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
139 ((char *)io_ga.ga_data)[io_ga.ga_len + len] = NUL;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
140 fn((char_u *)io_ga.ga_data);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
141 str = ptr + 1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
142 n -= len + 1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
143 io_ga.ga_len = 0;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
144 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
145
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
146 /* Put the remaining text into io_ga for later printing. */
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
147 if (n > 0 && ga_grow(&io_ga, (int)(n + 1)) == OK)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
148 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
149 mch_memmove(((char *)io_ga.ga_data) + io_ga.ga_len, str, (size_t)n);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
150 io_ga.ga_len += (int)n;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
151 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
152 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
153
2399
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
154 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
155 OutputWrite(OutputObject *self, PyObject *args)
2399
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
156 {
3806
5e909c379a1e updated for version 7.3.661
Bram Moolenaar <bram@vim.org>
parents: 3800
diff changeset
157 Py_ssize_t len = 0;
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
158 char *str = NULL;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
159 int error = self->error;
2399
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
160
3056
2665b456ee59 updated for version 7.3.300
Bram Moolenaar <bram@vim.org>
parents: 2933
diff changeset
161 if (!PyArg_ParseTuple(args, "et#", ENC_OPT, &str, &len))
2399
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
162 return NULL;
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
163
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
164 Py_BEGIN_ALLOW_THREADS
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
165 Python_Lock_Vim();
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
166 writer((writefn)(error ? emsg : msg), (char_u *)str, len);
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
167 Python_Release_Vim();
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
168 Py_END_ALLOW_THREADS
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
169 PyMem_Free(str);
2399
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
170
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
171 Py_INCREF(Py_None);
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
172 return Py_None;
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
173 }
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
174
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
175 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
176 OutputWritelines(OutputObject *self, PyObject *args)
2399
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
177 {
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
178 PyInt n;
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
179 PyInt i;
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
180 PyObject *list;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
181 int error = self->error;
2399
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
182
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
183 if (!PyArg_ParseTuple(args, "O", &list))
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
184 return NULL;
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
185 Py_INCREF(list);
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
186
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
187 if (!PyList_Check(list))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
188 {
2399
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
189 PyErr_SetString(PyExc_TypeError, _("writelines() requires list of strings"));
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
190 Py_DECREF(list);
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
191 return NULL;
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
192 }
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
193
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
194 n = PyList_Size(list);
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
195
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
196 for (i = 0; i < n; ++i)
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
197 {
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
198 PyObject *line = PyList_GetItem(list, i);
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
199 char *str = NULL;
2399
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
200 PyInt len;
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
201
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
202 if (!PyArg_Parse(line, "et#", ENC_OPT, &str, &len))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
203 {
2399
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
204 PyErr_SetString(PyExc_TypeError, _("writelines() requires list of strings"));
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
205 Py_DECREF(list);
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
206 return NULL;
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
207 }
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
208
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
209 Py_BEGIN_ALLOW_THREADS
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
210 Python_Lock_Vim();
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
211 writer((writefn)(error ? emsg : msg), (char_u *)str, len);
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
212 Python_Release_Vim();
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
213 Py_END_ALLOW_THREADS
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
214 PyMem_Free(str);
2399
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
215 }
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
216
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
217 Py_DECREF(list);
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
218 Py_INCREF(Py_None);
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
219 return Py_None;
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
220 }
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
221
2727
62e8d93241cd updated for version 7.3.142
Bram Moolenaar <bram@vim.org>
parents: 2615
diff changeset
222 static PyObject *
4492
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
223 OutputFlush(PyObject *self UNUSED)
2727
62e8d93241cd updated for version 7.3.142
Bram Moolenaar <bram@vim.org>
parents: 2615
diff changeset
224 {
62e8d93241cd updated for version 7.3.142
Bram Moolenaar <bram@vim.org>
parents: 2615
diff changeset
225 /* do nothing */
62e8d93241cd updated for version 7.3.142
Bram Moolenaar <bram@vim.org>
parents: 2615
diff changeset
226 Py_INCREF(Py_None);
62e8d93241cd updated for version 7.3.142
Bram Moolenaar <bram@vim.org>
parents: 2615
diff changeset
227 return Py_None;
62e8d93241cd updated for version 7.3.142
Bram Moolenaar <bram@vim.org>
parents: 2615
diff changeset
228 }
62e8d93241cd updated for version 7.3.142
Bram Moolenaar <bram@vim.org>
parents: 2615
diff changeset
229
2399
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
230 /***************/
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
231
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
232 static struct PyMethodDef OutputMethods[] = {
4492
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
233 /* name, function, calling, doc */
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
234 {"write", (PyCFunction)OutputWrite, METH_VARARGS, ""},
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
235 {"writelines", (PyCFunction)OutputWritelines, METH_VARARGS, ""},
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
236 {"flush", (PyCFunction)OutputFlush, METH_NOARGS, ""},
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
237 { NULL, NULL, 0, NULL}
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
238 };
2399
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
239
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
240 static OutputObject Output =
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
241 {
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
242 PyObject_HEAD_INIT(&OutputType)
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
243 0,
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
244 0
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
245 };
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
246
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
247 static OutputObject Error =
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
248 {
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
249 PyObject_HEAD_INIT(&OutputType)
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
250 0,
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
251 1
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
252 };
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
253
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
254 static int
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
255 PythonIO_Init_io(void)
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
256 {
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
257 PySys_SetObject("stdout", (PyObject *)(void *)&Output);
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
258 PySys_SetObject("stderr", (PyObject *)(void *)&Error);
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
259
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
260 if (PyErr_Occurred())
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
261 {
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
262 EMSG(_("E264: Python: Error initialising I/O objects"));
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
263 return -1;
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
264 }
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
265
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
266 return 0;
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
267 }
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
268
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
269
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
270 static PyObject *VimError;
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
271
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
272 /* Check to see whether a Vim error has been reported, or a keyboard
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
273 * interrupt has been detected.
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
274 */
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
275 static int
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
276 VimErrorCheck(void)
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
277 {
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
278 if (got_int)
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
279 {
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
280 PyErr_SetNone(PyExc_KeyboardInterrupt);
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
281 return 1;
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
282 }
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
283 else if (did_emsg && !PyErr_Occurred())
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
284 {
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
285 PyErr_SetNone(VimError);
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
286 return 1;
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
287 }
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
288
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
289 return 0;
76f0c4918f5c Move some common code from if_python.c and if_python3.c to if_py_both.h.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
290 }
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
291
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
292 /* Vim module - Implementation
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
293 */
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
294
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
295 static PyObject *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
296 VimCommand(PyObject *self UNUSED, PyObject *args)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
297 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
298 char *cmd;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
299 PyObject *result;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
300
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
301 if (!PyArg_ParseTuple(args, "s", &cmd))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
302 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
303
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
304 PyErr_Clear();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
305
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
306 Py_BEGIN_ALLOW_THREADS
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
307 Python_Lock_Vim();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
308
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
309 do_cmdline_cmd((char_u *)cmd);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
310 update_screen(VALID);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
311
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
312 Python_Release_Vim();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
313 Py_END_ALLOW_THREADS
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
314
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
315 if (VimErrorCheck())
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
316 result = NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
317 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
318 result = Py_None;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
319
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
320 Py_XINCREF(result);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
321 return result;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
322 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
323
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
324 /*
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
325 * Function to translate a typval_T into a PyObject; this will recursively
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
326 * translate lists/dictionaries into their Python equivalents.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
327 *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
328 * The depth parameter is to avoid infinite recursion, set it to 1 when
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
329 * you call VimToPython.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
330 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
331 static PyObject *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
332 VimToPython(typval_T *our_tv, int depth, PyObject *lookupDict)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
333 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
334 PyObject *result;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
335 PyObject *newObj;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
336 char ptrBuf[sizeof(void *) * 2 + 3];
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
337
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
338 /* Avoid infinite recursion */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
339 if (depth > 100)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
340 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
341 Py_INCREF(Py_None);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
342 result = Py_None;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
343 return result;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
344 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
345
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
346 /* Check if we run into a recursive loop. The item must be in lookupDict
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
347 * then and we can use it again. */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
348 if ((our_tv->v_type == VAR_LIST && our_tv->vval.v_list != NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
349 || (our_tv->v_type == VAR_DICT && our_tv->vval.v_dict != NULL))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
350 {
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
351 sprintf(ptrBuf, "%p",
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
352 our_tv->v_type == VAR_LIST ? (void *)our_tv->vval.v_list
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
353 : (void *)our_tv->vval.v_dict);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
354 result = PyDict_GetItemString(lookupDict, ptrBuf);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
355 if (result != NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
356 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
357 Py_INCREF(result);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
358 return result;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
359 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
360 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
361
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
362 if (our_tv->v_type == VAR_STRING)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
363 {
3852
0f5ee2629635 updated for version 7.3.683
Bram Moolenaar <bram@vim.org>
parents: 3828
diff changeset
364 result = Py_BuildValue("s", our_tv->vval.v_string == NULL
0f5ee2629635 updated for version 7.3.683
Bram Moolenaar <bram@vim.org>
parents: 3828
diff changeset
365 ? "" : (char *)our_tv->vval.v_string);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
366 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
367 else if (our_tv->v_type == VAR_NUMBER)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
368 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
369 char buf[NUMBUFLEN];
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
370
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
371 /* For backwards compatibility numbers are stored as strings. */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
372 sprintf(buf, "%ld", (long)our_tv->vval.v_number);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
373 result = Py_BuildValue("s", buf);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
374 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
375 # ifdef FEAT_FLOAT
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
376 else if (our_tv->v_type == VAR_FLOAT)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
377 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
378 char buf[NUMBUFLEN];
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
379
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
380 sprintf(buf, "%f", our_tv->vval.v_float);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
381 result = Py_BuildValue("s", buf);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
382 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
383 # endif
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
384 else if (our_tv->v_type == VAR_LIST)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
385 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
386 list_T *list = our_tv->vval.v_list;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
387 listitem_T *curr;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
388
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
389 result = PyList_New(0);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
390
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
391 if (list != NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
392 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
393 PyDict_SetItemString(lookupDict, ptrBuf, result);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
394
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
395 for (curr = list->lv_first; curr != NULL; curr = curr->li_next)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
396 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
397 newObj = VimToPython(&curr->li_tv, depth + 1, lookupDict);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
398 PyList_Append(result, newObj);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
399 Py_DECREF(newObj);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
400 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
401 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
402 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
403 else if (our_tv->v_type == VAR_DICT)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
404 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
405 result = PyDict_New();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
406
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
407 if (our_tv->vval.v_dict != NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
408 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
409 hashtab_T *ht = &our_tv->vval.v_dict->dv_hashtab;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
410 long_u todo = ht->ht_used;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
411 hashitem_T *hi;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
412 dictitem_T *di;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
413
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
414 PyDict_SetItemString(lookupDict, ptrBuf, result);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
415
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
416 for (hi = ht->ht_array; todo > 0; ++hi)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
417 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
418 if (!HASHITEM_EMPTY(hi))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
419 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
420 --todo;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
421
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
422 di = dict_lookup(hi);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
423 newObj = VimToPython(&di->di_tv, depth + 1, lookupDict);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
424 PyDict_SetItemString(result, (char *)hi->hi_key, newObj);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
425 Py_DECREF(newObj);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
426 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
427 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
428 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
429 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
430 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
431 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
432 Py_INCREF(Py_None);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
433 result = Py_None;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
434 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
435
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
436 return result;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
437 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
438
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
439 static PyObject *
2520
6768ebd0bc04 Remove unused code.
Bram Moolenaar <bram@vim.org>
parents: 2447
diff changeset
440 VimEval(PyObject *self UNUSED, PyObject *args UNUSED)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
441 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
442 char *expr;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
443 typval_T *our_tv;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
444 PyObject *result;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
445 PyObject *lookup_dict;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
446
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
447 if (!PyArg_ParseTuple(args, "s", &expr))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
448 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
449
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
450 Py_BEGIN_ALLOW_THREADS
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
451 Python_Lock_Vim();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
452 our_tv = eval_expr((char_u *)expr, NULL);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
453
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
454 Python_Release_Vim();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
455 Py_END_ALLOW_THREADS
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
456
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
457 if (our_tv == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
458 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
459 PyErr_SetVim(_("invalid expression"));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
460 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
461 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
462
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
463 /* Convert the Vim type into a Python type. Create a dictionary that's
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
464 * used to check for recursive loops. */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
465 lookup_dict = PyDict_New();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
466 result = VimToPython(our_tv, 1, lookup_dict);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
467 Py_DECREF(lookup_dict);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
468
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
469
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
470 Py_BEGIN_ALLOW_THREADS
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
471 Python_Lock_Vim();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
472 free_tv(our_tv);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
473 Python_Release_Vim();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
474 Py_END_ALLOW_THREADS
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
475
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
476 return result;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
477 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
478
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
479 static PyObject *ConvertToPyObject(typval_T *);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
480
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
481 static PyObject *
4438
20e30e31bd86 updated for version 7.3.967
Bram Moolenaar <bram@vim.org>
parents: 4435
diff changeset
482 VimEvalPy(PyObject *self UNUSED, PyObject *args)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
483 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
484 char *expr;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
485 typval_T *our_tv;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
486 PyObject *result;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
487
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
488 if (!PyArg_ParseTuple(args, "s", &expr))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
489 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
490
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
491 Py_BEGIN_ALLOW_THREADS
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
492 Python_Lock_Vim();
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
493 our_tv = eval_expr((char_u *)expr, NULL);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
494
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
495 Python_Release_Vim();
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
496 Py_END_ALLOW_THREADS
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
497
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
498 if (our_tv == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
499 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
500 PyErr_SetVim(_("invalid expression"));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
501 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
502 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
503
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
504 result = ConvertToPyObject(our_tv);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
505 Py_BEGIN_ALLOW_THREADS
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
506 Python_Lock_Vim();
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
507 free_tv(our_tv);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
508 Python_Release_Vim();
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
509 Py_END_ALLOW_THREADS
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
510
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
511 return result;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
512 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
513
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
514 static PyObject *
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
515 VimStrwidth(PyObject *self UNUSED, PyObject *args)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
516 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
517 char *expr;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
518
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
519 if (!PyArg_ParseTuple(args, "s", &expr))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
520 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
521
3988
3e22fe67fa69 updated for version 7.3.749
Bram Moolenaar <bram@vim.org>
parents: 3852
diff changeset
522 return PyLong_FromLong(
3e22fe67fa69 updated for version 7.3.749
Bram Moolenaar <bram@vim.org>
parents: 3852
diff changeset
523 #ifdef FEAT_MBYTE
3e22fe67fa69 updated for version 7.3.749
Bram Moolenaar <bram@vim.org>
parents: 3852
diff changeset
524 mb_string2cells((char_u *)expr, (int)STRLEN(expr))
3e22fe67fa69 updated for version 7.3.749
Bram Moolenaar <bram@vim.org>
parents: 3852
diff changeset
525 #else
3e22fe67fa69 updated for version 7.3.749
Bram Moolenaar <bram@vim.org>
parents: 3852
diff changeset
526 STRLEN(expr)
3e22fe67fa69 updated for version 7.3.749
Bram Moolenaar <bram@vim.org>
parents: 3852
diff changeset
527 #endif
3e22fe67fa69 updated for version 7.3.749
Bram Moolenaar <bram@vim.org>
parents: 3852
diff changeset
528 );
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
529 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
530
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
531 /*
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
532 * Vim module - Definitions
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
533 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
534
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
535 static struct PyMethodDef VimMethods[] = {
4492
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
536 /* name, function, calling, documentation */
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
537 {"command", VimCommand, METH_VARARGS, "Execute a Vim ex-mode command" },
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
538 {"eval", VimEval, METH_VARARGS, "Evaluate an expression using Vim evaluator" },
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
539 {"bindeval", VimEvalPy, METH_VARARGS, "Like eval(), but returns objects attached to vim ones"},
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
540 {"strwidth", VimStrwidth, METH_VARARGS, "Screen string width, counts <Tab> as having width 1"},
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
541 { NULL, NULL, 0, NULL }
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
542 };
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
543
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
544 /*
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
545 * Generic iterator object
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
546 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
547
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
548 static PyTypeObject IterType;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
549
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
550 typedef PyObject *(*nextfun)(void **);
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
551 typedef void (*destructorfun)(void *);
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
552 typedef int (*traversefun)(void *, visitproc, void *);
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
553 typedef int (*clearfun)(void **);
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
554
4438
20e30e31bd86 updated for version 7.3.967
Bram Moolenaar <bram@vim.org>
parents: 4435
diff changeset
555 /* Main purpose of this object is removing the need for do python
20e30e31bd86 updated for version 7.3.967
Bram Moolenaar <bram@vim.org>
parents: 4435
diff changeset
556 * initialization (i.e. PyType_Ready and setting type attributes) for a big
20e30e31bd86 updated for version 7.3.967
Bram Moolenaar <bram@vim.org>
parents: 4435
diff changeset
557 * bunch of objects. */
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
558
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
559 typedef struct
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
560 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
561 PyObject_HEAD
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
562 void *cur;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
563 nextfun next;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
564 destructorfun destruct;
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
565 traversefun traverse;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
566 clearfun clear;
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
567 } IterObject;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
568
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
569 static PyObject *
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
570 IterNew(void *start, destructorfun destruct, nextfun next, traversefun traverse,
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
571 clearfun clear)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
572 {
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
573 IterObject *self;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
574
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
575 self = PyObject_NEW(IterObject, &IterType);
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
576 self->cur = start;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
577 self->next = next;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
578 self->destruct = destruct;
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
579 self->traverse = traverse;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
580 self->clear = clear;
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
581
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
582 return (PyObject *)(self);
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
583 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
584
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
585 static void
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
586 IterDestructor(IterObject *self)
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
587 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
588 self->destruct(self->cur);
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
589
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
590 DESTRUCTOR_FINISH(self);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
591 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
592
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
593 static int
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
594 IterTraverse(IterObject *self, visitproc visit, void *arg)
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
595 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
596 if (self->traverse != NULL)
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
597 return self->traverse(self->cur, visit, arg);
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
598 else
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
599 return 0;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
600 }
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
601
4438
20e30e31bd86 updated for version 7.3.967
Bram Moolenaar <bram@vim.org>
parents: 4435
diff changeset
602 /* Mac OSX defines clear() somewhere. */
20e30e31bd86 updated for version 7.3.967
Bram Moolenaar <bram@vim.org>
parents: 4435
diff changeset
603 #ifdef clear
20e30e31bd86 updated for version 7.3.967
Bram Moolenaar <bram@vim.org>
parents: 4435
diff changeset
604 # undef clear
20e30e31bd86 updated for version 7.3.967
Bram Moolenaar <bram@vim.org>
parents: 4435
diff changeset
605 #endif
20e30e31bd86 updated for version 7.3.967
Bram Moolenaar <bram@vim.org>
parents: 4435
diff changeset
606
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
607 static int
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
608 IterClear(IterObject *self)
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
609 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
610 if (self->clear != NULL)
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
611 return self->clear(&self->cur);
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
612 else
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
613 return 0;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
614 }
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
615
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
616 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
617 IterNext(IterObject *self)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
618 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
619 return self->next(&self->cur);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
620 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
621
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
622 static PyObject *
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
623 IterIter(PyObject *self)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
624 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
625 return self;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
626 }
4393
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
627
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
628 typedef struct pylinkedlist_S {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
629 struct pylinkedlist_S *pll_next;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
630 struct pylinkedlist_S *pll_prev;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
631 PyObject *pll_obj;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
632 } pylinkedlist_T;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
633
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
634 static pylinkedlist_T *lastdict = NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
635 static pylinkedlist_T *lastlist = NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
636
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
637 static void
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
638 pyll_remove(pylinkedlist_T *ref, pylinkedlist_T **last)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
639 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
640 if (ref->pll_prev == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
641 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
642 if (ref->pll_next == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
643 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
644 *last = NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
645 return;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
646 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
647 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
648 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
649 ref->pll_prev->pll_next = ref->pll_next;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
650
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
651 if (ref->pll_next == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
652 *last = ref->pll_prev;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
653 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
654 ref->pll_next->pll_prev = ref->pll_prev;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
655 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
656
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
657 static void
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
658 pyll_add(PyObject *self, pylinkedlist_T *ref, pylinkedlist_T **last)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
659 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
660 if (*last == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
661 ref->pll_prev = NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
662 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
663 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
664 (*last)->pll_next = ref;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
665 ref->pll_prev = *last;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
666 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
667 ref->pll_next = NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
668 ref->pll_obj = self;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
669 *last = ref;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
670 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
671
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
672 static PyTypeObject DictionaryType;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
673
3792
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
674 #define DICTKEY_GET_NOTEMPTY(err) \
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
675 DICTKEY_GET(err) \
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
676 if (*key == NUL) \
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
677 { \
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
678 PyErr_SetString(PyExc_ValueError, _("empty keys are not allowed")); \
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
679 return err; \
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
680 }
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
681
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
682 typedef struct
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
683 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
684 PyObject_HEAD
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
685 dict_T *dict;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
686 pylinkedlist_T ref;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
687 } DictionaryObject;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
688
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
689 static PyObject *
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
690 DictionaryNew(dict_T *dict)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
691 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
692 DictionaryObject *self;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
693
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
694 self = PyObject_NEW(DictionaryObject, &DictionaryType);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
695 if (self == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
696 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
697 self->dict = dict;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
698 ++dict->dv_refcount;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
699
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
700 pyll_add((PyObject *)(self), &self->ref, &lastdict);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
701
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
702 return (PyObject *)(self);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
703 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
704
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
705 static void
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
706 DictionaryDestructor(DictionaryObject *self)
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
707 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
708 pyll_remove(&self->ref, &lastdict);
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
709 dict_unref(self->dict);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
710
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
711 DESTRUCTOR_FINISH(self);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
712 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
713
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
714 static int
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
715 DictionarySetattr(DictionaryObject *self, char *name, PyObject *val)
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
716 {
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
717 if (val == NULL)
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
718 {
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
719 PyErr_SetString(PyExc_AttributeError, _("Cannot delete DictionaryObject attributes"));
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
720 return -1;
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
721 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
722
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
723 if (strcmp(name, "locked") == 0)
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
724 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
725 if (self->dict->dv_lock == VAR_FIXED)
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
726 {
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
727 PyErr_SetString(PyExc_TypeError, _("Cannot modify fixed dictionary"));
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
728 return -1;
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
729 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
730 else
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
731 {
4411
1afdb7d21c14 updated for version 7.3.954
Bram Moolenaar <bram@vim.org>
parents: 4407
diff changeset
732 int istrue = PyObject_IsTrue(val);
1afdb7d21c14 updated for version 7.3.954
Bram Moolenaar <bram@vim.org>
parents: 4407
diff changeset
733 if (istrue == -1)
1afdb7d21c14 updated for version 7.3.954
Bram Moolenaar <bram@vim.org>
parents: 4407
diff changeset
734 return -1;
1afdb7d21c14 updated for version 7.3.954
Bram Moolenaar <bram@vim.org>
parents: 4407
diff changeset
735 else if (istrue)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
736 self->dict->dv_lock = VAR_LOCKED;
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
737 else
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
738 self->dict->dv_lock = 0;
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
739 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
740 return 0;
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
741 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
742 else
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
743 {
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
744 PyErr_SetString(PyExc_AttributeError, _("Cannot set this attribute"));
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
745 return -1;
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
746 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
747 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
748
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
749 static PyInt
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
750 DictionaryLength(DictionaryObject *self)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
751 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
752 return ((PyInt) (self->dict->dv_hashtab.ht_used));
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
753 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
754
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
755 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
756 DictionaryItem(DictionaryObject *self, PyObject *keyObject)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
757 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
758 char_u *key;
3792
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
759 dictitem_T *di;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
760 DICTKEY_DECL
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
761
3792
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
762 DICTKEY_GET_NOTEMPTY(NULL)
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
763
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
764 di = dict_find(self->dict, key, -1);
3792
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
765
3824
2bf8c00741f7 updated for version 7.3.670
Bram Moolenaar <bram@vim.org>
parents: 3806
diff changeset
766 DICTKEY_UNREF
2bf8c00741f7 updated for version 7.3.670
Bram Moolenaar <bram@vim.org>
parents: 3806
diff changeset
767
3792
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
768 if (di == NULL)
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
769 {
4403
d4816e7c3328 updated for version 7.3.950
Bram Moolenaar <bram@vim.org>
parents: 4401
diff changeset
770 PyErr_SetObject(PyExc_KeyError, keyObject);
3792
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
771 return NULL;
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
772 }
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
773
3792
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
774 return ConvertToPyObject(&di->di_tv);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
775 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
776
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
777 static PyInt
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
778 DictionaryAssItem(DictionaryObject *self, PyObject *keyObject, PyObject *valObject)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
779 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
780 char_u *key;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
781 typval_T tv;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
782 dict_T *d = self->dict;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
783 dictitem_T *di;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
784 DICTKEY_DECL
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
785
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
786 if (d->dv_lock)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
787 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
788 PyErr_SetVim(_("dict is locked"));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
789 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
790 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
791
3792
73557eda7027 updated for version 7.3.654
Bram Moolenaar <bram@vim.org>
parents: 3788
diff changeset
792 DICTKEY_GET_NOTEMPTY(-1)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
793
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
794 di = dict_find(d, key, -1);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
795
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
796 if (valObject == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
797 {
3636
0e9b2622c94a updated for version 7.3.578
Bram Moolenaar <bram@vim.org>
parents: 3618
diff changeset
798 hashitem_T *hi;
0e9b2622c94a updated for version 7.3.578
Bram Moolenaar <bram@vim.org>
parents: 3618
diff changeset
799
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
800 if (di == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
801 {
3824
2bf8c00741f7 updated for version 7.3.670
Bram Moolenaar <bram@vim.org>
parents: 3806
diff changeset
802 DICTKEY_UNREF
4403
d4816e7c3328 updated for version 7.3.950
Bram Moolenaar <bram@vim.org>
parents: 4401
diff changeset
803 PyErr_SetObject(PyExc_KeyError, keyObject);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
804 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
805 }
3636
0e9b2622c94a updated for version 7.3.578
Bram Moolenaar <bram@vim.org>
parents: 3618
diff changeset
806 hi = hash_find(&d->dv_hashtab, di->di_key);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
807 hash_remove(&d->dv_hashtab, hi);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
808 dictitem_free(di);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
809 return 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
810 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
811
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
812 if (ConvertFromPyObject(valObject, &tv) == -1)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
813 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
814
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
815 if (di == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
816 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
817 di = dictitem_alloc(key);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
818 if (di == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
819 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
820 PyErr_NoMemory();
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
821 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
822 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
823 di->di_tv.v_lock = 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
824
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
825 if (dict_add(d, di) == FAIL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
826 {
3824
2bf8c00741f7 updated for version 7.3.670
Bram Moolenaar <bram@vim.org>
parents: 3806
diff changeset
827 DICTKEY_UNREF
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
828 vim_free(di);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
829 PyErr_SetVim(_("failed to add key to dictionary"));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
830 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
831 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
832 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
833 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
834 clear_tv(&di->di_tv);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
835
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
836 DICTKEY_UNREF
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
837
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
838 copy_tv(&tv, &di->di_tv);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
839 return 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
840 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
841
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
842 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
843 DictionaryListKeys(DictionaryObject *self)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
844 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
845 dict_T *dict = self->dict;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
846 long_u todo = dict->dv_hashtab.ht_used;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
847 Py_ssize_t i = 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
848 PyObject *r;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
849 hashitem_T *hi;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
850
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
851 r = PyList_New(todo);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
852 for (hi = dict->dv_hashtab.ht_array; todo > 0; ++hi)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
853 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
854 if (!HASHITEM_EMPTY(hi))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
855 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
856 PyList_SetItem(r, i, PyBytes_FromString((char *)(hi->hi_key)));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
857 --todo;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
858 ++i;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
859 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
860 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
861 return r;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
862 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
863
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
864 static PyMappingMethods DictionaryAsMapping = {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
865 (lenfunc) DictionaryLength,
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
866 (binaryfunc) DictionaryItem,
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
867 (objobjargproc) DictionaryAssItem,
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
868 };
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
869
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
870 static struct PyMethodDef DictionaryMethods[] = {
4492
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
871 {"keys", (PyCFunction)DictionaryListKeys, METH_NOARGS, ""},
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
872 { NULL, NULL, 0, NULL }
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
873 };
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
874
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
875 static PyTypeObject ListType;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
876 static PySequenceMethods ListAsSeq;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
877 static PyMappingMethods ListAsMapping;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
878
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
879 typedef struct
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
880 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
881 PyObject_HEAD
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
882 list_T *list;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
883 pylinkedlist_T ref;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
884 } ListObject;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
885
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
886 static PyObject *
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
887 ListNew(list_T *list)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
888 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
889 ListObject *self;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
890
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
891 self = PyObject_NEW(ListObject, &ListType);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
892 if (self == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
893 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
894 self->list = list;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
895 ++list->lv_refcount;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
896
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
897 pyll_add((PyObject *)(self), &self->ref, &lastlist);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
898
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
899 return (PyObject *)(self);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
900 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
901
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
902 static void
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
903 ListDestructor(ListObject *self)
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
904 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
905 pyll_remove(&self->ref, &lastlist);
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
906 list_unref(self->list);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
907
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
908 DESTRUCTOR_FINISH(self);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
909 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
910
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
911 static int
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
912 list_py_concat(list_T *l, PyObject *obj, PyObject *lookupDict)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
913 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
914 Py_ssize_t i;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
915 Py_ssize_t lsize = PySequence_Size(obj);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
916 PyObject *litem;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
917 listitem_T *li;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
918
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
919 for(i=0; i<lsize; i++)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
920 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
921 li = listitem_alloc();
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
922 if (li == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
923 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
924 PyErr_NoMemory();
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
925 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
926 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
927 li->li_tv.v_lock = 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
928
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
929 litem = PySequence_GetItem(obj, i);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
930 if (litem == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
931 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
932 if (_ConvertFromPyObject(litem, &li->li_tv, lookupDict) == -1)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
933 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
934
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
935 list_append(l, li);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
936 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
937 return 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
938 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
939
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
940 static PyInt
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
941 ListLength(ListObject *self)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
942 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
943 return ((PyInt) (self->list->lv_len));
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
944 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
945
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
946 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
947 ListItem(ListObject *self, Py_ssize_t index)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
948 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
949 listitem_T *li;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
950
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
951 if (index >= ListLength(self))
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
952 {
4405
907b1f035ee7 updated for version 7.3.951
Bram Moolenaar <bram@vim.org>
parents: 4403
diff changeset
953 PyErr_SetString(PyExc_IndexError, _("list index out of range"));
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
954 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
955 }
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
956 li = list_find(self->list, (long) index);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
957 if (li == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
958 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
959 PyErr_SetVim(_("internal error: failed to get vim list item"));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
960 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
961 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
962 return ConvertToPyObject(&li->li_tv);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
963 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
964
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
965 #define PROC_RANGE \
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
966 if (last < 0) {\
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
967 if (last < -size) \
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
968 last = 0; \
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
969 else \
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
970 last += size; \
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
971 } \
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
972 if (first < 0) \
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
973 first = 0; \
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
974 if (first > size) \
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
975 first = size; \
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
976 if (last > size) \
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
977 last = size;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
978
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
979 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
980 ListSlice(ListObject *self, Py_ssize_t first, Py_ssize_t last)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
981 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
982 PyInt i;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
983 PyInt size = ListLength(self);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
984 PyInt n;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
985 PyObject *list;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
986 int reversed = 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
987
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
988 PROC_RANGE
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
989 if (first >= last)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
990 first = last;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
991
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
992 n = last-first;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
993 list = PyList_New(n);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
994 if (list == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
995 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
996
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
997 for (i = 0; i < n; ++i)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
998 {
4260
d8acfc49d94e updated for version 7.3.881
Bram Moolenaar <bram@vim.org>
parents: 4133
diff changeset
999 PyObject *item = ListItem(self, first + i);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1000 if (item == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1001 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1002 Py_DECREF(list);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1003 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1004 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1005
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1006 if ((PyList_SetItem(list, ((reversed)?(n-i-1):(i)), item)))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1007 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1008 Py_DECREF(item);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1009 Py_DECREF(list);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1010 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1011 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1012 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1013
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1014 return list;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1015 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1016
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1017 typedef struct
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1018 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1019 listwatch_T lw;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1020 list_T *list;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1021 } listiterinfo_T;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1022
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1023 static void
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1024 ListIterDestruct(listiterinfo_T *lii)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1025 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1026 list_rem_watch(lii->list, &lii->lw);
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1027 PyMem_Free(lii);
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1028 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1029
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1030 static PyObject *
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1031 ListIterNext(listiterinfo_T **lii)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1032 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1033 PyObject *r;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1034
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1035 if (!((*lii)->lw.lw_item))
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1036 return NULL;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1037
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1038 if (!(r = ConvertToPyObject(&((*lii)->lw.lw_item->li_tv))))
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1039 return NULL;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1040
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1041 (*lii)->lw.lw_item = (*lii)->lw.lw_item->li_next;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1042
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1043 return r;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1044 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1045
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1046 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1047 ListIter(ListObject *self)
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1048 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1049 listiterinfo_T *lii;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1050 list_T *l = self->list;
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1051
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1052 if (!(lii = PyMem_New(listiterinfo_T, 1)))
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1053 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1054 PyErr_NoMemory();
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1055 return NULL;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1056 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1057
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1058 list_add_watch(l, &lii->lw);
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1059 lii->lw.lw_item = l->lv_first;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1060 lii->list = l;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1061
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1062 return IterNew(lii,
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1063 (destructorfun) ListIterDestruct, (nextfun) ListIterNext,
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1064 NULL, NULL);
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1065 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
1066
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1067 static int
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1068 ListAssItem(ListObject *self, Py_ssize_t index, PyObject *obj)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1069 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1070 typval_T tv;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1071 list_T *l = self->list;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1072 listitem_T *li;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1073 Py_ssize_t length = ListLength(self);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1074
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1075 if (l->lv_lock)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1076 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1077 PyErr_SetVim(_("list is locked"));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1078 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1079 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1080 if (index>length || (index==length && obj==NULL))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1081 {
4405
907b1f035ee7 updated for version 7.3.951
Bram Moolenaar <bram@vim.org>
parents: 4403
diff changeset
1082 PyErr_SetString(PyExc_IndexError, _("list index out of range"));
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1083 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1084 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1085
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1086 if (obj == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1087 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1088 li = list_find(l, (long) index);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1089 list_remove(l, li, li);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1090 clear_tv(&li->li_tv);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1091 vim_free(li);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1092 return 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1093 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1094
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1095 if (ConvertFromPyObject(obj, &tv) == -1)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1096 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1097
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1098 if (index == length)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1099 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1100 if (list_append_tv(l, &tv) == FAIL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1101 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1102 PyErr_SetVim(_("Failed to add item to list"));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1103 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1104 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1105 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1106 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1107 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1108 li = list_find(l, (long) index);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1109 clear_tv(&li->li_tv);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1110 copy_tv(&tv, &li->li_tv);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1111 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1112 return 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1113 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1114
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1115 static int
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1116 ListAssSlice(ListObject *self, Py_ssize_t first, Py_ssize_t last, PyObject *obj)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1117 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1118 PyInt size = ListLength(self);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1119 Py_ssize_t i;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1120 Py_ssize_t lsize;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1121 PyObject *litem;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1122 listitem_T *li;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1123 listitem_T *next;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1124 typval_T v;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1125 list_T *l = self->list;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1126
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1127 if (l->lv_lock)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1128 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1129 PyErr_SetVim(_("list is locked"));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1130 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1131 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1132
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1133 PROC_RANGE
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1134
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1135 if (first == size)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1136 li = NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1137 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1138 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1139 li = list_find(l, (long) first);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1140 if (li == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1141 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1142 PyErr_SetVim(_("internal error: no vim list item"));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1143 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1144 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1145 if (last > first)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1146 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1147 i = last - first;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1148 while (i-- && li != NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1149 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1150 next = li->li_next;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1151 listitem_remove(l, li);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1152 li = next;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1153 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1154 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1155 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1156
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1157 if (obj == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1158 return 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1159
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1160 if (!PyList_Check(obj))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1161 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1162 PyErr_SetString(PyExc_TypeError, _("can only assign lists to slice"));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1163 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1164 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1165
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1166 lsize = PyList_Size(obj);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1167
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1168 for(i=0; i<lsize; i++)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1169 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1170 litem = PyList_GetItem(obj, i);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1171 if (litem == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1172 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1173 if (ConvertFromPyObject(litem, &v) == -1)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1174 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1175 if (list_insert_tv(l, &v, li) == FAIL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1176 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1177 PyErr_SetVim(_("internal error: failed to add item to list"));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1178 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1179 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1180 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1181 return 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1182 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1183
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1184 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1185 ListConcatInPlace(ListObject *self, PyObject *obj)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1186 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1187 list_T *l = self->list;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1188 PyObject *lookup_dict;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1189
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1190 if (l->lv_lock)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1191 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1192 PyErr_SetVim(_("list is locked"));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1193 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1194 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1195
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1196 if (!PySequence_Check(obj))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1197 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1198 PyErr_SetString(PyExc_TypeError, _("can only concatenate with lists"));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1199 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1200 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1201
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1202 lookup_dict = PyDict_New();
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1203 if (list_py_concat(l, obj, lookup_dict) == -1)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1204 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1205 Py_DECREF(lookup_dict);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1206 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1207 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1208 Py_DECREF(lookup_dict);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1209
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1210 Py_INCREF(self);
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1211 return (PyObject *)(self);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1212 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1213
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1214 static int
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1215 ListSetattr(ListObject *self, char *name, PyObject *val)
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1216 {
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1217 if (val == NULL)
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1218 {
4405
907b1f035ee7 updated for version 7.3.951
Bram Moolenaar <bram@vim.org>
parents: 4403
diff changeset
1219 PyErr_SetString(PyExc_AttributeError,
907b1f035ee7 updated for version 7.3.951
Bram Moolenaar <bram@vim.org>
parents: 4403
diff changeset
1220 _("cannot delete vim.dictionary attributes"));
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1221 return -1;
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1222 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1223
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1224 if (strcmp(name, "locked") == 0)
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1225 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1226 if (self->list->lv_lock == VAR_FIXED)
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1227 {
4405
907b1f035ee7 updated for version 7.3.951
Bram Moolenaar <bram@vim.org>
parents: 4403
diff changeset
1228 PyErr_SetString(PyExc_TypeError, _("cannot modify fixed list"));
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1229 return -1;
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1230 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1231 else
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1232 {
4411
1afdb7d21c14 updated for version 7.3.954
Bram Moolenaar <bram@vim.org>
parents: 4407
diff changeset
1233 int istrue = PyObject_IsTrue(val);
1afdb7d21c14 updated for version 7.3.954
Bram Moolenaar <bram@vim.org>
parents: 4407
diff changeset
1234 if (istrue == -1)
1afdb7d21c14 updated for version 7.3.954
Bram Moolenaar <bram@vim.org>
parents: 4407
diff changeset
1235 return -1;
1afdb7d21c14 updated for version 7.3.954
Bram Moolenaar <bram@vim.org>
parents: 4407
diff changeset
1236 else if (istrue)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1237 self->list->lv_lock = VAR_LOCKED;
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1238 else
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1239 self->list->lv_lock = 0;
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1240 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1241 return 0;
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1242 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1243 else
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1244 {
4405
907b1f035ee7 updated for version 7.3.951
Bram Moolenaar <bram@vim.org>
parents: 4403
diff changeset
1245 PyErr_SetString(PyExc_AttributeError, _("cannot set this attribute"));
3828
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1246 return -1;
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1247 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1248 }
fd6ef931aa77 updated for version 7.3.672
Bram Moolenaar <bram@vim.org>
parents: 3826
diff changeset
1249
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1250 static struct PyMethodDef ListMethods[] = {
4492
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
1251 {"extend", (PyCFunction)ListConcatInPlace, METH_O, ""},
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
1252 { NULL, NULL, 0, NULL }
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1253 };
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1254
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1255 typedef struct
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1256 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1257 PyObject_HEAD
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1258 char_u *name;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1259 } FunctionObject;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1260
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1261 static PyTypeObject FunctionType;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1262
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1263 static PyObject *
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1264 FunctionNew(char_u *name)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1265 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1266 FunctionObject *self;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1267
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1268 self = PyObject_NEW(FunctionObject, &FunctionType);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1269 if (self == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1270 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1271 self->name = PyMem_New(char_u, STRLEN(name) + 1);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1272 if (self->name == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1273 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1274 PyErr_NoMemory();
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1275 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1276 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1277 STRCPY(self->name, name);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1278 func_ref(name);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1279 return (PyObject *)(self);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1280 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1281
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1282 static void
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1283 FunctionDestructor(FunctionObject *self)
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1284 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1285 func_unref(self->name);
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1286 PyMem_Free(self->name);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1287
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1288 DESTRUCTOR_FINISH(self);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1289 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1290
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1291 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1292 FunctionCall(FunctionObject *self, PyObject *argsObject, PyObject *kwargs)
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1293 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1294 char_u *name = self->name;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1295 typval_T args;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1296 typval_T selfdicttv;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1297 typval_T rettv;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1298 dict_T *selfdict = NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1299 PyObject *selfdictObject;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1300 PyObject *result;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1301 int error;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1302
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1303 if (ConvertFromPyObject(argsObject, &args) == -1)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1304 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1305
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1306 if (kwargs != NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1307 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1308 selfdictObject = PyDict_GetItemString(kwargs, "self");
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1309 if (selfdictObject != NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1310 {
3703
e13f2f3568e1 updated for version 7.3.611
Bram Moolenaar <bram@vim.org>
parents: 3648
diff changeset
1311 if (!PyMapping_Check(selfdictObject))
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1312 {
3703
e13f2f3568e1 updated for version 7.3.611
Bram Moolenaar <bram@vim.org>
parents: 3648
diff changeset
1313 PyErr_SetString(PyExc_TypeError,
e13f2f3568e1 updated for version 7.3.611
Bram Moolenaar <bram@vim.org>
parents: 3648
diff changeset
1314 _("'self' argument must be a dictionary"));
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1315 clear_tv(&args);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1316 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1317 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1318 if (ConvertFromPyObject(selfdictObject, &selfdicttv) == -1)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1319 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1320 selfdict = selfdicttv.vval.v_dict;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1321 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1322 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1323
4415
0bbacb6a83bd updated for version 7.3.956
Bram Moolenaar <bram@vim.org>
parents: 4411
diff changeset
1324 Py_BEGIN_ALLOW_THREADS
0bbacb6a83bd updated for version 7.3.956
Bram Moolenaar <bram@vim.org>
parents: 4411
diff changeset
1325 Python_Lock_Vim();
0bbacb6a83bd updated for version 7.3.956
Bram Moolenaar <bram@vim.org>
parents: 4411
diff changeset
1326
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1327 error = func_call(name, &args, selfdict, &rettv);
4415
0bbacb6a83bd updated for version 7.3.956
Bram Moolenaar <bram@vim.org>
parents: 4411
diff changeset
1328
0bbacb6a83bd updated for version 7.3.956
Bram Moolenaar <bram@vim.org>
parents: 4411
diff changeset
1329 Python_Release_Vim();
0bbacb6a83bd updated for version 7.3.956
Bram Moolenaar <bram@vim.org>
parents: 4411
diff changeset
1330 Py_END_ALLOW_THREADS
0bbacb6a83bd updated for version 7.3.956
Bram Moolenaar <bram@vim.org>
parents: 4411
diff changeset
1331
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1332 if (error != OK)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1333 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1334 result = NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1335 PyErr_SetVim(_("failed to run function"));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1336 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1337 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1338 result = ConvertToPyObject(&rettv);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1339
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1340 /* FIXME Check what should really be cleared. */
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1341 clear_tv(&args);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1342 clear_tv(&rettv);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1343 /*
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1344 * if (selfdict!=NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1345 * clear_tv(selfdicttv);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1346 */
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1347
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1348 return result;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1349 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1350
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1351 static struct PyMethodDef FunctionMethods[] = {
4492
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
1352 {"__call__", (PyCFunction)FunctionCall, METH_VARARGS|METH_KEYWORDS, ""},
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
1353 { NULL, NULL, 0, NULL}
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1354 };
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
1355
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1356 /*
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1357 * Options object
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1358 */
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1359
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1360 static PyTypeObject OptionsType;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1361
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1362 typedef int (*checkfun)(void *);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1363
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1364 typedef struct
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1365 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1366 PyObject_HEAD
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1367 int opt_type;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1368 void *from;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1369 checkfun Check;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1370 PyObject *fromObj;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1371 } OptionsObject;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1372
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1373 static int
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1374 dummy_check(void *arg UNUSED)
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1375 {
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1376 return 0;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1377 }
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1378
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1379 static PyObject *
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1380 OptionsNew(int opt_type, void *from, checkfun Check, PyObject *fromObj)
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1381 {
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1382 OptionsObject *self;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1383
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1384 self = PyObject_NEW(OptionsObject, &OptionsType);
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1385 if (self == NULL)
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1386 return NULL;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1387
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1388 self->opt_type = opt_type;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1389 self->from = from;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1390 self->Check = Check;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1391 self->fromObj = fromObj;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1392 if (fromObj)
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1393 Py_INCREF(fromObj);
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1394
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1395 return (PyObject *)(self);
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1396 }
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1397
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1398 static void
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1399 OptionsDestructor(OptionsObject *self)
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1400 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1401 if (self->fromObj)
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1402 Py_DECREF(self->fromObj);
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1403 DESTRUCTOR_FINISH(self);
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1404 }
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1405
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1406 static int
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1407 OptionsTraverse(OptionsObject *self, visitproc visit, void *arg)
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1408 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1409 Py_VISIT(self->fromObj);
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1410 return 0;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1411 }
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1412
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1413 static int
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1414 OptionsClear(OptionsObject *self)
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1415 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1416 Py_CLEAR(self->fromObj);
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1417 return 0;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1418 }
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1419
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1420 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1421 OptionsItem(OptionsObject *self, PyObject *keyObject)
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1422 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1423 char_u *key;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1424 int flags;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1425 long numval;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1426 char_u *stringval;
4359
6d45e6f97415 updated for version 7.3.928
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
1427 DICTKEY_DECL
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1428
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1429 if (self->Check(self->from))
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1430 return NULL;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1431
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1432 DICTKEY_GET_NOTEMPTY(NULL)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1433
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1434 flags = get_option_value_strict(key, &numval, &stringval,
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1435 self->opt_type, self->from);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1436
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1437 DICTKEY_UNREF
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1438
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1439 if (flags == 0)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1440 {
4403
d4816e7c3328 updated for version 7.3.950
Bram Moolenaar <bram@vim.org>
parents: 4401
diff changeset
1441 PyErr_SetObject(PyExc_KeyError, keyObject);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1442 return NULL;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1443 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1444
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1445 if (flags & SOPT_UNSET)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1446 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1447 Py_INCREF(Py_None);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1448 return Py_None;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1449 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1450 else if (flags & SOPT_BOOL)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1451 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1452 PyObject *r;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1453 r = numval ? Py_True : Py_False;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1454 Py_INCREF(r);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1455 return r;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1456 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1457 else if (flags & SOPT_NUM)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1458 return PyInt_FromLong(numval);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1459 else if (flags & SOPT_STRING)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1460 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1461 if (stringval)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1462 return PyBytes_FromString((char *) stringval);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1463 else
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1464 {
4405
907b1f035ee7 updated for version 7.3.951
Bram Moolenaar <bram@vim.org>
parents: 4403
diff changeset
1465 PyErr_SetString(PyExc_RuntimeError,
907b1f035ee7 updated for version 7.3.951
Bram Moolenaar <bram@vim.org>
parents: 4403
diff changeset
1466 _("unable to get option value"));
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1467 return NULL;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1468 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1469 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1470 else
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1471 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1472 PyErr_SetVim("Internal error: unknown option type. Should not happen");
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1473 return NULL;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1474 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1475 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1476
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1477 static int
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1478 set_option_value_for(key, numval, stringval, opt_flags, opt_type, from)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1479 char_u *key;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1480 int numval;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1481 char_u *stringval;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1482 int opt_flags;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1483 int opt_type;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1484 void *from;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1485 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1486 win_T *save_curwin;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1487 tabpage_T *save_curtab;
4429
7eafa576528e updated for version 7.3.963
Bram Moolenaar <bram@vim.org>
parents: 4419
diff changeset
1488 buf_T *save_curbuf;
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1489 int r = 0;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1490
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1491 switch (opt_type)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1492 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1493 case SREQ_WIN:
4429
7eafa576528e updated for version 7.3.963
Bram Moolenaar <bram@vim.org>
parents: 4419
diff changeset
1494 if (switch_win(&save_curwin, &save_curtab, (win_T *)from,
7eafa576528e updated for version 7.3.963
Bram Moolenaar <bram@vim.org>
parents: 4419
diff changeset
1495 win_find_tabpage((win_T *)from)) == FAIL)
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1496 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1497 PyErr_SetVim("Problem while switching windows.");
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1498 return -1;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1499 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1500 set_option_value(key, numval, stringval, opt_flags);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1501 restore_win(save_curwin, save_curtab);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1502 break;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1503 case SREQ_BUF:
4429
7eafa576528e updated for version 7.3.963
Bram Moolenaar <bram@vim.org>
parents: 4419
diff changeset
1504 switch_buffer(&save_curbuf, (buf_T *)from);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1505 set_option_value(key, numval, stringval, opt_flags);
4429
7eafa576528e updated for version 7.3.963
Bram Moolenaar <bram@vim.org>
parents: 4419
diff changeset
1506 restore_buffer(save_curbuf);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1507 break;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1508 case SREQ_GLOBAL:
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1509 set_option_value(key, numval, stringval, opt_flags);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1510 break;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1511 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1512 return r;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1513 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1514
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1515 static int
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1516 OptionsAssItem(OptionsObject *self, PyObject *keyObject, PyObject *valObject)
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1517 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1518 char_u *key;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1519 int flags;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1520 int opt_flags;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1521 int r = 0;
4359
6d45e6f97415 updated for version 7.3.928
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
1522 DICTKEY_DECL
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1523
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1524 if (self->Check(self->from))
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1525 return -1;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1526
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1527 DICTKEY_GET_NOTEMPTY(-1)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1528
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1529 flags = get_option_value_strict(key, NULL, NULL,
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1530 self->opt_type, self->from);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1531
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1532 DICTKEY_UNREF
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1533
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1534 if (flags == 0)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1535 {
4403
d4816e7c3328 updated for version 7.3.950
Bram Moolenaar <bram@vim.org>
parents: 4401
diff changeset
1536 PyErr_SetObject(PyExc_KeyError, keyObject);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1537 return -1;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1538 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1539
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1540 if (valObject == NULL)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1541 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1542 if (self->opt_type == SREQ_GLOBAL)
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1543 {
4405
907b1f035ee7 updated for version 7.3.951
Bram Moolenaar <bram@vim.org>
parents: 4403
diff changeset
1544 PyErr_SetString(PyExc_ValueError,
907b1f035ee7 updated for version 7.3.951
Bram Moolenaar <bram@vim.org>
parents: 4403
diff changeset
1545 _("unable to unset global option"));
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1546 return -1;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1547 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1548 else if (!(flags & SOPT_GLOBAL))
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1549 {
4405
907b1f035ee7 updated for version 7.3.951
Bram Moolenaar <bram@vim.org>
parents: 4403
diff changeset
1550 PyErr_SetString(PyExc_ValueError, _("unable to unset option "
907b1f035ee7 updated for version 7.3.951
Bram Moolenaar <bram@vim.org>
parents: 4403
diff changeset
1551 "without global value"));
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1552 return -1;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1553 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1554 else
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1555 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1556 unset_global_local_option(key, self->from);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1557 return 0;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1558 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1559 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1560
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1561 opt_flags = (self->opt_type ? OPT_LOCAL : OPT_GLOBAL);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1562
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1563 if (flags & SOPT_BOOL)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1564 {
4411
1afdb7d21c14 updated for version 7.3.954
Bram Moolenaar <bram@vim.org>
parents: 4407
diff changeset
1565 int istrue = PyObject_IsTrue(valObject);
1afdb7d21c14 updated for version 7.3.954
Bram Moolenaar <bram@vim.org>
parents: 4407
diff changeset
1566 if (istrue == -1)
1afdb7d21c14 updated for version 7.3.954
Bram Moolenaar <bram@vim.org>
parents: 4407
diff changeset
1567 return -1;
1afdb7d21c14 updated for version 7.3.954
Bram Moolenaar <bram@vim.org>
parents: 4407
diff changeset
1568 r = set_option_value_for(key, istrue, NULL,
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1569 opt_flags, self->opt_type, self->from);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1570 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1571 else if (flags & SOPT_NUM)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1572 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1573 int val;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1574
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1575 #if PY_MAJOR_VERSION < 3
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1576 if (PyInt_Check(valObject))
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1577 val = PyInt_AsLong(valObject);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1578 else
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1579 #endif
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1580 if (PyLong_Check(valObject))
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1581 val = PyLong_AsLong(valObject);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1582 else
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1583 {
4405
907b1f035ee7 updated for version 7.3.951
Bram Moolenaar <bram@vim.org>
parents: 4403
diff changeset
1584 PyErr_SetString(PyExc_TypeError, _("object must be integer"));
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1585 return -1;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1586 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1587
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1588 r = set_option_value_for(key, val, NULL, opt_flags,
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1589 self->opt_type, self->from);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1590 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1591 else
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1592 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1593 char_u *val;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1594 if (PyBytes_Check(valObject))
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1595 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1596
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1597 if (PyString_AsStringAndSize(valObject, (char **) &val, NULL) == -1)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1598 return -1;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1599 if (val == NULL)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1600 return -1;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1601
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1602 val = vim_strsave(val);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1603 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1604 else if (PyUnicode_Check(valObject))
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1605 {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1606 PyObject *bytes;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1607
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1608 bytes = PyUnicode_AsEncodedString(valObject, (char *)ENC_OPT, NULL);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1609 if (bytes == NULL)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1610 return -1;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1611
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1612 if(PyString_AsStringAndSize(bytes, (char **) &val, NULL) == -1)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1613 return -1;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1614 if (val == NULL)
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1615 return -1;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1616
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1617 val = vim_strsave(val);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1618 Py_XDECREF(bytes);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1619 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1620 else
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1621 {
4405
907b1f035ee7 updated for version 7.3.951
Bram Moolenaar <bram@vim.org>
parents: 4403
diff changeset
1622 PyErr_SetString(PyExc_TypeError, _("object must be string"));
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1623 return -1;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1624 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1625
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1626 r = set_option_value_for(key, 0, val, opt_flags,
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1627 self->opt_type, self->from);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1628 vim_free(val);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1629 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1630
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1631 return r;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1632 }
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1633
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1634 static PyMappingMethods OptionsAsMapping = {
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1635 (lenfunc) NULL,
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1636 (binaryfunc) OptionsItem,
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1637 (objobjargproc) OptionsAssItem,
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1638 };
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1639
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1640 /* Tabpage object
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1641 */
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1642
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1643 typedef struct
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1644 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1645 PyObject_HEAD
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1646 tabpage_T *tab;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1647 } TabPageObject;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1648
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1649 static PyObject *WinListNew(TabPageObject *tabObject);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1650
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1651 static PyTypeObject TabPageType;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1652
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1653 static int
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1654 CheckTabPage(TabPageObject *self)
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1655 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1656 if (self->tab == INVALID_TABPAGE_VALUE)
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1657 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1658 PyErr_SetVim(_("attempt to refer to deleted tab page"));
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1659 return -1;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1660 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1661
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1662 return 0;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1663 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1664
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1665 static PyObject *
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1666 TabPageNew(tabpage_T *tab)
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1667 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1668 TabPageObject *self;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1669
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1670 if (TAB_PYTHON_REF(tab))
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1671 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1672 self = TAB_PYTHON_REF(tab);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1673 Py_INCREF(self);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1674 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1675 else
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1676 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1677 self = PyObject_NEW(TabPageObject, &TabPageType);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1678 if (self == NULL)
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1679 return NULL;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1680 self->tab = tab;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1681 TAB_PYTHON_REF(tab) = self;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1682 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1683
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1684 return (PyObject *)(self);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1685 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1686
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1687 static void
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1688 TabPageDestructor(TabPageObject *self)
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1689 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1690 if (self->tab && self->tab != INVALID_TABPAGE_VALUE)
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1691 TAB_PYTHON_REF(self->tab) = NULL;
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1692
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1693 DESTRUCTOR_FINISH(self);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1694 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1695
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1696 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1697 TabPageAttr(TabPageObject *self, char *name)
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1698 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1699 if (strcmp(name, "windows") == 0)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1700 return WinListNew(self);
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1701 else if (strcmp(name, "number") == 0)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1702 return PyLong_FromLong((long) get_tab_number(self->tab));
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1703 else if (strcmp(name, "vars") == 0)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1704 return DictionaryNew(self->tab->tp_vars);
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1705 else if (strcmp(name, "window") == 0)
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1706 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1707 /* For current tab window.c does not bother to set or update tp_curwin
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1708 */
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1709 if (self->tab == curtab)
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
1710 return WindowNew(curwin, curtab);
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1711 else
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1712 return WindowNew(self->tab->tp_curwin, self->tab);
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1713 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1714 return NULL;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1715 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1716
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1717 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1718 TabPageRepr(TabPageObject *self)
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1719 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1720 static char repr[100];
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1721
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1722 if (self->tab == INVALID_TABPAGE_VALUE)
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1723 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1724 vim_snprintf(repr, 100, _("<tabpage object (deleted) at %p>"), (self));
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1725 return PyString_FromString(repr);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1726 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1727 else
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1728 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1729 int t = get_tab_number(self->tab);
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1730
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1731 if (t == 0)
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1732 vim_snprintf(repr, 100, _("<tabpage object (unknown) at %p>"),
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1733 (self));
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1734 else
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1735 vim_snprintf(repr, 100, _("<tabpage %d>"), t - 1);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1736
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1737 return PyString_FromString(repr);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1738 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1739 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1740
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1741 static struct PyMethodDef TabPageMethods[] = {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1742 /* name, function, calling, documentation */
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1743 { NULL, NULL, 0, NULL }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1744 };
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1745
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1746 /*
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1747 * Window list object
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1748 */
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1749
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1750 static PyTypeObject TabListType;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1751 static PySequenceMethods TabListAsSeq;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1752
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1753 typedef struct
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1754 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1755 PyObject_HEAD
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1756 } TabListObject;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1757
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1758 static PyInt
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1759 TabListLength(PyObject *self UNUSED)
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1760 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1761 tabpage_T *tp = first_tabpage;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1762 PyInt n = 0;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1763
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1764 while (tp != NULL)
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1765 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1766 ++n;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1767 tp = tp->tp_next;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1768 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1769
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1770 return n;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1771 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1772
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1773 static PyObject *
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1774 TabListItem(PyObject *self UNUSED, PyInt n)
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1775 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1776 tabpage_T *tp;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1777
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1778 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next, --n)
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1779 if (n == 0)
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1780 return TabPageNew(tp);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1781
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1782 PyErr_SetString(PyExc_IndexError, _("no such tab page"));
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1783 return NULL;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1784 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
1785
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1786 /* Window object
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1787 */
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1788
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1789 typedef struct
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1790 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1791 PyObject_HEAD
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1792 win_T *win;
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
1793 TabPageObject *tabObject;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1794 } WindowObject;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1795
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1796 static PyTypeObject WindowType;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1797
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1798 static int
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1799 CheckWindow(WindowObject *self)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1800 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1801 if (self->win == INVALID_WINDOW_VALUE)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1802 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1803 PyErr_SetVim(_("attempt to refer to deleted window"));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1804 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1805 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1806
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1807 return 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1808 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1809
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1810 static PyObject *
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
1811 WindowNew(win_T *win, tabpage_T *tab)
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1812 {
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1813 /* We need to handle deletion of windows underneath us.
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1814 * If we add a "w_python*_ref" field to the win_T structure,
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1815 * then we can get at it in win_free() in vim. We then
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1816 * need to create only ONE Python object per window - if
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1817 * we try to create a second, just INCREF the existing one
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1818 * and return it. The (single) Python object referring to
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1819 * the window is stored in "w_python*_ref".
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1820 * On a win_free() we set the Python object's win_T* field
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1821 * to an invalid value. We trap all uses of a window
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1822 * object, and reject them if the win_T* field is invalid.
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1823 *
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1824 * Python2 and Python3 get different fields and different objects:
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1825 * w_python_ref and w_python3_ref fields respectively.
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1826 */
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1827
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1828 WindowObject *self;
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1829
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1830 if (WIN_PYTHON_REF(win))
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1831 {
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1832 self = WIN_PYTHON_REF(win);
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1833 Py_INCREF(self);
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1834 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1835 else
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1836 {
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1837 self = PyObject_NEW(WindowObject, &WindowType);
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1838 if (self == NULL)
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1839 return NULL;
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1840 self->win = win;
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1841 WIN_PYTHON_REF(win) = self;
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1842 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1843
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
1844 self->tabObject = ((TabPageObject *)(TabPageNew(tab)));
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
1845
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1846 return (PyObject *)(self);
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1847 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1848
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1849 static void
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1850 WindowDestructor(WindowObject *self)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1851 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1852 if (self->win && self->win != INVALID_WINDOW_VALUE)
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1853 WIN_PYTHON_REF(self->win) = NULL;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1854
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1855 Py_DECREF(((PyObject *)(self->tabObject)));
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
1856
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1857 DESTRUCTOR_FINISH(self);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1858 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
1859
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
1860 static win_T *
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
1861 get_firstwin(TabPageObject *tabObject)
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
1862 {
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
1863 if (tabObject)
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
1864 {
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
1865 if (CheckTabPage(tabObject))
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
1866 return NULL;
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
1867 /* For current tab window.c does not bother to set or update tp_firstwin
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
1868 */
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
1869 else if (tabObject->tab == curtab)
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
1870 return firstwin;
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
1871 else
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
1872 return tabObject->tab->tp_firstwin;
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
1873 }
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
1874 else
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
1875 return firstwin;
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
1876 }
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1877 static int
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1878 WindowTraverse(WindowObject *self, visitproc visit, void *arg)
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1879 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1880 Py_VISIT(((PyObject *)(self->tabObject)));
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1881 return 0;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1882 }
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1883
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1884 static int
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1885 WindowClear(WindowObject *self)
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1886 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1887 Py_CLEAR(self->tabObject);
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1888 return 0;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
1889 }
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
1890
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
1891 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1892 WindowAttr(WindowObject *self, char *name)
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1893 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1894 if (strcmp(name, "buffer") == 0)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1895 return (PyObject *)BufferNew(self->win->w_buffer);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1896 else if (strcmp(name, "cursor") == 0)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1897 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1898 pos_T *pos = &self->win->w_cursor;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1899
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1900 return Py_BuildValue("(ll)", (long)(pos->lnum), (long)(pos->col));
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1901 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1902 else if (strcmp(name, "height") == 0)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1903 return PyLong_FromLong((long)(self->win->w_height));
4383
e2db42528a5b updated for version 7.3.940
Bram Moolenaar <bram@vim.org>
parents: 4381
diff changeset
1904 #ifdef FEAT_WINDOWS
e2db42528a5b updated for version 7.3.940
Bram Moolenaar <bram@vim.org>
parents: 4381
diff changeset
1905 else if (strcmp(name, "row") == 0)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1906 return PyLong_FromLong((long)(self->win->w_winrow));
4383
e2db42528a5b updated for version 7.3.940
Bram Moolenaar <bram@vim.org>
parents: 4381
diff changeset
1907 #endif
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1908 #ifdef FEAT_VERTSPLIT
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1909 else if (strcmp(name, "width") == 0)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1910 return PyLong_FromLong((long)(W_WIDTH(self->win)));
4383
e2db42528a5b updated for version 7.3.940
Bram Moolenaar <bram@vim.org>
parents: 4381
diff changeset
1911 else if (strcmp(name, "col") == 0)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1912 return PyLong_FromLong((long)(W_WINCOL(self->win)));
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1913 #endif
4323
f1eab4f77a6f updated for version 7.3.911
Bram Moolenaar <bram@vim.org>
parents: 4321
diff changeset
1914 else if (strcmp(name, "vars") == 0)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1915 return DictionaryNew(self->win->w_vars);
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
1916 else if (strcmp(name, "options") == 0)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1917 return OptionsNew(SREQ_WIN, self->win, (checkfun) CheckWindow,
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1918 (PyObject *) self);
4379
a2f03b41dca7 updated for version 7.3.938
Bram Moolenaar <bram@vim.org>
parents: 4377
diff changeset
1919 else if (strcmp(name, "number") == 0)
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
1920 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1921 if (CheckTabPage(self->tabObject))
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
1922 return NULL;
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
1923 return PyLong_FromLong((long)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1924 get_win_number(self->win, get_firstwin(self->tabObject)));
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
1925 }
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
1926 else if (strcmp(name, "tabpage") == 0)
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
1927 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1928 Py_INCREF(self->tabObject);
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1929 return (PyObject *)(self->tabObject);
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
1930 }
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1931 else if (strcmp(name,"__members__") == 0)
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
1932 return Py_BuildValue("[sssssssss]", "buffer", "cursor", "height",
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
1933 "vars", "options", "number", "row", "col", "tabpage");
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1934 else
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1935 return NULL;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1936 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
1937
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1938 static int
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1939 WindowSetattr(WindowObject *self, char *name, PyObject *val)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1940 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1941 if (CheckWindow(self))
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1942 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1943
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1944 if (strcmp(name, "buffer") == 0)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1945 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1946 PyErr_SetString(PyExc_TypeError, _("readonly attribute"));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1947 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1948 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1949 else if (strcmp(name, "cursor") == 0)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1950 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1951 long lnum;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1952 long col;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1953
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1954 if (!PyArg_Parse(val, "(ll)", &lnum, &col))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1955 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1956
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1957 if (lnum <= 0 || lnum > self->win->w_buffer->b_ml.ml_line_count)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1958 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1959 PyErr_SetVim(_("cursor position outside buffer"));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1960 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1961 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1962
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1963 /* Check for keyboard interrupts */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1964 if (VimErrorCheck())
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1965 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1966
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1967 self->win->w_cursor.lnum = lnum;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1968 self->win->w_cursor.col = col;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1969 #ifdef FEAT_VIRTUALEDIT
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1970 self->win->w_cursor.coladd = 0;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1971 #endif
2933
0bef86c5c985 updated for version 7.3.239
Bram Moolenaar <bram@vim.org>
parents: 2919
diff changeset
1972 /* When column is out of range silently correct it. */
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1973 check_cursor_col_win(self->win);
2933
0bef86c5c985 updated for version 7.3.239
Bram Moolenaar <bram@vim.org>
parents: 2919
diff changeset
1974
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1975 update_screen(VALID);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1976 return 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1977 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1978 else if (strcmp(name, "height") == 0)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1979 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1980 int height;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1981 win_T *savewin;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1982
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1983 if (!PyArg_Parse(val, "i", &height))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1984 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1985
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1986 #ifdef FEAT_GUI
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1987 need_mouse_correct = TRUE;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1988 #endif
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1989 savewin = curwin;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
1990 curwin = self->win;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1991 win_setheight(height);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1992 curwin = savewin;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1993
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1994 /* Check for keyboard interrupts */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1995 if (VimErrorCheck())
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1996 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1997
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1998 return 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
1999 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2000 #ifdef FEAT_VERTSPLIT
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2001 else if (strcmp(name, "width") == 0)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2002 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2003 int width;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2004 win_T *savewin;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2005
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2006 if (!PyArg_Parse(val, "i", &width))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2007 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2008
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2009 #ifdef FEAT_GUI
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2010 need_mouse_correct = TRUE;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2011 #endif
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2012 savewin = curwin;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2013 curwin = self->win;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2014 win_setwidth(width);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2015 curwin = savewin;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2016
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2017 /* Check for keyboard interrupts */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2018 if (VimErrorCheck())
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2019 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2020
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2021 return 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2022 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2023 #endif
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2024 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2025 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2026 PyErr_SetString(PyExc_AttributeError, name);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2027 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2028 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2029 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2030
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2031 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2032 WindowRepr(WindowObject *self)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2033 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2034 static char repr[100];
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2035
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2036 if (self->win == INVALID_WINDOW_VALUE)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2037 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2038 vim_snprintf(repr, 100, _("<window object (deleted) at %p>"), (self));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2039 return PyString_FromString(repr);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2040 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2041 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2042 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2043 int w = get_win_number(self->win, firstwin);
4379
a2f03b41dca7 updated for version 7.3.938
Bram Moolenaar <bram@vim.org>
parents: 4377
diff changeset
2044
a2f03b41dca7 updated for version 7.3.938
Bram Moolenaar <bram@vim.org>
parents: 4377
diff changeset
2045 if (w == 0)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2046 vim_snprintf(repr, 100, _("<window object (unknown) at %p>"),
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2047 (self));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2048 else
4379
a2f03b41dca7 updated for version 7.3.938
Bram Moolenaar <bram@vim.org>
parents: 4377
diff changeset
2049 vim_snprintf(repr, 100, _("<window %d>"), w - 1);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2050
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2051 return PyString_FromString(repr);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2052 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2053 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2054
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2055 static struct PyMethodDef WindowMethods[] = {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2056 /* name, function, calling, documentation */
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2057 { NULL, NULL, 0, NULL }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2058 };
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2059
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2060 /*
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2061 * Window list object
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2062 */
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2063
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2064 static PyTypeObject WinListType;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2065 static PySequenceMethods WinListAsSeq;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2066
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2067 typedef struct
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2068 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2069 PyObject_HEAD
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
2070 TabPageObject *tabObject;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2071 } WinListObject;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2072
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
2073 static PyObject *
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
2074 WinListNew(TabPageObject *tabObject)
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
2075 {
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
2076 WinListObject *self;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
2077
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
2078 self = PyObject_NEW(WinListObject, &WinListType);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
2079 self->tabObject = tabObject;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
2080 Py_INCREF(tabObject);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
2081
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
2082 return (PyObject *)(self);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
2083 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
2084
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
2085 static void
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2086 WinListDestructor(WinListObject *self)
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
2087 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2088 TabPageObject *tabObject = self->tabObject;
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
2089
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
2090 if (tabObject)
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
2091 Py_DECREF((PyObject *)(tabObject));
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
2092
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
2093 DESTRUCTOR_FINISH(self);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
2094 }
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
2095
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2096 static PyInt
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2097 WinListLength(WinListObject *self)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2098 {
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
2099 win_T *w;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2100 PyInt n = 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2101
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2102 if (!(w = get_firstwin(self->tabObject)))
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
2103 return -1;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
2104
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2105 while (w != NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2106 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2107 ++n;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2108 w = W_NEXT(w);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2109 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2110
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2111 return n;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2112 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2113
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2114 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2115 WinListItem(WinListObject *self, PyInt n)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2116 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2117 win_T *w;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2118
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2119 if (!(w = get_firstwin(self->tabObject)))
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
2120 return NULL;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
2121
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
2122 for (; w != NULL; w = W_NEXT(w), --n)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2123 if (n == 0)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2124 return WindowNew(w, self->tabObject? self->tabObject->tab: curtab);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2125
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2126 PyErr_SetString(PyExc_IndexError, _("no such window"));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2127 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2128 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2129
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2130 /* Convert a Python string into a Vim line.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2131 *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2132 * The result is in allocated memory. All internal nulls are replaced by
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2133 * newline characters. It is an error for the string to contain newline
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2134 * characters.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2135 *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2136 * On errors, the Python exception data is set, and NULL is returned.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2137 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2138 static char *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2139 StringToLine(PyObject *obj)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2140 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2141 const char *str;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2142 char *save;
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2143 PyObject *bytes;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2144 PyInt len;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2145 PyInt i;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2146 char *p;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2147
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2148 if (obj == NULL || !PyString_Check(obj))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2149 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2150 PyErr_BadArgument();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2151 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2152 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2153
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2154 bytes = PyString_AsBytes(obj); /* for Python 2 this does nothing */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2155 str = PyString_AsString(bytes);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2156 len = PyString_Size(bytes);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2157
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2158 /*
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2159 * Error checking: String must not contain newlines, as we
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2160 * are replacing a single line, and we must replace it with
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2161 * a single line.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2162 * A trailing newline is removed, so that append(f.readlines()) works.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2163 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2164 p = memchr(str, '\n', len);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2165 if (p != NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2166 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2167 if (p == str + len - 1)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2168 --len;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2169 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2170 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2171 PyErr_SetVim(_("string cannot contain newlines"));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2172 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2173 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2174 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2175
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2176 /* Create a copy of the string, with internal nulls replaced by
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2177 * newline characters, as is the vim convention.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2178 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2179 save = (char *)alloc((unsigned)(len+1));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2180 if (save == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2181 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2182 PyErr_NoMemory();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2183 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2184 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2185
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2186 for (i = 0; i < len; ++i)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2187 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2188 if (str[i] == '\0')
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2189 save[i] = '\n';
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2190 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2191 save[i] = str[i];
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2192 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2193
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2194 save[i] = '\0';
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2195 PyString_FreeBytes(bytes); /* Python 2 does nothing here */
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2196
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2197 return save;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2198 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2199
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2200 /* Get a line from the specified buffer. The line number is
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2201 * in Vim format (1-based). The line is returned as a Python
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2202 * string object.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2203 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2204 static PyObject *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2205 GetBufferLine(buf_T *buf, PyInt n)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2206 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2207 return LineToString((char *)ml_get_buf(buf, (linenr_T)n, FALSE));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2208 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2209
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2210
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2211 /* Get a list of lines from the specified buffer. The line numbers
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2212 * are in Vim format (1-based). The range is from lo up to, but not
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2213 * including, hi. The list is returned as a Python list of string objects.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2214 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2215 static PyObject *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2216 GetBufferLineList(buf_T *buf, PyInt lo, PyInt hi)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2217 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2218 PyInt i;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2219 PyInt n = hi - lo;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2220 PyObject *list = PyList_New(n);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2221
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2222 if (list == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2223 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2224
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2225 for (i = 0; i < n; ++i)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2226 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2227 PyObject *str = LineToString((char *)ml_get_buf(buf, (linenr_T)(lo+i), FALSE));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2228
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2229 /* Error check - was the Python string creation OK? */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2230 if (str == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2231 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2232 Py_DECREF(list);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2233 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2234 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2235
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2236 /* Set the list item */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2237 if (PyList_SetItem(list, i, str))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2238 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2239 Py_DECREF(str);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2240 Py_DECREF(list);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2241 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2242 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2243 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2244
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2245 /* The ownership of the Python list is passed to the caller (ie,
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2246 * the caller should Py_DECREF() the object when it is finished
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2247 * with it).
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2248 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2249
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2250 return list;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2251 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2252
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2253 /*
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2254 * Check if deleting lines made the cursor position invalid.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2255 * Changed the lines from "lo" to "hi" and added "extra" lines (negative if
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2256 * deleted).
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2257 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2258 static void
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2259 py_fix_cursor(linenr_T lo, linenr_T hi, linenr_T extra)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2260 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2261 if (curwin->w_cursor.lnum >= lo)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2262 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2263 /* Adjust the cursor position if it's in/after the changed
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2264 * lines. */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2265 if (curwin->w_cursor.lnum >= hi)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2266 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2267 curwin->w_cursor.lnum += extra;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2268 check_cursor_col();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2269 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2270 else if (extra < 0)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2271 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2272 curwin->w_cursor.lnum = lo;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2273 check_cursor();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2274 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2275 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2276 check_cursor_col();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2277 changed_cline_bef_curs();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2278 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2279 invalidate_botline();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2280 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2281
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2282 /*
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2283 * Replace a line in the specified buffer. The line number is
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2284 * in Vim format (1-based). The replacement line is given as
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2285 * a Python string object. The object is checked for validity
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2286 * and correct format. Errors are returned as a value of FAIL.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2287 * The return value is OK on success.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2288 * If OK is returned and len_change is not NULL, *len_change
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2289 * is set to the change in the buffer length.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2290 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2291 static int
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2292 SetBufferLine(buf_T *buf, PyInt n, PyObject *line, PyInt *len_change)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2293 {
4352
04736b4030ec updated for version 7.3.925
Bram Moolenaar <bram@vim.org>
parents: 4350
diff changeset
2294 /* First of all, we check the type of the supplied Python object.
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2295 * There are three cases:
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2296 * 1. NULL, or None - this is a deletion.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2297 * 2. A string - this is a replacement.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2298 * 3. Anything else - this is an error.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2299 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2300 if (line == Py_None || line == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2301 {
4429
7eafa576528e updated for version 7.3.963
Bram Moolenaar <bram@vim.org>
parents: 4419
diff changeset
2302 buf_T *savebuf;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2303
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2304 PyErr_Clear();
4429
7eafa576528e updated for version 7.3.963
Bram Moolenaar <bram@vim.org>
parents: 4419
diff changeset
2305 switch_buffer(&savebuf, buf);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2306
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2307 if (u_savedel((linenr_T)n, 1L) == FAIL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2308 PyErr_SetVim(_("cannot save undo information"));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2309 else if (ml_delete((linenr_T)n, FALSE) == FAIL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2310 PyErr_SetVim(_("cannot delete line"));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2311 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2312 {
4429
7eafa576528e updated for version 7.3.963
Bram Moolenaar <bram@vim.org>
parents: 4419
diff changeset
2313 if (buf == savebuf)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2314 py_fix_cursor((linenr_T)n, (linenr_T)n + 1, (linenr_T)-1);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2315 deleted_lines_mark((linenr_T)n, 1L);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2316 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2317
4429
7eafa576528e updated for version 7.3.963
Bram Moolenaar <bram@vim.org>
parents: 4419
diff changeset
2318 restore_buffer(savebuf);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2319
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2320 if (PyErr_Occurred() || VimErrorCheck())
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2321 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2322
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2323 if (len_change)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2324 *len_change = -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2325
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2326 return OK;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2327 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2328 else if (PyString_Check(line))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2329 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2330 char *save = StringToLine(line);
4429
7eafa576528e updated for version 7.3.963
Bram Moolenaar <bram@vim.org>
parents: 4419
diff changeset
2331 buf_T *savebuf;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2332
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2333 if (save == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2334 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2335
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2336 /* We do not need to free "save" if ml_replace() consumes it. */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2337 PyErr_Clear();
4429
7eafa576528e updated for version 7.3.963
Bram Moolenaar <bram@vim.org>
parents: 4419
diff changeset
2338 switch_buffer(&savebuf, buf);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2339
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2340 if (u_savesub((linenr_T)n) == FAIL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2341 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2342 PyErr_SetVim(_("cannot save undo information"));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2343 vim_free(save);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2344 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2345 else if (ml_replace((linenr_T)n, (char_u *)save, FALSE) == FAIL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2346 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2347 PyErr_SetVim(_("cannot replace line"));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2348 vim_free(save);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2349 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2350 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2351 changed_bytes((linenr_T)n, 0);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2352
4429
7eafa576528e updated for version 7.3.963
Bram Moolenaar <bram@vim.org>
parents: 4419
diff changeset
2353 restore_buffer(savebuf);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2354
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2355 /* Check that the cursor is not beyond the end of the line now. */
4429
7eafa576528e updated for version 7.3.963
Bram Moolenaar <bram@vim.org>
parents: 4419
diff changeset
2356 if (buf == savebuf)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2357 check_cursor_col();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2358
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2359 if (PyErr_Occurred() || VimErrorCheck())
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2360 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2361
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2362 if (len_change)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2363 *len_change = 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2364
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2365 return OK;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2366 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2367 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2368 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2369 PyErr_BadArgument();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2370 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2371 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2372 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2373
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2374 /* Replace a range of lines in the specified buffer. The line numbers are in
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2375 * Vim format (1-based). The range is from lo up to, but not including, hi.
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2376 * The replacement lines are given as a Python list of string objects. The
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2377 * list is checked for validity and correct format. Errors are returned as a
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2378 * value of FAIL. The return value is OK on success.
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2379 * If OK is returned and len_change is not NULL, *len_change
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2380 * is set to the change in the buffer length.
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2381 */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2382 static int
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2383 SetBufferLineList(buf_T *buf, PyInt lo, PyInt hi, PyObject *list, PyInt *len_change)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2384 {
4352
04736b4030ec updated for version 7.3.925
Bram Moolenaar <bram@vim.org>
parents: 4350
diff changeset
2385 /* First of all, we check the type of the supplied Python object.
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2386 * There are three cases:
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2387 * 1. NULL, or None - this is a deletion.
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2388 * 2. A list - this is a replacement.
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2389 * 3. Anything else - this is an error.
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2390 */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2391 if (list == Py_None || list == NULL)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2392 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2393 PyInt i;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2394 PyInt n = (int)(hi - lo);
4429
7eafa576528e updated for version 7.3.963
Bram Moolenaar <bram@vim.org>
parents: 4419
diff changeset
2395 buf_T *savebuf;
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2396
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2397 PyErr_Clear();
4429
7eafa576528e updated for version 7.3.963
Bram Moolenaar <bram@vim.org>
parents: 4419
diff changeset
2398 switch_buffer(&savebuf, buf);
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2399
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2400 if (u_savedel((linenr_T)lo, (long)n) == FAIL)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2401 PyErr_SetVim(_("cannot save undo information"));
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2402 else
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2403 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2404 for (i = 0; i < n; ++i)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2405 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2406 if (ml_delete((linenr_T)lo, FALSE) == FAIL)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2407 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2408 PyErr_SetVim(_("cannot delete line"));
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2409 break;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2410 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2411 }
4429
7eafa576528e updated for version 7.3.963
Bram Moolenaar <bram@vim.org>
parents: 4419
diff changeset
2412 if (buf == savebuf)
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2413 py_fix_cursor((linenr_T)lo, (linenr_T)hi, (linenr_T)-n);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2414 deleted_lines_mark((linenr_T)lo, (long)i);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2415 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2416
4429
7eafa576528e updated for version 7.3.963
Bram Moolenaar <bram@vim.org>
parents: 4419
diff changeset
2417 restore_buffer(savebuf);
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2418
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2419 if (PyErr_Occurred() || VimErrorCheck())
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2420 return FAIL;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2421
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2422 if (len_change)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2423 *len_change = -n;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2424
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2425 return OK;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2426 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2427 else if (PyList_Check(list))
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2428 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2429 PyInt i;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2430 PyInt new_len = PyList_Size(list);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2431 PyInt old_len = hi - lo;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2432 PyInt extra = 0; /* lines added to text, can be negative */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2433 char **array;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2434 buf_T *savebuf;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2435
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2436 if (new_len == 0) /* avoid allocating zero bytes */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2437 array = NULL;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2438 else
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2439 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2440 array = (char **)alloc((unsigned)(new_len * sizeof(char *)));
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2441 if (array == NULL)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2442 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2443 PyErr_NoMemory();
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2444 return FAIL;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2445 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2446 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2447
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2448 for (i = 0; i < new_len; ++i)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2449 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2450 PyObject *line = PyList_GetItem(list, i);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2451
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2452 array[i] = StringToLine(line);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2453 if (array[i] == NULL)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2454 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2455 while (i)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2456 vim_free(array[--i]);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2457 vim_free(array);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2458 return FAIL;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2459 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2460 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2461
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2462 PyErr_Clear();
4429
7eafa576528e updated for version 7.3.963
Bram Moolenaar <bram@vim.org>
parents: 4419
diff changeset
2463
7eafa576528e updated for version 7.3.963
Bram Moolenaar <bram@vim.org>
parents: 4419
diff changeset
2464 // START of region without "return". Must call restore_buffer()!
7eafa576528e updated for version 7.3.963
Bram Moolenaar <bram@vim.org>
parents: 4419
diff changeset
2465 switch_buffer(&savebuf, buf);
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2466
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2467 if (u_save((linenr_T)(lo-1), (linenr_T)hi) == FAIL)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2468 PyErr_SetVim(_("cannot save undo information"));
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2469
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2470 /* If the size of the range is reducing (ie, new_len < old_len) we
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2471 * need to delete some old_len. We do this at the start, by
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2472 * repeatedly deleting line "lo".
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2473 */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2474 if (!PyErr_Occurred())
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2475 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2476 for (i = 0; i < old_len - new_len; ++i)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2477 if (ml_delete((linenr_T)lo, FALSE) == FAIL)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2478 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2479 PyErr_SetVim(_("cannot delete line"));
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2480 break;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2481 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2482 extra -= i;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2483 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2484
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2485 /* For as long as possible, replace the existing old_len with the
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2486 * new old_len. This is a more efficient operation, as it requires
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2487 * less memory allocation and freeing.
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2488 */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2489 if (!PyErr_Occurred())
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2490 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2491 for (i = 0; i < old_len && i < new_len; ++i)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2492 if (ml_replace((linenr_T)(lo+i), (char_u *)array[i], FALSE)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2493 == FAIL)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2494 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2495 PyErr_SetVim(_("cannot replace line"));
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2496 break;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2497 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2498 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2499 else
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2500 i = 0;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2501
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2502 /* Now we may need to insert the remaining new old_len. If we do, we
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2503 * must free the strings as we finish with them (we can't pass the
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2504 * responsibility to vim in this case).
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2505 */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2506 if (!PyErr_Occurred())
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2507 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2508 while (i < new_len)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2509 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2510 if (ml_append((linenr_T)(lo + i - 1),
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2511 (char_u *)array[i], 0, FALSE) == FAIL)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2512 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2513 PyErr_SetVim(_("cannot insert line"));
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2514 break;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2515 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2516 vim_free(array[i]);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2517 ++i;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2518 ++extra;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2519 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2520 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2521
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2522 /* Free any left-over old_len, as a result of an error */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2523 while (i < new_len)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2524 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2525 vim_free(array[i]);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2526 ++i;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2527 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2528
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2529 /* Free the array of old_len. All of its contents have now
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2530 * been dealt with (either freed, or the responsibility passed
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2531 * to vim.
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2532 */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2533 vim_free(array);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2534
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2535 /* Adjust marks. Invalidate any which lie in the
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2536 * changed range, and move any in the remainder of the buffer.
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2537 */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2538 mark_adjust((linenr_T)lo, (linenr_T)(hi - 1),
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2539 (long)MAXLNUM, (long)extra);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2540 changed_lines((linenr_T)lo, 0, (linenr_T)hi, (long)extra);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2541
4429
7eafa576528e updated for version 7.3.963
Bram Moolenaar <bram@vim.org>
parents: 4419
diff changeset
2542 if (buf == savebuf)
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2543 py_fix_cursor((linenr_T)lo, (linenr_T)hi, (linenr_T)extra);
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2544
4429
7eafa576528e updated for version 7.3.963
Bram Moolenaar <bram@vim.org>
parents: 4419
diff changeset
2545 // END of region without "return".
7eafa576528e updated for version 7.3.963
Bram Moolenaar <bram@vim.org>
parents: 4419
diff changeset
2546 restore_buffer(savebuf);
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2547
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2548 if (PyErr_Occurred() || VimErrorCheck())
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2549 return FAIL;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2550
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2551 if (len_change)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2552 *len_change = new_len - old_len;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2553
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2554 return OK;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2555 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2556 else
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2557 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2558 PyErr_BadArgument();
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2559 return FAIL;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2560 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2561 }
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2562
4352
04736b4030ec updated for version 7.3.925
Bram Moolenaar <bram@vim.org>
parents: 4350
diff changeset
2563 /* Insert a number of lines into the specified buffer after the specified line.
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2564 * The line number is in Vim format (1-based). The lines to be inserted are
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2565 * given as a Python list of string objects or as a single string. The lines
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2566 * to be added are checked for validity and correct format. Errors are
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2567 * returned as a value of FAIL. The return value is OK on success.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2568 * If OK is returned and len_change is not NULL, *len_change
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2569 * is set to the change in the buffer length.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2570 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2571 static int
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2572 InsertBufferLines(buf_T *buf, PyInt n, PyObject *lines, PyInt *len_change)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2573 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2574 /* First of all, we check the type of the supplied Python object.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2575 * It must be a string or a list, or the call is in error.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2576 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2577 if (PyString_Check(lines))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2578 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2579 char *str = StringToLine(lines);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2580 buf_T *savebuf;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2581
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2582 if (str == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2583 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2584
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2585 PyErr_Clear();
4429
7eafa576528e updated for version 7.3.963
Bram Moolenaar <bram@vim.org>
parents: 4419
diff changeset
2586 switch_buffer(&savebuf, buf);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2587
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2588 if (u_save((linenr_T)n, (linenr_T)(n+1)) == FAIL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2589 PyErr_SetVim(_("cannot save undo information"));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2590 else if (ml_append((linenr_T)n, (char_u *)str, 0, FALSE) == FAIL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2591 PyErr_SetVim(_("cannot insert line"));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2592 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2593 appended_lines_mark((linenr_T)n, 1L);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2594
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2595 vim_free(str);
4429
7eafa576528e updated for version 7.3.963
Bram Moolenaar <bram@vim.org>
parents: 4419
diff changeset
2596 restore_buffer(savebuf);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2597 update_screen(VALID);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2598
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2599 if (PyErr_Occurred() || VimErrorCheck())
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2600 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2601
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2602 if (len_change)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2603 *len_change = 1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2604
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2605 return OK;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2606 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2607 else if (PyList_Check(lines))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2608 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2609 PyInt i;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2610 PyInt size = PyList_Size(lines);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2611 char **array;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2612 buf_T *savebuf;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2613
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2614 array = (char **)alloc((unsigned)(size * sizeof(char *)));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2615 if (array == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2616 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2617 PyErr_NoMemory();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2618 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2619 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2620
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2621 for (i = 0; i < size; ++i)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2622 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2623 PyObject *line = PyList_GetItem(lines, i);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2624 array[i] = StringToLine(line);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2625
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2626 if (array[i] == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2627 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2628 while (i)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2629 vim_free(array[--i]);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2630 vim_free(array);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2631 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2632 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2633 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2634
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2635 PyErr_Clear();
4429
7eafa576528e updated for version 7.3.963
Bram Moolenaar <bram@vim.org>
parents: 4419
diff changeset
2636 switch_buffer(&savebuf, buf);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2637
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2638 if (u_save((linenr_T)n, (linenr_T)(n + 1)) == FAIL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2639 PyErr_SetVim(_("cannot save undo information"));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2640 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2641 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2642 for (i = 0; i < size; ++i)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2643 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2644 if (ml_append((linenr_T)(n + i),
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2645 (char_u *)array[i], 0, FALSE) == FAIL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2646 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2647 PyErr_SetVim(_("cannot insert line"));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2648
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2649 /* Free the rest of the lines */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2650 while (i < size)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2651 vim_free(array[i++]);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2652
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2653 break;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2654 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2655 vim_free(array[i]);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2656 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2657 if (i > 0)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2658 appended_lines_mark((linenr_T)n, (long)i);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2659 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2660
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2661 /* Free the array of lines. All of its contents have now
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2662 * been freed.
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2663 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2664 vim_free(array);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2665
4429
7eafa576528e updated for version 7.3.963
Bram Moolenaar <bram@vim.org>
parents: 4419
diff changeset
2666 restore_buffer(savebuf);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2667 update_screen(VALID);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2668
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2669 if (PyErr_Occurred() || VimErrorCheck())
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2670 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2671
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2672 if (len_change)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2673 *len_change = size;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2674
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2675 return OK;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2676 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2677 else
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2678 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2679 PyErr_BadArgument();
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2680 return FAIL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2681 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2682 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2683
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2684 /*
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2685 * Common routines for buffers and line ranges
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2686 * -------------------------------------------
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2687 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2688
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2689 typedef struct
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2690 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2691 PyObject_HEAD
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2692 buf_T *buf;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2693 } BufferObject;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2694
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2695 static int
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2696 CheckBuffer(BufferObject *self)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2697 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2698 if (self->buf == INVALID_BUFFER_VALUE)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2699 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2700 PyErr_SetVim(_("attempt to refer to deleted buffer"));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2701 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2702 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2703
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2704 return 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2705 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2706
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2707 static PyObject *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2708 RBItem(BufferObject *self, PyInt n, PyInt start, PyInt end)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2709 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2710 if (CheckBuffer(self))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2711 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2712
4387
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
2713 if (end == -1)
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
2714 end = self->buf->b_ml.ml_line_count;
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
2715
4389
736b8e18a3bc updated for version 7.3.943
Bram Moolenaar <bram@vim.org>
parents: 4387
diff changeset
2716 if (n < 0)
736b8e18a3bc updated for version 7.3.943
Bram Moolenaar <bram@vim.org>
parents: 4387
diff changeset
2717 n += end - start + 1;
736b8e18a3bc updated for version 7.3.943
Bram Moolenaar <bram@vim.org>
parents: 4387
diff changeset
2718
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2719 if (n < 0 || n > end - start)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2720 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2721 PyErr_SetString(PyExc_IndexError, _("line number out of range"));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2722 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2723 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2724
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2725 return GetBufferLine(self->buf, n+start);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2726 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2727
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2728 static PyObject *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2729 RBSlice(BufferObject *self, PyInt lo, PyInt hi, PyInt start, PyInt end)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2730 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2731 PyInt size;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2732
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2733 if (CheckBuffer(self))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2734 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2735
4387
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
2736 if (end == -1)
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
2737 end = self->buf->b_ml.ml_line_count;
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
2738
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2739 size = end - start + 1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2740
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2741 if (lo < 0)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2742 lo = 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2743 else if (lo > size)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2744 lo = size;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2745 if (hi < 0)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2746 hi = 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2747 if (hi < lo)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2748 hi = lo;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2749 else if (hi > size)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2750 hi = size;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2751
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2752 return GetBufferLineList(self->buf, lo+start, hi+start);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2753 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2754
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2755 static PyInt
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2756 RBAsItem(BufferObject *self, PyInt n, PyObject *val, PyInt start, PyInt end, PyInt *new_end)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2757 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2758 PyInt len_change;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2759
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2760 if (CheckBuffer(self))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2761 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2762
4387
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
2763 if (end == -1)
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
2764 end = self->buf->b_ml.ml_line_count;
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
2765
4389
736b8e18a3bc updated for version 7.3.943
Bram Moolenaar <bram@vim.org>
parents: 4387
diff changeset
2766 if (n < 0)
736b8e18a3bc updated for version 7.3.943
Bram Moolenaar <bram@vim.org>
parents: 4387
diff changeset
2767 n += end - start + 1;
736b8e18a3bc updated for version 7.3.943
Bram Moolenaar <bram@vim.org>
parents: 4387
diff changeset
2768
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2769 if (n < 0 || n > end - start)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2770 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2771 PyErr_SetString(PyExc_IndexError, _("line number out of range"));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2772 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2773 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2774
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2775 if (SetBufferLine(self->buf, n+start, val, &len_change) == FAIL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2776 return -1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2777
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2778 if (new_end)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2779 *new_end = end + len_change;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2780
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2781 return 0;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2782 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2783
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2784 static PyInt
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2785 RBAsSlice(BufferObject *self, PyInt lo, PyInt hi, PyObject *val, PyInt start, PyInt end, PyInt *new_end)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2786 {
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2787 PyInt size;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2788 PyInt len_change;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2789
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2790 /* Self must be a valid buffer */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2791 if (CheckBuffer(self))
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2792 return -1;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2793
4387
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
2794 if (end == -1)
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
2795 end = self->buf->b_ml.ml_line_count;
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
2796
2894
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2797 /* Sort out the slice range */
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2798 size = end - start + 1;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2799
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2800 if (lo < 0)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2801 lo = 0;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2802 else if (lo > size)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2803 lo = size;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2804 if (hi < 0)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2805 hi = 0;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2806 if (hi < lo)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2807 hi = lo;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2808 else if (hi > size)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2809 hi = size;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2810
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2811 if (SetBufferLineList(self->buf, lo + start, hi + start,
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2812 val, &len_change) == FAIL)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2813 return -1;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2814
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2815 if (new_end)
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2816 *new_end = end + len_change;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2817
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2818 return 0;
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2819 }
fe9c7da98b5e updated for version 7.3.220
Bram Moolenaar <bram@vim.org>
parents: 2727
diff changeset
2820
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2821
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2822 static PyObject *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2823 RBAppend(BufferObject *self, PyObject *args, PyInt start, PyInt end, PyInt *new_end)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2824 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2825 PyObject *lines;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2826 PyInt len_change;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2827 PyInt max;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2828 PyInt n;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2829
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2830 if (CheckBuffer(self))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2831 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2832
4387
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
2833 if (end == -1)
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
2834 end = self->buf->b_ml.ml_line_count;
358c10968c7f updated for version 7.3.942
Bram Moolenaar <bram@vim.org>
parents: 4385
diff changeset
2835
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2836 max = n = end - start + 1;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2837
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2838 if (!PyArg_ParseTuple(args, "O|n", &lines, &n))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2839 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2840
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2841 if (n < 0 || n > max)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2842 {
4405
907b1f035ee7 updated for version 7.3.951
Bram Moolenaar <bram@vim.org>
parents: 4403
diff changeset
2843 PyErr_SetString(PyExc_IndexError, _("line number out of range"));
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2844 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2845 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2846
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2847 if (InsertBufferLines(self->buf, n + start - 1, lines, &len_change) == FAIL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2848 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2849
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2850 if (new_end)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2851 *new_end = end + len_change;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2852
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2853 Py_INCREF(Py_None);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2854 return Py_None;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2855 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2856
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2857 /* Range object
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2858 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2859
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2860 static PyTypeObject RangeType;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2861 static PySequenceMethods RangeAsSeq;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2862 static PyMappingMethods RangeAsMapping;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2863
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2864 typedef struct
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2865 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2866 PyObject_HEAD
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2867 BufferObject *buf;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2868 PyInt start;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2869 PyInt end;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2870 } RangeObject;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2871
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2872 static PyObject *
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2873 RangeNew(buf_T *buf, PyInt start, PyInt end)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2874 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2875 BufferObject *bufr;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2876 RangeObject *self;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2877 self = PyObject_NEW(RangeObject, &RangeType);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2878 if (self == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2879 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2880
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2881 bufr = (BufferObject *)BufferNew(buf);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2882 if (bufr == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2883 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2884 Py_DECREF(self);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2885 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2886 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2887 Py_INCREF(bufr);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2888
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2889 self->buf = bufr;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2890 self->start = start;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2891 self->end = end;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2892
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2893 return (PyObject *)(self);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2894 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
2895
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2896 static void
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2897 RangeDestructor(RangeObject *self)
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2898 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2899 Py_DECREF(self->buf);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2900 DESTRUCTOR_FINISH(self);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2901 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2902
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2903 static PyInt
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2904 RangeLength(RangeObject *self)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2905 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2906 /* HOW DO WE SIGNAL AN ERROR FROM THIS FUNCTION? */
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2907 if (CheckBuffer(self->buf))
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2908 return -1; /* ??? */
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2909
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2910 return (self->end - self->start + 1);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2911 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2912
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2913 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2914 RangeItem(RangeObject *self, PyInt n)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2915 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2916 return RBItem(self->buf, n, self->start, self->end);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2917 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2918
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2919 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2920 RangeSlice(RangeObject *self, PyInt lo, PyInt hi)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2921 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2922 return RBSlice(self->buf, lo, hi, self->start, self->end);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2923 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2924
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2925 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2926 RangeAppend(RangeObject *self, PyObject *args)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2927 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2928 return RBAppend(self->buf, args, self->start, self->end, &self->end);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2929 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2930
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2931 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2932 RangeRepr(RangeObject *self)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2933 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2934 static char repr[100];
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2935
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2936 if (self->buf->buf == INVALID_BUFFER_VALUE)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2937 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2938 vim_snprintf(repr, 100, "<range object (for deleted buffer) at %p>",
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2939 (self));
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2940 return PyString_FromString(repr);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2941 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2942 else
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2943 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2944 char *name = (char *)self->buf->buf->b_fname;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2945 int len;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2946
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2947 if (name == NULL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2948 name = "";
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2949 len = (int)strlen(name);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2950
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2951 if (len > 45)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2952 name = name + (45 - len);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2953
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2954 vim_snprintf(repr, 100, "<range %s%s (%d:%d)>",
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2955 len > 45 ? "..." : "", name,
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
2956 self->start, self->end);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2957
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2958 return PyString_FromString(repr);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2959 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2960 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2961
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2962 static struct PyMethodDef RangeMethods[] = {
4492
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
2963 /* name, function, calling, documentation */
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
2964 {"append", (PyCFunction)RangeAppend, METH_VARARGS, "Append data to the Vim range" },
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
2965 { NULL, NULL, 0, NULL }
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2966 };
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2967
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2968 static PyTypeObject BufferType;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2969 static PySequenceMethods BufferAsSeq;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2970 static PyMappingMethods BufferAsMapping;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2971
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
2972 static PyObject *
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2973 BufferNew(buf_T *buf)
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2974 {
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2975 /* We need to handle deletion of buffers underneath us.
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2976 * If we add a "b_python*_ref" field to the buf_T structure,
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2977 * then we can get at it in buf_freeall() in vim. We then
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2978 * need to create only ONE Python object per buffer - if
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2979 * we try to create a second, just INCREF the existing one
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2980 * and return it. The (single) Python object referring to
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2981 * the buffer is stored in "b_python*_ref".
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2982 * Question: what to do on a buf_freeall(). We'll probably
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2983 * have to either delete the Python object (DECREF it to
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2984 * zero - a bad idea, as it leaves dangling refs!) or
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2985 * set the buf_T * value to an invalid value (-1?), which
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2986 * means we need checks in all access functions... Bah.
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2987 *
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
2988 * Python2 and Python3 get different fields and different objects:
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2989 * b_python_ref and b_python3_ref fields respectively.
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2990 */
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2991
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2992 BufferObject *self;
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2993
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2994 if (BUF_PYTHON_REF(buf) != NULL)
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2995 {
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2996 self = BUF_PYTHON_REF(buf);
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2997 Py_INCREF(self);
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2998 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
2999 else
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3000 {
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3001 self = PyObject_NEW(BufferObject, &BufferType);
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3002 if (self == NULL)
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3003 return NULL;
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3004 self->buf = buf;
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3005 BUF_PYTHON_REF(buf) = self;
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3006 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3007
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3008 return (PyObject *)(self);
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3009 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3010
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3011 static void
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3012 BufferDestructor(BufferObject *self)
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3013 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3014 if (self->buf && self->buf != INVALID_BUFFER_VALUE)
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3015 BUF_PYTHON_REF(self->buf) = NULL;
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3016
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3017 DESTRUCTOR_FINISH(self);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3018 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3019
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3020 static PyInt
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3021 BufferLength(BufferObject *self)
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3022 {
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3023 /* HOW DO WE SIGNAL AN ERROR FROM THIS FUNCTION? */
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3024 if (CheckBuffer(self))
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3025 return -1; /* ??? */
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3026
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3027 return (PyInt)(self->buf->b_ml.ml_line_count);
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3028 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3029
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3030 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3031 BufferItem(BufferObject *self, PyInt n)
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3032 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3033 return RBItem(self, n, 1, -1);
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3034 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3035
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3036 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3037 BufferSlice(BufferObject *self, PyInt lo, PyInt hi)
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3038 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3039 return RBSlice(self, lo, hi, 1, -1);
4377
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3040 }
8ec7323f417d updated for version 7.3.937
Bram Moolenaar <bram@vim.org>
parents: 4359
diff changeset
3041
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3042 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3043 BufferAttr(BufferObject *self, char *name)
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3044 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3045 if (strcmp(name, "name") == 0)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3046 return Py_BuildValue("s", self->buf->b_ffname);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3047 else if (strcmp(name, "number") == 0)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3048 return Py_BuildValue(Py_ssize_t_fmt, self->buf->b_fnum);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3049 else if (strcmp(name, "vars") == 0)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3050 return DictionaryNew(self->buf->b_vars);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3051 else if (strcmp(name, "options") == 0)
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3052 return OptionsNew(SREQ_BUF, self->buf, (checkfun) CheckBuffer,
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3053 (PyObject *) self);
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3054 else if (strcmp(name,"__members__") == 0)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3055 return Py_BuildValue("[ssss]", "name", "number", "vars", "options");
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3056 else
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3057 return NULL;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3058 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3059
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3060 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3061 BufferAppend(BufferObject *self, PyObject *args)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3062 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3063 return RBAppend(self, args, 1, -1, NULL);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3064 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3065
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3066 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3067 BufferMark(BufferObject *self, PyObject *args)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3068 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3069 pos_T *posp;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3070 char *pmark;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3071 char mark;
4429
7eafa576528e updated for version 7.3.963
Bram Moolenaar <bram@vim.org>
parents: 4419
diff changeset
3072 buf_T *savebuf;
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3073
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3074 if (CheckBuffer(self))
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3075 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3076
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3077 if (!PyArg_ParseTuple(args, "s", &pmark))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3078 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3079 mark = *pmark;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3080
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3081 switch_buffer(&savebuf, self->buf);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3082 posp = getmark(mark, FALSE);
4429
7eafa576528e updated for version 7.3.963
Bram Moolenaar <bram@vim.org>
parents: 4419
diff changeset
3083 restore_buffer(savebuf);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3084
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3085 if (posp == NULL)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3086 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3087 PyErr_SetVim(_("invalid mark name"));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3088 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3089 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3090
4352
04736b4030ec updated for version 7.3.925
Bram Moolenaar <bram@vim.org>
parents: 4350
diff changeset
3091 /* Check for keyboard interrupt */
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3092 if (VimErrorCheck())
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3093 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3094
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3095 if (posp->lnum <= 0)
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3096 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3097 /* Or raise an error? */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3098 Py_INCREF(Py_None);
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3099 return Py_None;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3100 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3101
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3102 return Py_BuildValue("(ll)", (long)(posp->lnum), (long)(posp->col));
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3103 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3104
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3105 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3106 BufferRange(BufferObject *self, PyObject *args)
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3107 {
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3108 PyInt start;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3109 PyInt end;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3110
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3111 if (CheckBuffer(self))
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3112 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3113
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3114 if (!PyArg_ParseTuple(args, "nn", &start, &end))
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3115 return NULL;
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3116
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3117 return RangeNew(self->buf, start, end);
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3118 }
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3119
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3120 static PyObject *
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3121 BufferRepr(BufferObject *self)
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3122 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3123 static char repr[100];
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3124
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3125 if (self->buf == INVALID_BUFFER_VALUE)
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3126 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3127 vim_snprintf(repr, 100, _("<buffer object (deleted) at %p>"), (self));
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3128 return PyString_FromString(repr);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3129 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3130 else
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3131 {
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3132 char *name = (char *)self->buf->b_fname;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3133 PyInt len;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3134
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3135 if (name == NULL)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3136 name = "";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3137 len = strlen(name);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3138
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3139 if (len > 35)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3140 name = name + (35 - len);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3141
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3142 vim_snprintf(repr, 100, "<buffer %s%s>", len > 35 ? "..." : "", name);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3143
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3144 return PyString_FromString(repr);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3145 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3146 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3147
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3148 static struct PyMethodDef BufferMethods[] = {
4492
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
3149 /* name, function, calling, documentation */
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
3150 {"append", (PyCFunction)BufferAppend, METH_VARARGS, "Append data to Vim buffer" },
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
3151 {"mark", (PyCFunction)BufferMark, METH_VARARGS, "Return (row,col) representing position of named mark" },
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
3152 {"range", (PyCFunction)BufferRange, METH_VARARGS, "Return a range object which represents the part of the given buffer between line numbers s and e" },
3310
60f6df978a41 updated for version 7.3.422
Bram Moolenaar <bram@vim.org>
parents: 3056
diff changeset
3153 #if PY_VERSION_HEX >= 0x03000000
4492
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
3154 {"__dir__", (PyCFunction)BufferDir, METH_NOARGS, "List buffer attributes" },
3310
60f6df978a41 updated for version 7.3.422
Bram Moolenaar <bram@vim.org>
parents: 3056
diff changeset
3155 #endif
4492
f74611bfb1b7 updated for version 7.3.994
Bram Moolenaar <bram@vim.org>
parents: 4490
diff changeset
3156 { NULL, NULL, 0, NULL }
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3157 };
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3158
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3159 /*
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3160 * Buffer list object - Implementation
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3161 */
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3162
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3163 static PyTypeObject BufMapType;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3164
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3165 typedef struct
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3166 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3167 PyObject_HEAD
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3168 } BufMapObject;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3169
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3170 static PyInt
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3171 BufMapLength(PyObject *self UNUSED)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3172 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3173 buf_T *b = firstbuf;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3174 PyInt n = 0;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3175
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3176 while (b)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3177 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3178 ++n;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3179 b = b->b_next;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3180 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3181
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3182 return n;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3183 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3184
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3185 static PyObject *
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3186 BufMapItem(PyObject *self UNUSED, PyObject *keyObject)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3187 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3188 buf_T *b;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3189 int bnr;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3190
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3191 #if PY_MAJOR_VERSION < 3
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3192 if (PyInt_Check(keyObject))
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3193 bnr = PyInt_AsLong(keyObject);
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3194 else
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3195 #endif
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3196 if (PyLong_Check(keyObject))
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3197 bnr = PyLong_AsLong(keyObject);
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3198 else
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3199 {
4405
907b1f035ee7 updated for version 7.3.951
Bram Moolenaar <bram@vim.org>
parents: 4403
diff changeset
3200 PyErr_SetString(PyExc_TypeError, _("key must be integer"));
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3201 return NULL;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3202 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3203
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3204 b = buflist_findnr(bnr);
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3205
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3206 if (b)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3207 return BufferNew(b);
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3208 else
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3209 {
4403
d4816e7c3328 updated for version 7.3.950
Bram Moolenaar <bram@vim.org>
parents: 4401
diff changeset
3210 PyErr_SetObject(PyExc_KeyError, keyObject);
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3211 return NULL;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3212 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3213 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3214
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3215 static void
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3216 BufMapIterDestruct(PyObject *buffer)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3217 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3218 /* Iteration was stopped before all buffers were processed */
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3219 if (buffer)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3220 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3221 Py_DECREF(buffer);
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3222 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3223 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3224
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3225 static int
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3226 BufMapIterTraverse(PyObject *buffer, visitproc visit, void *arg)
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3227 {
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3228 Py_VISIT(buffer);
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3229 return 0;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3230 }
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3231
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3232 static int
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3233 BufMapIterClear(PyObject **buffer)
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3234 {
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3235 Py_CLEAR(*buffer);
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3236 return 0;
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3237 }
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3238
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3239 static PyObject *
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3240 BufMapIterNext(PyObject **buffer)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3241 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3242 PyObject *next;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3243 PyObject *r;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3244
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3245 if (!*buffer)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3246 return NULL;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3247
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3248 r = *buffer;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3249
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3250 if (CheckBuffer((BufferObject *)(r)))
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3251 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3252 *buffer = NULL;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3253 return NULL;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3254 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3255
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3256 if (!((BufferObject *)(r))->buf->b_next)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3257 next = NULL;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3258 else if (!(next = BufferNew(((BufferObject *)(r))->buf->b_next)))
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3259 return NULL;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3260 *buffer = next;
4438
20e30e31bd86 updated for version 7.3.967
Bram Moolenaar <bram@vim.org>
parents: 4435
diff changeset
3261 /* Do not increment reference: we no longer hold it (decref), but whoever
20e30e31bd86 updated for version 7.3.967
Bram Moolenaar <bram@vim.org>
parents: 4435
diff changeset
3262 * on other side will hold (incref). Decref+incref = nothing. */
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3263 return r;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3264 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3265
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3266 static PyObject *
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3267 BufMapIter(PyObject *self UNUSED)
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3268 {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3269 PyObject *buffer;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3270
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3271 buffer = BufferNew(firstbuf);
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3272 return IterNew(buffer,
4433
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3273 (destructorfun) BufMapIterDestruct, (nextfun) BufMapIterNext,
8a3ca4adb5d8 updated for version 7.3.965
Bram Moolenaar <bram@vim.org>
parents: 4431
diff changeset
3274 (traversefun) BufMapIterTraverse, (clearfun) BufMapIterClear);
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3275 }
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3276
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3277 static PyMappingMethods BufMapAsMapping = {
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3278 (lenfunc) BufMapLength,
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3279 (binaryfunc) BufMapItem,
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3280 (objobjargproc) 0,
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3281 };
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3282
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3283 /* Current items object
2447
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3284 */
84d353762845 Move many more common Python items to if_py_both.c.
Bram Moolenaar <bram@vim.org>
parents: 2399
diff changeset
3285
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3286 static PyObject *
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3287 CurrentGetattr(PyObject *self UNUSED, char *name)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3288 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3289 if (strcmp(name, "buffer") == 0)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3290 return (PyObject *)BufferNew(curbuf);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3291 else if (strcmp(name, "window") == 0)
4431
7d81f4e96728 updated for version 7.3.964
Bram Moolenaar <bram@vim.org>
parents: 4429
diff changeset
3292 return (PyObject *)WindowNew(curwin, curtab);
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3293 else if (strcmp(name, "tabpage") == 0)
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3294 return (PyObject *)TabPageNew(curtab);
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3295 else if (strcmp(name, "line") == 0)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3296 return GetBufferLine(curbuf, (PyInt)curwin->w_cursor.lnum);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3297 else if (strcmp(name, "range") == 0)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3298 return RangeNew(curbuf, RangeStart, RangeEnd);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3299 else if (strcmp(name,"__members__") == 0)
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3300 return Py_BuildValue("[sssss]", "buffer", "window", "line", "range",
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
3301 "tabpage");
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3302 else
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3303 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3304 PyErr_SetString(PyExc_AttributeError, name);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3305 return NULL;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3306 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3307 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3308
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3309 static int
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3310 CurrentSetattr(PyObject *self UNUSED, char *name, PyObject *value)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3311 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3312 if (strcmp(name, "line") == 0)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3313 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3314 if (SetBufferLine(curbuf, (PyInt)curwin->w_cursor.lnum, value, NULL) == FAIL)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3315 return -1;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3316
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3317 return 0;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3318 }
4407
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3319 else if (strcmp(name, "buffer") == 0)
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3320 {
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3321 int count;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3322
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3323 if (value->ob_type != &BufferType)
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3324 {
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3325 PyErr_SetString(PyExc_TypeError, _("expected vim.buffer object"));
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3326 return -1;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3327 }
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3328
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3329 if (CheckBuffer((BufferObject *)(value)))
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3330 return -1;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3331 count = ((BufferObject *)(value))->buf->b_fnum;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3332
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3333 if (do_buffer(DOBUF_GOTO, DOBUF_FIRST, FORWARD, count, 0) == FAIL)
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3334 {
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3335 PyErr_SetVim(_("failed to switch to given buffer"));
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3336 return -1;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3337 }
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3338
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3339 return 0;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3340 }
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3341 else if (strcmp(name, "window") == 0)
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3342 {
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3343 int count;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3344
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3345 if (value->ob_type != &WindowType)
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3346 {
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3347 PyErr_SetString(PyExc_TypeError, _("expected vim.window object"));
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3348 return -1;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3349 }
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3350
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3351 if (CheckWindow((WindowObject *)(value)))
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3352 return -1;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3353 count = get_win_number(((WindowObject *)(value))->win, firstwin);
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3354
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3355 if (!count)
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3356 {
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3357 PyErr_SetString(PyExc_ValueError,
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3358 _("failed to find window in the current tab page"));
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3359 return -1;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3360 }
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3361
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3362 win_goto(((WindowObject *)(value))->win);
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3363 if (((WindowObject *)(value))->win != curwin)
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3364 {
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3365 PyErr_SetString(PyExc_RuntimeError,
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3366 _("did not switch to the specified window"));
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3367 return -1;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3368 }
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3369
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3370 return 0;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3371 }
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3372 else if (strcmp(name, "tabpage") == 0)
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3373 {
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3374 if (value->ob_type != &TabPageType)
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3375 {
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3376 PyErr_SetString(PyExc_TypeError, _("expected vim.tabpage object"));
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3377 return -1;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3378 }
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3379
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3380 if (CheckTabPage((TabPageObject *)(value)))
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3381 return -1;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3382
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3383 goto_tabpage_tp(((TabPageObject *)(value))->tab, TRUE, TRUE);
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3384 if (((TabPageObject *)(value))->tab != curtab)
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3385 {
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3386 PyErr_SetString(PyExc_RuntimeError,
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3387 _("did not switch to the specified tab page"));
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3388 return -1;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3389 }
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3390
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3391 return 0;
2a166caf8709 updated for version 7.3.952
Bram Moolenaar <bram@vim.org>
parents: 4405
diff changeset
3392 }
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3393 else
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3394 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3395 PyErr_SetString(PyExc_AttributeError, name);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3396 return -1;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3397 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3398 }
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3399
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3400 static void
4486
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3401 init_range_cmd(exarg_T *eap)
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3402 {
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3403 RangeStart = eap->line1;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3404 RangeEnd = eap->line2;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3405 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3406
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3407 static void
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3408 init_range_eval(typval_T *rettv UNUSED)
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3409 {
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3410 RangeStart = (PyInt) curwin->w_cursor.lnum;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3411 RangeEnd = RangeStart;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3412 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3413
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3414 static void
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3415 run_cmd(const char *cmd, void *arg UNUSED, PyGILState_STATE *pygilstate UNUSED)
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3416 {
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3417 PyRun_SimpleString((char *) cmd);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3418 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3419
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3420 static const char *code_hdr = "def " DOPY_FUNC "(line, linenr):\n ";
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3421 static int code_hdr_len = 30;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3422
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3423 static void
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3424 run_do(const char *cmd, void *arg UNUSED, PyGILState_STATE *pygilstate)
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3425 {
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3426 PyInt lnum;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3427 size_t len;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3428 char *code;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3429 int status;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3430 PyObject *pyfunc, *pymain;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3431
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3432 if (u_save(RangeStart - 1, RangeEnd + 1) != OK)
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3433 {
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3434 EMSG(_("cannot save undo information"));
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3435 return;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3436 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3437
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3438 len = code_hdr_len + STRLEN(cmd);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3439 code = PyMem_New(char, len + 1);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3440 memcpy(code, code_hdr, code_hdr_len);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3441 STRCPY(code + code_hdr_len, cmd);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3442 status = PyRun_SimpleString(code);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3443 PyMem_Free(code);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3444
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3445 if (status)
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3446 {
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3447 EMSG(_("failed to run the code"));
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3448 return;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3449 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3450
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3451 status = 0;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3452 pymain = PyImport_AddModule("__main__");
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3453 pyfunc = PyObject_GetAttrString(pymain, DOPY_FUNC);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3454 PyGILState_Release(*pygilstate);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3455
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3456 for (lnum = RangeStart; lnum <= RangeEnd; ++lnum)
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3457 {
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3458 PyObject *line, *linenr, *ret;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3459
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3460 *pygilstate = PyGILState_Ensure();
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3461 if (!(line = GetBufferLine(curbuf, lnum)))
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3462 goto err;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3463 if (!(linenr = PyInt_FromLong((long) lnum)))
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3464 {
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3465 Py_DECREF(line);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3466 goto err;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3467 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3468 ret = PyObject_CallFunctionObjArgs(pyfunc, line, linenr, NULL);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3469 Py_DECREF(line);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3470 Py_DECREF(linenr);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3471 if (!ret)
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3472 goto err;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3473
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3474 if (ret != Py_None)
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3475 if (SetBufferLine(curbuf, lnum, ret, NULL) == FAIL)
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3476 goto err;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3477
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3478 Py_XDECREF(ret);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3479 PythonIO_Flush();
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3480 PyGILState_Release(*pygilstate);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3481 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3482 goto out;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3483 err:
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3484 *pygilstate = PyGILState_Ensure();
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3485 PyErr_PrintEx(0);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3486 PythonIO_Flush();
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3487 status = 1;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3488 out:
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3489 if (!status)
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3490 *pygilstate = PyGILState_Ensure();
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3491 Py_DECREF(pyfunc);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3492 PyObject_SetAttrString(pymain, DOPY_FUNC, NULL);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3493 if (status)
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3494 return;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3495 check_cursor();
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3496 update_curbuf(NOT_VALID);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3497 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3498
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3499 static void
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3500 run_eval(const char *cmd, typval_T *rettv, PyGILState_STATE *pygilstate UNUSED)
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3501 {
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3502 PyObject *r;
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3503
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3504 r = PyRun_String((char *) cmd, Py_eval_input, globals, globals);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3505 if (r == NULL)
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3506 {
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3507 if (PyErr_Occurred() && !msg_silent)
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3508 PyErr_PrintEx(0);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3509 EMSG(_("E858: Eval did not return a valid python object"));
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3510 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3511 else
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3512 {
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3513 if (ConvertFromPyObject(r, rettv) == -1)
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3514 EMSG(_("E859: Failed to convert returned python object to vim value"));
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3515 Py_DECREF(r);
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3516 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3517 PyErr_Clear();
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3518 }
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3519
8fe768bc1234 updated for version 7.3.991
Bram Moolenaar <bram@vim.org>
parents: 4438
diff changeset
3520 static void
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3521 set_ref_in_py(const int copyID)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3522 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3523 pylinkedlist_T *cur;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3524 dict_T *dd;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3525 list_T *ll;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3526
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3527 if (lastdict != NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3528 for(cur = lastdict ; cur != NULL ; cur = cur->pll_prev)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3529 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3530 dd = ((DictionaryObject *) (cur->pll_obj))->dict;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3531 if (dd->dv_copyID != copyID)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3532 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3533 dd->dv_copyID = copyID;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3534 set_ref_in_ht(&dd->dv_hashtab, copyID);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3535 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3536 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3537
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3538 if (lastlist != NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3539 for(cur = lastlist ; cur != NULL ; cur = cur->pll_prev)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3540 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3541 ll = ((ListObject *) (cur->pll_obj))->list;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3542 if (ll->lv_copyID != copyID)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3543 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3544 ll->lv_copyID = copyID;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3545 set_ref_in_list(ll, copyID);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3546 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3547 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3548 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3549
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3550 static int
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3551 set_string_copy(char_u *str, typval_T *tv)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3552 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3553 tv->vval.v_string = vim_strsave(str);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3554 if (tv->vval.v_string == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3555 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3556 PyErr_NoMemory();
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3557 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3558 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3559 return 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3560 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3561
4385
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3562 static int
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3563 pydict_to_tv(PyObject *obj, typval_T *tv, PyObject *lookupDict)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3564 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3565 dict_T *d;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3566 char_u *key;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3567 dictitem_T *di;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3568 PyObject *keyObject;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3569 PyObject *valObject;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3570 Py_ssize_t iter = 0;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3571
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3572 d = dict_alloc();
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3573 if (d == NULL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3574 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3575 PyErr_NoMemory();
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3576 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3577 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3578
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3579 tv->v_type = VAR_DICT;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3580 tv->vval.v_dict = d;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3581
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3582 while (PyDict_Next(obj, &iter, &keyObject, &valObject))
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3583 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3584 DICTKEY_DECL
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3585
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3586 if (keyObject == NULL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3587 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3588 if (valObject == NULL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3589 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3590
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3591 DICTKEY_GET_NOTEMPTY(-1)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3592
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3593 di = dictitem_alloc(key);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3594
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3595 DICTKEY_UNREF
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3596
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3597 if (di == NULL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3598 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3599 PyErr_NoMemory();
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3600 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3601 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3602 di->di_tv.v_lock = 0;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3603
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3604 if (_ConvertFromPyObject(valObject, &di->di_tv, lookupDict) == -1)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3605 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3606 vim_free(di);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3607 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3608 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3609 if (dict_add(d, di) == FAIL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3610 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3611 vim_free(di);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3612 PyErr_SetVim(_("failed to add key to dictionary"));
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3613 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3614 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3615 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3616 return 0;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3617 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3618
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3619 static int
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3620 pymap_to_tv(PyObject *obj, typval_T *tv, PyObject *lookupDict)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3621 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3622 dict_T *d;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3623 char_u *key;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3624 dictitem_T *di;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3625 PyObject *list;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3626 PyObject *litem;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3627 PyObject *keyObject;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3628 PyObject *valObject;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3629 Py_ssize_t lsize;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3630
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3631 d = dict_alloc();
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3632 if (d == NULL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3633 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3634 PyErr_NoMemory();
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3635 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3636 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3637
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3638 tv->v_type = VAR_DICT;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3639 tv->vval.v_dict = d;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3640
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3641 list = PyMapping_Items(obj);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3642 if (list == NULL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3643 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3644 lsize = PyList_Size(list);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3645 while (lsize--)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3646 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3647 DICTKEY_DECL
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3648
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3649 litem = PyList_GetItem(list, lsize);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3650 if (litem == NULL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3651 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3652 Py_DECREF(list);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3653 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3654 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3655
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3656 keyObject = PyTuple_GetItem(litem, 0);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3657 if (keyObject == NULL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3658 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3659 Py_DECREF(list);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3660 Py_DECREF(litem);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3661 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3662 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3663
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3664 DICTKEY_GET_NOTEMPTY(-1)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3665
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3666 valObject = PyTuple_GetItem(litem, 1);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3667 if (valObject == NULL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3668 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3669 Py_DECREF(list);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3670 Py_DECREF(litem);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3671 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3672 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3673
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3674 di = dictitem_alloc(key);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3675
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3676 DICTKEY_UNREF
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3677
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3678 if (di == NULL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3679 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3680 Py_DECREF(list);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3681 Py_DECREF(litem);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3682 PyErr_NoMemory();
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3683 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3684 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3685 di->di_tv.v_lock = 0;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3686
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3687 if (_ConvertFromPyObject(valObject, &di->di_tv, lookupDict) == -1)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3688 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3689 vim_free(di);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3690 Py_DECREF(list);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3691 Py_DECREF(litem);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3692 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3693 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3694 if (dict_add(d, di) == FAIL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3695 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3696 vim_free(di);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3697 Py_DECREF(list);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3698 Py_DECREF(litem);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3699 PyErr_SetVim(_("failed to add key to dictionary"));
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3700 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3701 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3702 Py_DECREF(litem);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3703 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3704 Py_DECREF(list);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3705 return 0;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3706 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3707
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3708 static int
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3709 pyseq_to_tv(PyObject *obj, typval_T *tv, PyObject *lookupDict)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3710 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3711 list_T *l;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3712
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3713 l = list_alloc();
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3714 if (l == NULL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3715 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3716 PyErr_NoMemory();
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3717 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3718 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3719
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3720 tv->v_type = VAR_LIST;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3721 tv->vval.v_list = l;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3722
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3723 if (list_py_concat(l, obj, lookupDict) == -1)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3724 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3725
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3726 return 0;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3727 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3728
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3729 static int
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3730 pyiter_to_tv(PyObject *obj, typval_T *tv, PyObject *lookupDict)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3731 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3732 PyObject *iterator = PyObject_GetIter(obj);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3733 PyObject *item;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3734 list_T *l;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3735 listitem_T *li;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3736
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3737 l = list_alloc();
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3738
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3739 if (l == NULL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3740 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3741 PyErr_NoMemory();
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3742 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3743 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3744
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3745 tv->vval.v_list = l;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3746 tv->v_type = VAR_LIST;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3747
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3748
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3749 if (iterator == NULL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3750 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3751
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3752 while ((item = PyIter_Next(obj)))
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3753 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3754 li = listitem_alloc();
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3755 if (li == NULL)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3756 {
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3757 PyErr_NoMemory();
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3758 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3759 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3760 li->li_tv.v_lock = 0;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3761
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3762 if (_ConvertFromPyObject(item, &li->li_tv, lookupDict) == -1)
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3763 return -1;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3764
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3765 list_append(l, li);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3766
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3767 Py_DECREF(item);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3768 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3769
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3770 Py_DECREF(iterator);
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3771 return 0;
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3772 }
da71e66dc1d4 updated for version 7.3.941
Bram Moolenaar <bram@vim.org>
parents: 4383
diff changeset
3773
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3774 typedef int (*pytotvfunc)(PyObject *, typval_T *, PyObject *);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3775
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3776 static int
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3777 convert_dl(PyObject *obj, typval_T *tv,
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3778 pytotvfunc py_to_tv, PyObject *lookupDict)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3779 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3780 PyObject *capsule;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3781 char hexBuf[sizeof(void *) * 2 + 3];
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3782
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3783 sprintf(hexBuf, "%p", obj);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3784
3638
80ed6aa7b9eb updated for version 7.3.579
Bram Moolenaar <bram@vim.org>
parents: 3636
diff changeset
3785 # ifdef PY_USE_CAPSULE
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3786 capsule = PyDict_GetItemString(lookupDict, hexBuf);
3648
2d107086903a updated for version 7.3.584
Bram Moolenaar <bram@vim.org>
parents: 3640
diff changeset
3787 # else
2d107086903a updated for version 7.3.584
Bram Moolenaar <bram@vim.org>
parents: 3640
diff changeset
3788 capsule = (PyObject *)PyDict_GetItemString(lookupDict, hexBuf);
2d107086903a updated for version 7.3.584
Bram Moolenaar <bram@vim.org>
parents: 3640
diff changeset
3789 # endif
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3790 if (capsule == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3791 {
3638
80ed6aa7b9eb updated for version 7.3.579
Bram Moolenaar <bram@vim.org>
parents: 3636
diff changeset
3792 # ifdef PY_USE_CAPSULE
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3793 capsule = PyCapsule_New(tv, NULL, NULL);
3648
2d107086903a updated for version 7.3.584
Bram Moolenaar <bram@vim.org>
parents: 3640
diff changeset
3794 # else
2d107086903a updated for version 7.3.584
Bram Moolenaar <bram@vim.org>
parents: 3640
diff changeset
3795 capsule = PyCObject_FromVoidPtr(tv, NULL);
2d107086903a updated for version 7.3.584
Bram Moolenaar <bram@vim.org>
parents: 3640
diff changeset
3796 # endif
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3797 PyDict_SetItemString(lookupDict, hexBuf, capsule);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3798 Py_DECREF(capsule);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3799 if (py_to_tv(obj, tv, lookupDict) == -1)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3800 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3801 tv->v_type = VAR_UNKNOWN;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3802 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3803 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3804 /* As we are not using copy_tv which increments reference count we must
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3805 * do it ourself. */
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3806 switch(tv->v_type)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3807 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3808 case VAR_DICT: ++tv->vval.v_dict->dv_refcount; break;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3809 case VAR_LIST: ++tv->vval.v_list->lv_refcount; break;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3810 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3811 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3812 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3813 {
3638
80ed6aa7b9eb updated for version 7.3.579
Bram Moolenaar <bram@vim.org>
parents: 3636
diff changeset
3814 typval_T *v;
80ed6aa7b9eb updated for version 7.3.579
Bram Moolenaar <bram@vim.org>
parents: 3636
diff changeset
3815
80ed6aa7b9eb updated for version 7.3.579
Bram Moolenaar <bram@vim.org>
parents: 3636
diff changeset
3816 # ifdef PY_USE_CAPSULE
80ed6aa7b9eb updated for version 7.3.579
Bram Moolenaar <bram@vim.org>
parents: 3636
diff changeset
3817 v = PyCapsule_GetPointer(capsule, NULL);
80ed6aa7b9eb updated for version 7.3.579
Bram Moolenaar <bram@vim.org>
parents: 3636
diff changeset
3818 # else
3648
2d107086903a updated for version 7.3.584
Bram Moolenaar <bram@vim.org>
parents: 3640
diff changeset
3819 v = PyCObject_AsVoidPtr(capsule);
3638
80ed6aa7b9eb updated for version 7.3.579
Bram Moolenaar <bram@vim.org>
parents: 3636
diff changeset
3820 # endif
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3821 copy_tv(v, tv);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3822 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3823 return 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3824 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3825
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3826 static int
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3827 ConvertFromPyObject(PyObject *obj, typval_T *tv)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3828 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3829 PyObject *lookup_dict;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3830 int r;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3831
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3832 lookup_dict = PyDict_New();
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3833 r = _ConvertFromPyObject(obj, tv, lookup_dict);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3834 Py_DECREF(lookup_dict);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3835 return r;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3836 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3837
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3838 static int
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3839 _ConvertFromPyObject(PyObject *obj, typval_T *tv, PyObject *lookupDict)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3840 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3841 if (obj->ob_type == &DictionaryType)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3842 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3843 tv->v_type = VAR_DICT;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3844 tv->vval.v_dict = (((DictionaryObject *)(obj))->dict);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3845 ++tv->vval.v_dict->dv_refcount;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3846 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3847 else if (obj->ob_type == &ListType)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3848 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3849 tv->v_type = VAR_LIST;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3850 tv->vval.v_list = (((ListObject *)(obj))->list);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3851 ++tv->vval.v_list->lv_refcount;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3852 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3853 else if (obj->ob_type == &FunctionType)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3854 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3855 if (set_string_copy(((FunctionObject *) (obj))->name, tv) == -1)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3856 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3857
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3858 tv->v_type = VAR_FUNC;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3859 func_ref(tv->vval.v_string);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3860 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3861 else if (PyBytes_Check(obj))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3862 {
3800
15cdcb8ddcfb updated for version 7.3.658
Bram Moolenaar <bram@vim.org>
parents: 3792
diff changeset
3863 char_u *result;
15cdcb8ddcfb updated for version 7.3.658
Bram Moolenaar <bram@vim.org>
parents: 3792
diff changeset
3864
15cdcb8ddcfb updated for version 7.3.658
Bram Moolenaar <bram@vim.org>
parents: 3792
diff changeset
3865 if (PyString_AsStringAndSize(obj, (char **) &result, NULL) == -1)
15cdcb8ddcfb updated for version 7.3.658
Bram Moolenaar <bram@vim.org>
parents: 3792
diff changeset
3866 return -1;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3867 if (result == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3868 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3869
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3870 if (set_string_copy(result, tv) == -1)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3871 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3872
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3873 tv->v_type = VAR_STRING;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3874 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3875 else if (PyUnicode_Check(obj))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3876 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3877 PyObject *bytes;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3878 char_u *result;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3879
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3880 bytes = PyUnicode_AsEncodedString(obj, (char *)ENC_OPT, NULL);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3881 if (bytes == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3882 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3883
3800
15cdcb8ddcfb updated for version 7.3.658
Bram Moolenaar <bram@vim.org>
parents: 3792
diff changeset
3884 if(PyString_AsStringAndSize(bytes, (char **) &result, NULL) == -1)
15cdcb8ddcfb updated for version 7.3.658
Bram Moolenaar <bram@vim.org>
parents: 3792
diff changeset
3885 return -1;
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3886 if (result == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3887 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3888
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3889 if (set_string_copy(result, tv) == -1)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3890 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3891 Py_XDECREF(bytes);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3892 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3893 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3894 Py_XDECREF(bytes);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3895
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3896 tv->v_type = VAR_STRING;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3897 }
4321
d8d9c591c50f updated for version 7.3.910
Bram Moolenaar <bram@vim.org>
parents: 4319
diff changeset
3898 #if PY_MAJOR_VERSION < 3
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3899 else if (PyInt_Check(obj))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3900 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3901 tv->v_type = VAR_NUMBER;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3902 tv->vval.v_number = (varnumber_T) PyInt_AsLong(obj);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3903 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3904 #endif
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3905 else if (PyLong_Check(obj))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3906 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3907 tv->v_type = VAR_NUMBER;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3908 tv->vval.v_number = (varnumber_T) PyLong_AsLong(obj);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3909 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3910 else if (PyDict_Check(obj))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3911 return convert_dl(obj, tv, pydict_to_tv, lookupDict);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3912 #ifdef FEAT_FLOAT
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3913 else if (PyFloat_Check(obj))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3914 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3915 tv->v_type = VAR_FLOAT;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3916 tv->vval.v_float = (float_T) PyFloat_AsDouble(obj);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3917 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3918 #endif
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3919 else if (PyIter_Check(obj))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3920 return convert_dl(obj, tv, pyiter_to_tv, lookupDict);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3921 else if (PySequence_Check(obj))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3922 return convert_dl(obj, tv, pyseq_to_tv, lookupDict);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3923 else if (PyMapping_Check(obj))
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3924 return convert_dl(obj, tv, pymap_to_tv, lookupDict);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3925 else
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3926 {
4405
907b1f035ee7 updated for version 7.3.951
Bram Moolenaar <bram@vim.org>
parents: 4403
diff changeset
3927 PyErr_SetString(PyExc_TypeError,
907b1f035ee7 updated for version 7.3.951
Bram Moolenaar <bram@vim.org>
parents: 4403
diff changeset
3928 _("unable to convert to vim structure"));
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3929 return -1;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3930 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3931 return 0;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3932 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3933
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3934 static PyObject *
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3935 ConvertToPyObject(typval_T *tv)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3936 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3937 if (tv == NULL)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3938 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3939 PyErr_SetVim(_("NULL reference passed"));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3940 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3941 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3942 switch (tv->v_type)
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3943 {
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3944 case VAR_STRING:
3852
0f5ee2629635 updated for version 7.3.683
Bram Moolenaar <bram@vim.org>
parents: 3828
diff changeset
3945 return PyBytes_FromString(tv->vval.v_string == NULL
0f5ee2629635 updated for version 7.3.683
Bram Moolenaar <bram@vim.org>
parents: 3828
diff changeset
3946 ? "" : (char *)tv->vval.v_string);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3947 case VAR_NUMBER:
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3948 return PyLong_FromLong((long) tv->vval.v_number);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3949 #ifdef FEAT_FLOAT
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3950 case VAR_FLOAT:
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3951 return PyFloat_FromDouble((double) tv->vval.v_float);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3952 #endif
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3953 case VAR_LIST:
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3954 return ListNew(tv->vval.v_list);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3955 case VAR_DICT:
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3956 return DictionaryNew(tv->vval.v_dict);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3957 case VAR_FUNC:
3852
0f5ee2629635 updated for version 7.3.683
Bram Moolenaar <bram@vim.org>
parents: 3828
diff changeset
3958 return FunctionNew(tv->vval.v_string == NULL
0f5ee2629635 updated for version 7.3.683
Bram Moolenaar <bram@vim.org>
parents: 3828
diff changeset
3959 ? (char_u *)"" : tv->vval.v_string);
3618
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3960 case VAR_UNKNOWN:
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3961 Py_INCREF(Py_None);
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3962 return Py_None;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3963 default:
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3964 PyErr_SetVim(_("internal error: invalid value type"));
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3965 return NULL;
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3966 }
c052f3b79b99 updated for version 7.3.569
Bram Moolenaar <bram@vim.org>
parents: 3466
diff changeset
3967 }
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3968
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3969 typedef struct
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3970 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3971 PyObject_HEAD
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3972 } CurrentObject;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3973 static PyTypeObject CurrentType;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3974
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3975 static void
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3976 init_structs(void)
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3977 {
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3978 vim_memset(&OutputType, 0, sizeof(OutputType));
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3979 OutputType.tp_name = "vim.message";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3980 OutputType.tp_basicsize = sizeof(OutputObject);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3981 OutputType.tp_flags = Py_TPFLAGS_DEFAULT;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3982 OutputType.tp_doc = "vim message object";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3983 OutputType.tp_methods = OutputMethods;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3984 #if PY_MAJOR_VERSION >= 3
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3985 OutputType.tp_getattro = (getattrofunc)OutputGetattro;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3986 OutputType.tp_setattro = (setattrofunc)OutputSetattro;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3987 OutputType.tp_alloc = call_PyType_GenericAlloc;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3988 OutputType.tp_new = call_PyType_GenericNew;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3989 OutputType.tp_free = call_PyObject_Free;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3990 #else
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3991 OutputType.tp_getattr = (getattrfunc)OutputGetattr;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
3992 OutputType.tp_setattr = (setattrfunc)OutputSetattr;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3993 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
3994
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3995 vim_memset(&IterType, 0, sizeof(IterType));
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3996 IterType.tp_name = "vim.iter";
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3997 IterType.tp_basicsize = sizeof(IterObject);
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3998 IterType.tp_flags = Py_TPFLAGS_DEFAULT;
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
3999 IterType.tp_doc = "generic iterator object";
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4000 IterType.tp_iter = (getiterfunc)IterIter;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4001 IterType.tp_iternext = (iternextfunc)IterNext;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4002 IterType.tp_dealloc = (destructor)IterDestructor;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4003 IterType.tp_traverse = (traverseproc)IterTraverse;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4004 IterType.tp_clear = (inquiry)IterClear;
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
4005
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4006 vim_memset(&BufferType, 0, sizeof(BufferType));
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4007 BufferType.tp_name = "vim.buffer";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4008 BufferType.tp_basicsize = sizeof(BufferType);
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4009 BufferType.tp_dealloc = (destructor)BufferDestructor;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4010 BufferType.tp_repr = (reprfunc)BufferRepr;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4011 BufferType.tp_as_sequence = &BufferAsSeq;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4012 BufferType.tp_as_mapping = &BufferAsMapping;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4013 BufferType.tp_flags = Py_TPFLAGS_DEFAULT;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4014 BufferType.tp_doc = "vim buffer object";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4015 BufferType.tp_methods = BufferMethods;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4016 #if PY_MAJOR_VERSION >= 3
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4017 BufferType.tp_getattro = (getattrofunc)BufferGetattro;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4018 BufferType.tp_alloc = call_PyType_GenericAlloc;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4019 BufferType.tp_new = call_PyType_GenericNew;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4020 BufferType.tp_free = call_PyObject_Free;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4021 #else
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4022 BufferType.tp_getattr = (getattrfunc)BufferGetattr;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4023 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4024
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4025 vim_memset(&WindowType, 0, sizeof(WindowType));
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4026 WindowType.tp_name = "vim.window";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4027 WindowType.tp_basicsize = sizeof(WindowObject);
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4028 WindowType.tp_dealloc = (destructor)WindowDestructor;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4029 WindowType.tp_repr = (reprfunc)WindowRepr;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4030 WindowType.tp_flags = Py_TPFLAGS_DEFAULT;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4031 WindowType.tp_doc = "vim Window object";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4032 WindowType.tp_methods = WindowMethods;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4033 WindowType.tp_traverse = (traverseproc)WindowTraverse;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4034 WindowType.tp_clear = (inquiry)WindowClear;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4035 #if PY_MAJOR_VERSION >= 3
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4036 WindowType.tp_getattro = (getattrofunc)WindowGetattro;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4037 WindowType.tp_setattro = (setattrofunc)WindowSetattro;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4038 WindowType.tp_alloc = call_PyType_GenericAlloc;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4039 WindowType.tp_new = call_PyType_GenericNew;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4040 WindowType.tp_free = call_PyObject_Free;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4041 #else
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4042 WindowType.tp_getattr = (getattrfunc)WindowGetattr;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4043 WindowType.tp_setattr = (setattrfunc)WindowSetattr;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4044 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4045
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4046 vim_memset(&TabPageType, 0, sizeof(TabPageType));
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4047 TabPageType.tp_name = "vim.tabpage";
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4048 TabPageType.tp_basicsize = sizeof(TabPageObject);
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4049 TabPageType.tp_dealloc = (destructor)TabPageDestructor;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4050 TabPageType.tp_repr = (reprfunc)TabPageRepr;
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4051 TabPageType.tp_flags = Py_TPFLAGS_DEFAULT;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4052 TabPageType.tp_doc = "vim tab page object";
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4053 TabPageType.tp_methods = TabPageMethods;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4054 #if PY_MAJOR_VERSION >= 3
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4055 TabPageType.tp_getattro = (getattrofunc)TabPageGetattro;
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4056 TabPageType.tp_alloc = call_PyType_GenericAlloc;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4057 TabPageType.tp_new = call_PyType_GenericNew;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4058 TabPageType.tp_free = call_PyObject_Free;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4059 #else
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4060 TabPageType.tp_getattr = (getattrfunc)TabPageGetattr;
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4061 #endif
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4062
4393
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
4063 vim_memset(&BufMapType, 0, sizeof(BufMapType));
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
4064 BufMapType.tp_name = "vim.bufferlist";
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
4065 BufMapType.tp_basicsize = sizeof(BufMapObject);
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
4066 BufMapType.tp_as_mapping = &BufMapAsMapping;
80eea7a9d6b9 updated for version 7.3.945
Bram Moolenaar <bram@vim.org>
parents: 4389
diff changeset
4067 BufMapType.tp_flags = Py_TPFLAGS_DEFAULT;
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
4068 BufMapType.tp_iter = BufMapIter;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4069 BufferType.tp_doc = "vim buffer list";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4070
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4071 vim_memset(&WinListType, 0, sizeof(WinListType));
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4072 WinListType.tp_name = "vim.windowlist";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4073 WinListType.tp_basicsize = sizeof(WinListType);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4074 WinListType.tp_as_sequence = &WinListAsSeq;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4075 WinListType.tp_flags = Py_TPFLAGS_DEFAULT;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4076 WinListType.tp_doc = "vim window list";
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4077 WinListType.tp_dealloc = (destructor)WinListDestructor;
4401
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4078
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4079 vim_memset(&TabListType, 0, sizeof(TabListType));
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4080 TabListType.tp_name = "vim.tabpagelist";
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4081 TabListType.tp_basicsize = sizeof(TabListType);
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4082 TabListType.tp_as_sequence = &TabListAsSeq;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4083 TabListType.tp_flags = Py_TPFLAGS_DEFAULT;
cfd76908da25 updated for version 7.3.949
Bram Moolenaar <bram@vim.org>
parents: 4399
diff changeset
4084 TabListType.tp_doc = "vim tab page list";
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4085
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4086 vim_memset(&RangeType, 0, sizeof(RangeType));
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4087 RangeType.tp_name = "vim.range";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4088 RangeType.tp_basicsize = sizeof(RangeObject);
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4089 RangeType.tp_dealloc = (destructor)RangeDestructor;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4090 RangeType.tp_repr = (reprfunc)RangeRepr;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4091 RangeType.tp_as_sequence = &RangeAsSeq;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4092 RangeType.tp_as_mapping = &RangeAsMapping;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4093 RangeType.tp_flags = Py_TPFLAGS_DEFAULT;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4094 RangeType.tp_doc = "vim Range object";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4095 RangeType.tp_methods = RangeMethods;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4096 #if PY_MAJOR_VERSION >= 3
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4097 RangeType.tp_getattro = (getattrofunc)RangeGetattro;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4098 RangeType.tp_alloc = call_PyType_GenericAlloc;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4099 RangeType.tp_new = call_PyType_GenericNew;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4100 RangeType.tp_free = call_PyObject_Free;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4101 #else
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4102 RangeType.tp_getattr = (getattrfunc)RangeGetattr;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4103 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4104
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4105 vim_memset(&CurrentType, 0, sizeof(CurrentType));
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4106 CurrentType.tp_name = "vim.currentdata";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4107 CurrentType.tp_basicsize = sizeof(CurrentObject);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4108 CurrentType.tp_flags = Py_TPFLAGS_DEFAULT;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4109 CurrentType.tp_doc = "vim current object";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4110 #if PY_MAJOR_VERSION >= 3
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4111 CurrentType.tp_getattro = (getattrofunc)CurrentGetattro;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4112 CurrentType.tp_setattro = (setattrofunc)CurrentSetattro;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4113 #else
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4114 CurrentType.tp_getattr = (getattrfunc)CurrentGetattr;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4115 CurrentType.tp_setattr = (setattrfunc)CurrentSetattr;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4116 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4117
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4118 vim_memset(&DictionaryType, 0, sizeof(DictionaryType));
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4119 DictionaryType.tp_name = "vim.dictionary";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4120 DictionaryType.tp_basicsize = sizeof(DictionaryObject);
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4121 DictionaryType.tp_dealloc = (destructor)DictionaryDestructor;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4122 DictionaryType.tp_as_mapping = &DictionaryAsMapping;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4123 DictionaryType.tp_flags = Py_TPFLAGS_DEFAULT;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4124 DictionaryType.tp_doc = "dictionary pushing modifications to vim structure";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4125 DictionaryType.tp_methods = DictionaryMethods;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4126 #if PY_MAJOR_VERSION >= 3
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4127 DictionaryType.tp_getattro = (getattrofunc)DictionaryGetattro;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4128 DictionaryType.tp_setattro = (setattrofunc)DictionarySetattro;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4129 #else
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4130 DictionaryType.tp_getattr = (getattrfunc)DictionaryGetattr;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4131 DictionaryType.tp_setattr = (setattrfunc)DictionarySetattr;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4132 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4133
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4134 vim_memset(&ListType, 0, sizeof(ListType));
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4135 ListType.tp_name = "vim.list";
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4136 ListType.tp_dealloc = (destructor)ListDestructor;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4137 ListType.tp_basicsize = sizeof(ListObject);
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4138 ListType.tp_as_sequence = &ListAsSeq;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4139 ListType.tp_as_mapping = &ListAsMapping;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4140 ListType.tp_flags = Py_TPFLAGS_DEFAULT;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4141 ListType.tp_doc = "list pushing modifications to vim structure";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4142 ListType.tp_methods = ListMethods;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4143 ListType.tp_iter = (getiterfunc)ListIter;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4144 #if PY_MAJOR_VERSION >= 3
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4145 ListType.tp_getattro = (getattrofunc)ListGetattro;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4146 ListType.tp_setattro = (setattrofunc)ListSetattro;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4147 #else
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4148 ListType.tp_getattr = (getattrfunc)ListGetattr;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4149 ListType.tp_setattr = (setattrfunc)ListSetattr;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4150 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4151
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4152 vim_memset(&FunctionType, 0, sizeof(FunctionType));
4397
a84f21892563 updated for version 7.3.947
Bram Moolenaar <bram@vim.org>
parents: 4393
diff changeset
4153 FunctionType.tp_name = "vim.function";
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4154 FunctionType.tp_basicsize = sizeof(FunctionObject);
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4155 FunctionType.tp_dealloc = (destructor)FunctionDestructor;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4156 FunctionType.tp_call = (ternaryfunc)FunctionCall;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4157 FunctionType.tp_flags = Py_TPFLAGS_DEFAULT;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4158 FunctionType.tp_doc = "object that calls vim function";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4159 FunctionType.tp_methods = FunctionMethods;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4160 #if PY_MAJOR_VERSION >= 3
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4161 FunctionType.tp_getattro = (getattrofunc)FunctionGetattro;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4162 #else
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4163 FunctionType.tp_getattr = (getattrfunc)FunctionGetattr;
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4164 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4165
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
4166 vim_memset(&OptionsType, 0, sizeof(OptionsType));
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
4167 OptionsType.tp_name = "vim.options";
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
4168 OptionsType.tp_basicsize = sizeof(OptionsObject);
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
4169 OptionsType.tp_flags = Py_TPFLAGS_DEFAULT;
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
4170 OptionsType.tp_doc = "object for manipulating options";
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
4171 OptionsType.tp_as_mapping = &OptionsAsMapping;
4488
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4172 OptionsType.tp_dealloc = (destructor)OptionsDestructor;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4173 OptionsType.tp_traverse = (traverseproc)OptionsTraverse;
89ea7593fc0c updated for version 7.3.992
Bram Moolenaar <bram@vim.org>
parents: 4486
diff changeset
4174 OptionsType.tp_clear = (inquiry)OptionsClear;
4350
7eaccdaa5304 updated for version 7.3.924
Bram Moolenaar <bram@vim.org>
parents: 4323
diff changeset
4175
4319
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4176 #if PY_MAJOR_VERSION >= 3
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4177 vim_memset(&vimmodule, 0, sizeof(vimmodule));
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4178 vimmodule.m_name = "vim";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4179 vimmodule.m_doc = "Vim Python interface\n";
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4180 vimmodule.m_size = -1;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4181 vimmodule.m_methods = VimMethods;
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4182 #endif
b79f3c3a584c updated for version 7.3.909
Bram Moolenaar <bram@vim.org>
parents: 4317
diff changeset
4183 }
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4184
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4185 #define PYTYPE_READY(type) \
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4186 if (PyType_Ready(&type)) \
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4187 return -1;
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4188
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4189 static int
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4190 init_types()
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4191 {
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4192 PYTYPE_READY(IterType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4193 PYTYPE_READY(BufferType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4194 PYTYPE_READY(RangeType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4195 PYTYPE_READY(WindowType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4196 PYTYPE_READY(TabPageType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4197 PYTYPE_READY(BufMapType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4198 PYTYPE_READY(WinListType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4199 PYTYPE_READY(TabListType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4200 PYTYPE_READY(CurrentType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4201 PYTYPE_READY(DictionaryType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4202 PYTYPE_READY(ListType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4203 PYTYPE_READY(FunctionType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4204 PYTYPE_READY(OptionsType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4205 PYTYPE_READY(OutputType);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4206 return 0;
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4207 }
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4208
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4209 static BufMapObject TheBufferMap =
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4210 {
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4211 PyObject_HEAD_INIT(&BufMapType)
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4212 };
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4213
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4214 static WinListObject TheWindowList =
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4215 {
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4216 PyObject_HEAD_INIT(&WinListType)
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4217 NULL
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4218 };
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4219
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4220 static CurrentObject TheCurrent =
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4221 {
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4222 PyObject_HEAD_INIT(&CurrentType)
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4223 };
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4224
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4225 static TabListObject TheTabPageList =
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4226 {
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4227 PyObject_HEAD_INIT(&TabListType)
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4228 };
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4229
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4230 static struct numeric_constant {
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4231 char *name;
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4232 int value;
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4233 } numeric_constants[] = {
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4234 {"VAR_LOCKED", VAR_LOCKED},
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4235 {"VAR_FIXED", VAR_FIXED},
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4236 {"VAR_SCOPE", VAR_SCOPE},
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4237 {"VAR_DEF_SCOPE", VAR_DEF_SCOPE},
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4238 };
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4239
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4240 static struct object_constant {
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4241 char *name;
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4242 PyObject *value;
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4243 } object_constants[] = {
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4244 {"buffers", (PyObject *)(void *)&TheBufferMap},
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4245 {"windows", (PyObject *)(void *)&TheWindowList},
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4246 {"tabpages", (PyObject *)(void *)&TheTabPageList},
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4247 {"current", (PyObject *)(void *)&TheCurrent},
4496
ebd94eabfd80 updated for version 7.3.996
Bram Moolenaar <bram@vim.org>
parents: 4494
diff changeset
4248
ebd94eabfd80 updated for version 7.3.996
Bram Moolenaar <bram@vim.org>
parents: 4494
diff changeset
4249 {"Buffer", (PyObject *)&BufferType},
ebd94eabfd80 updated for version 7.3.996
Bram Moolenaar <bram@vim.org>
parents: 4494
diff changeset
4250 {"Range", (PyObject *)&RangeType},
ebd94eabfd80 updated for version 7.3.996
Bram Moolenaar <bram@vim.org>
parents: 4494
diff changeset
4251 {"Window", (PyObject *)&WindowType},
ebd94eabfd80 updated for version 7.3.996
Bram Moolenaar <bram@vim.org>
parents: 4494
diff changeset
4252 {"TabPage", (PyObject *)&TabPageType},
ebd94eabfd80 updated for version 7.3.996
Bram Moolenaar <bram@vim.org>
parents: 4494
diff changeset
4253 {"Dictionary", (PyObject *)&DictionaryType},
ebd94eabfd80 updated for version 7.3.996
Bram Moolenaar <bram@vim.org>
parents: 4494
diff changeset
4254 {"List", (PyObject *)&ListType},
ebd94eabfd80 updated for version 7.3.996
Bram Moolenaar <bram@vim.org>
parents: 4494
diff changeset
4255 {"Function", (PyObject *)&FunctionType},
ebd94eabfd80 updated for version 7.3.996
Bram Moolenaar <bram@vim.org>
parents: 4494
diff changeset
4256 {"Options", (PyObject *)&OptionsType},
4494
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4257 };
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4258
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4259 typedef int (*object_adder)(PyObject *, const char *, PyObject *);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4260
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4261 #define ADD_OBJECT(m, name, obj) \
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4262 if (add_object(m, name, obj)) \
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4263 return -1;
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4264
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4265 #define ADD_CHECKED_OBJECT(m, name, obj) \
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4266 { \
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4267 PyObject *value = obj; \
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4268 if (!value) \
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4269 return -1; \
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4270 ADD_OBJECT(m, name, value); \
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4271 }
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4272
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4273 static int
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4274 populate_module(PyObject *m, object_adder add_object)
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4275 {
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4276 int i;
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4277
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4278 for (i = 0; i < (int)(sizeof(numeric_constants)
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4279 / sizeof(struct numeric_constant));
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4280 ++i)
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4281 ADD_CHECKED_OBJECT(m, numeric_constants[i].name,
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4282 PyInt_FromLong(numeric_constants[i].value));
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4283
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4284 for (i = 0; i < (int)(sizeof(object_constants)
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4285 / sizeof(struct object_constant));
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4286 ++i)
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4287 {
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4288 PyObject *value;
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4289
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4290 value = object_constants[i].value;
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4291 Py_INCREF(value);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4292 ADD_OBJECT(m, object_constants[i].name, value);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4293 }
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4294
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4295 if (!(VimError = PyErr_NewException("vim.error", NULL, NULL)))
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4296 return -1;
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4297 ADD_OBJECT(m, "error", VimError);
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4298
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4299 ADD_CHECKED_OBJECT(m, "vars", DictionaryNew(&globvardict));
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4300 ADD_CHECKED_OBJECT(m, "vvars", DictionaryNew(&vimvardict));
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4301 ADD_CHECKED_OBJECT(m, "options",
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4302 OptionsNew(SREQ_GLOBAL, NULL, dummy_check, NULL));
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4303 return 0;
6d517f6e5f0b updated for version 7.3.995
Bram Moolenaar <bram@vim.org>
parents: 4492
diff changeset
4304 }