Mercurial > vim
annotate src/if_ruby.c @ 2083:24eb7921b8f0 v7.2.367
updated for version 7.2.367
Problem: "xxd -r -p" doesn't work as documented.
Solution: Skip white space. (James Vega)
author | Bram Moolenaar <bram@zimbu.org> |
---|---|
date | Wed, 17 Feb 2010 18:28:41 +0100 |
parents | d8983769c9dd |
children | 4bac7ed34007 |
rev | line source |
---|---|
7 | 1 /* vi:set ts=8 sts=4 sw=4: |
2 * | |
3 * VIM - Vi IMproved by Bram Moolenaar | |
779 | 4 * |
5 * Ruby interface by Shugo Maeda | |
6 * with improvements by SegPhault (Ryan Paul) | |
7 | 7 * |
8 * Do ":help uganda" in Vim to read copying and usage conditions. | |
9 * Do ":help credits" in Vim to see a list of people who contributed. | |
10 * See README.txt for an overview of the Vim source code. | |
11 */ | |
12 | |
13 #include <stdio.h> | |
14 #include <string.h> | |
15 | |
16 #ifdef _WIN32 | |
17 # if !defined(DYNAMIC_RUBY_VER) || (DYNAMIC_RUBY_VER < 18) | |
18 # define NT | |
19 # endif | |
20 # ifndef DYNAMIC_RUBY | |
21 # define IMPORT /* For static dll usage __declspec(dllimport) */ | |
22 # define RUBYEXTERN __declspec(dllimport) | |
23 # endif | |
24 #endif | |
25 #ifndef RUBYEXTERN | |
26 # define RUBYEXTERN extern | |
27 #endif | |
28 | |
29 /* | |
30 * This is tricky. In ruby.h there is (inline) function rb_class_of() | |
31 * definition. This function use these variables. But we want function to | |
32 * use dll_* variables. | |
33 */ | |
34 #ifdef DYNAMIC_RUBY | |
35 # define rb_cFalseClass (*dll_rb_cFalseClass) | |
36 # define rb_cFixnum (*dll_rb_cFixnum) | |
37 # define rb_cNilClass (*dll_rb_cNilClass) | |
38 # define rb_cSymbol (*dll_rb_cSymbol) | |
39 # define rb_cTrueClass (*dll_rb_cTrueClass) | |
40 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18 | |
41 /* | |
42 * On ver 1.8, all Ruby functions are exported with "__declspce(dllimport)" | |
43 * in ruby.h. But it cause trouble for these variables, because it is | |
44 * defined in this file. When defined this RUBY_EXPORT it modified to | |
45 * "extern" and be able to avoid this problem. | |
46 */ | |
47 # define RUBY_EXPORT | |
48 # endif | |
49 #endif | |
50 | |
2076
1c7a66d820e4
updated for version 7.2.360
Bram Moolenaar <bram@zimbu.org>
parents:
1888
diff
changeset
|
51 /* suggested by Ariya Mizutani */ |
1c7a66d820e4
updated for version 7.2.360
Bram Moolenaar <bram@zimbu.org>
parents:
1888
diff
changeset
|
52 #if (_MSC_VER == 1200) |
1c7a66d820e4
updated for version 7.2.360
Bram Moolenaar <bram@zimbu.org>
parents:
1888
diff
changeset
|
53 # undef _WIN32_WINNT |
1c7a66d820e4
updated for version 7.2.360
Bram Moolenaar <bram@zimbu.org>
parents:
1888
diff
changeset
|
54 #endif |
1c7a66d820e4
updated for version 7.2.360
Bram Moolenaar <bram@zimbu.org>
parents:
1888
diff
changeset
|
55 |
7 | 56 #include <ruby.h> |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
57 #if defined(RUBY_VERSION) && RUBY_VERSION >= 19 |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
58 # include <ruby/encoding.h> |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
59 #endif |
7 | 60 |
61 #undef EXTERN | |
62 #undef _ | |
63 | |
64 /* T_DATA defined both by Ruby and Mac header files, hack around it... */ | |
1233 | 65 #if defined(MACOS_X_UNIX) || defined(macintosh) |
7 | 66 # define __OPENTRANSPORT__ |
67 # define __OPENTRANSPORTPROTOCOL__ | |
68 # define __OPENTRANSPORTPROVIDERS__ | |
69 #endif | |
70 | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
71 /* |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
72 * Backward compatiblity for Ruby 1.8 and earlier. |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
73 * Ruby 1.9 does not provide STR2CSTR, instead StringValuePtr is provided. |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
74 * Ruby 1.9 does not provide RXXX(s)->len and RXXX(s)->ptr, instead |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
75 * RXXX_LEN(s) and RXXX_PTR(s) are provided. |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
76 */ |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
77 #ifndef StringValuePtr |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
78 # define StringValuePtr(s) STR2CSTR(s) |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
79 #endif |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
80 #ifndef RARRAY_LEN |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
81 # define RARRAY_LEN(s) RARRAY(s)->len |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
82 #endif |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
83 #ifndef RARRAY_PTR |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
84 # define RARRAY_PTR(s) RARRAY(s)->ptr |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
85 #endif |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
86 #ifndef RSTRING_LEN |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
87 # define RSTRING_LEN(s) RSTRING(s)->len |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
88 #endif |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
89 #ifndef RSTRING_PTR |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
90 # define RSTRING_PTR(s) RSTRING(s)->ptr |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
91 #endif |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
92 |
7 | 93 #include "vim.h" |
94 #include "version.h" | |
95 | |
96 #if defined(PROTO) && !defined(FEAT_RUBY) | |
97 /* Define these to be able to generate the function prototypes. */ | |
98 # define VALUE int | |
99 # define RUBY_DATA_FUNC int | |
100 #endif | |
101 | |
102 static int ruby_initialized = 0; | |
103 static VALUE objtbl; | |
104 | |
105 static VALUE mVIM; | |
106 static VALUE cBuffer; | |
107 static VALUE cVimWindow; | |
108 static VALUE eDeletedBufferError; | |
109 static VALUE eDeletedWindowError; | |
110 | |
111 static int ensure_ruby_initialized(void); | |
112 static void error_print(int); | |
113 static void ruby_io_init(void); | |
114 static void ruby_vim_init(void); | |
115 | |
116 #if defined(DYNAMIC_RUBY) || defined(PROTO) | |
117 #ifdef PROTO | |
118 # define HINSTANCE int /* for generating prototypes */ | |
119 #endif | |
120 | |
121 /* | |
122 * Wrapper defines | |
123 */ | |
124 #define rb_assoc_new dll_rb_assoc_new | |
125 #define rb_cObject (*dll_rb_cObject) | |
126 #define rb_check_type dll_rb_check_type | |
127 #define rb_class_path dll_rb_class_path | |
128 #define rb_data_object_alloc dll_rb_data_object_alloc | |
129 #define rb_define_class_under dll_rb_define_class_under | |
130 #define rb_define_const dll_rb_define_const | |
131 #define rb_define_global_function dll_rb_define_global_function | |
132 #define rb_define_method dll_rb_define_method | |
133 #define rb_define_module dll_rb_define_module | |
134 #define rb_define_module_function dll_rb_define_module_function | |
135 #define rb_define_singleton_method dll_rb_define_singleton_method | |
136 #define rb_define_virtual_variable dll_rb_define_virtual_variable | |
137 #define rb_stdout (*dll_rb_stdout) | |
138 #define rb_eArgError (*dll_rb_eArgError) | |
139 #define rb_eIndexError (*dll_rb_eIndexError) | |
140 #define rb_eRuntimeError (*dll_rb_eRuntimeError) | |
141 #define rb_eStandardError (*dll_rb_eStandardError) | |
142 #define rb_eval_string_protect dll_rb_eval_string_protect | |
143 #define rb_global_variable dll_rb_global_variable | |
144 #define rb_hash_aset dll_rb_hash_aset | |
145 #define rb_hash_new dll_rb_hash_new | |
146 #define rb_inspect dll_rb_inspect | |
147 #define rb_int2inum dll_rb_int2inum | |
148 #define rb_lastline_get dll_rb_lastline_get | |
149 #define rb_lastline_set dll_rb_lastline_set | |
150 #define rb_load_protect dll_rb_load_protect | |
151 #define rb_num2long dll_rb_num2long | |
152 #define rb_num2ulong dll_rb_num2ulong | |
153 #define rb_obj_alloc dll_rb_obj_alloc | |
154 #define rb_obj_as_string dll_rb_obj_as_string | |
155 #define rb_obj_id dll_rb_obj_id | |
156 #define rb_raise dll_rb_raise | |
157 #define rb_str2cstr dll_rb_str2cstr | |
158 #define rb_str_cat dll_rb_str_cat | |
159 #define rb_str_concat dll_rb_str_concat | |
160 #define rb_str_new dll_rb_str_new | |
161 #define rb_str_new2 dll_rb_str_new2 | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
162 #if defined(RUBY_VERSION) && RUBY_VERSION >= 19 |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
163 # define rb_errinfo dll_rb_errinfo |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
164 #else |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
165 # define ruby_errinfo (*dll_ruby_errinfo) |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
166 #endif |
7 | 167 #define ruby_init dll_ruby_init |
168 #define ruby_init_loadpath dll_ruby_init_loadpath | |
2076
1c7a66d820e4
updated for version 7.2.360
Bram Moolenaar <bram@zimbu.org>
parents:
1888
diff
changeset
|
169 #define NtInitialize dll_NtInitialize |
7 | 170 #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18 |
171 # define rb_w32_snprintf dll_rb_w32_snprintf | |
172 #endif | |
173 | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
174 #if defined(RUBY_VERSION) && RUBY_VERSION >= 19 |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
175 # define ruby_script dll_ruby_script |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
176 # define rb_enc_find_index dll_rb_enc_find_index |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
177 # define rb_enc_find dll_rb_enc_find |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
178 # define rb_enc_str_new dll_rb_enc_str_new |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
179 # define rb_sprintf dll_rb_sprintf |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
180 #endif |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
181 |
7 | 182 /* |
183 * Pointers for dynamic link | |
184 */ | |
185 static VALUE (*dll_rb_assoc_new) (VALUE, VALUE); | |
186 static VALUE *dll_rb_cFalseClass; | |
187 static VALUE *dll_rb_cFixnum; | |
188 static VALUE *dll_rb_cNilClass; | |
189 static VALUE *dll_rb_cObject; | |
190 static VALUE *dll_rb_cSymbol; | |
191 static VALUE *dll_rb_cTrueClass; | |
192 static void (*dll_rb_check_type) (VALUE,int); | |
193 static VALUE (*dll_rb_class_path) (VALUE); | |
194 static VALUE (*dll_rb_data_object_alloc) (VALUE, void*, RUBY_DATA_FUNC, RUBY_DATA_FUNC); | |
195 static VALUE (*dll_rb_define_class_under) (VALUE, const char*, VALUE); | |
196 static void (*dll_rb_define_const) (VALUE,const char*,VALUE); | |
197 static void (*dll_rb_define_global_function) (const char*,VALUE(*)(),int); | |
198 static void (*dll_rb_define_method) (VALUE,const char*,VALUE(*)(),int); | |
199 static VALUE (*dll_rb_define_module) (const char*); | |
200 static void (*dll_rb_define_module_function) (VALUE,const char*,VALUE(*)(),int); | |
201 static void (*dll_rb_define_singleton_method) (VALUE,const char*,VALUE(*)(),int); | |
202 static void (*dll_rb_define_virtual_variable) (const char*,VALUE(*)(),void(*)()); | |
203 static VALUE *dll_rb_stdout; | |
204 static VALUE *dll_rb_eArgError; | |
205 static VALUE *dll_rb_eIndexError; | |
206 static VALUE *dll_rb_eRuntimeError; | |
207 static VALUE *dll_rb_eStandardError; | |
208 static VALUE (*dll_rb_eval_string_protect) (const char*, int*); | |
209 static void (*dll_rb_global_variable) (VALUE*); | |
210 static VALUE (*dll_rb_hash_aset) (VALUE, VALUE, VALUE); | |
211 static VALUE (*dll_rb_hash_new) (void); | |
212 static VALUE (*dll_rb_inspect) (VALUE); | |
213 static VALUE (*dll_rb_int2inum) (long); | |
214 static VALUE (*dll_rb_int2inum) (long); | |
215 static VALUE (*dll_rb_lastline_get) (void); | |
216 static void (*dll_rb_lastline_set) (VALUE); | |
217 static void (*dll_rb_load_protect) (VALUE, int, int*); | |
218 static long (*dll_rb_num2long) (VALUE); | |
219 static unsigned long (*dll_rb_num2ulong) (VALUE); | |
220 static VALUE (*dll_rb_obj_alloc) (VALUE); | |
221 static VALUE (*dll_rb_obj_as_string) (VALUE); | |
222 static VALUE (*dll_rb_obj_id) (VALUE); | |
223 static void (*dll_rb_raise) (VALUE, const char*, ...); | |
224 static char *(*dll_rb_str2cstr) (VALUE,int*); | |
225 static VALUE (*dll_rb_str_cat) (VALUE, const char*, long); | |
226 static VALUE (*dll_rb_str_concat) (VALUE, VALUE); | |
227 static VALUE (*dll_rb_str_new) (const char*, long); | |
228 static VALUE (*dll_rb_str_new2) (const char*); | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
229 #if defined(RUBY_VERSION) && RUBY_VERSION >= 19 |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
230 static VALUE (*dll_rb_errinfo) (void); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
231 #else |
7 | 232 static VALUE *dll_ruby_errinfo; |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
233 #endif |
7 | 234 static void (*dll_ruby_init) (void); |
235 static void (*dll_ruby_init_loadpath) (void); | |
2076
1c7a66d820e4
updated for version 7.2.360
Bram Moolenaar <bram@zimbu.org>
parents:
1888
diff
changeset
|
236 static void (*dll_NtInitialize) (int*, char***); |
7 | 237 #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18 |
238 static int (*dll_rb_w32_snprintf)(char*, size_t, const char*, ...); | |
239 #endif | |
240 | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
241 #if defined(RUBY_VERSION) && RUBY_VERSION >= 19 |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
242 static void (*dll_ruby_script) (const char*); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
243 static int (*dll_rb_enc_find_index) (const char*); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
244 static rb_encoding* (*dll_rb_enc_find) (const char*); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
245 static VALUE (*dll_rb_enc_str_new) (const char*, long, rb_encoding*); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
246 static VALUE (*dll_rb_sprintf) (const char*, ...); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
247 #endif |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
248 |
7 | 249 static HINSTANCE hinstRuby = 0; /* Instance of ruby.dll */ |
250 | |
251 /* | |
501 | 252 * Table of name to function pointer of ruby. |
7 | 253 */ |
254 #define RUBY_PROC FARPROC | |
255 static struct | |
256 { | |
257 char *name; | |
258 RUBY_PROC *ptr; | |
259 } ruby_funcname_table[] = | |
260 { | |
261 {"rb_assoc_new", (RUBY_PROC*)&dll_rb_assoc_new}, | |
262 {"rb_cFalseClass", (RUBY_PROC*)&dll_rb_cFalseClass}, | |
263 {"rb_cFixnum", (RUBY_PROC*)&dll_rb_cFixnum}, | |
264 {"rb_cNilClass", (RUBY_PROC*)&dll_rb_cNilClass}, | |
265 {"rb_cObject", (RUBY_PROC*)&dll_rb_cObject}, | |
266 {"rb_cSymbol", (RUBY_PROC*)&dll_rb_cSymbol}, | |
267 {"rb_cTrueClass", (RUBY_PROC*)&dll_rb_cTrueClass}, | |
268 {"rb_check_type", (RUBY_PROC*)&dll_rb_check_type}, | |
269 {"rb_class_path", (RUBY_PROC*)&dll_rb_class_path}, | |
270 {"rb_data_object_alloc", (RUBY_PROC*)&dll_rb_data_object_alloc}, | |
271 {"rb_define_class_under", (RUBY_PROC*)&dll_rb_define_class_under}, | |
272 {"rb_define_const", (RUBY_PROC*)&dll_rb_define_const}, | |
273 {"rb_define_global_function", (RUBY_PROC*)&dll_rb_define_global_function}, | |
274 {"rb_define_method", (RUBY_PROC*)&dll_rb_define_method}, | |
275 {"rb_define_module", (RUBY_PROC*)&dll_rb_define_module}, | |
276 {"rb_define_module_function", (RUBY_PROC*)&dll_rb_define_module_function}, | |
277 {"rb_define_singleton_method", (RUBY_PROC*)&dll_rb_define_singleton_method}, | |
278 {"rb_define_virtual_variable", (RUBY_PROC*)&dll_rb_define_virtual_variable}, | |
279 {"rb_stdout", (RUBY_PROC*)&dll_rb_stdout}, | |
280 {"rb_eArgError", (RUBY_PROC*)&dll_rb_eArgError}, | |
281 {"rb_eIndexError", (RUBY_PROC*)&dll_rb_eIndexError}, | |
282 {"rb_eRuntimeError", (RUBY_PROC*)&dll_rb_eRuntimeError}, | |
283 {"rb_eStandardError", (RUBY_PROC*)&dll_rb_eStandardError}, | |
284 {"rb_eval_string_protect", (RUBY_PROC*)&dll_rb_eval_string_protect}, | |
285 {"rb_global_variable", (RUBY_PROC*)&dll_rb_global_variable}, | |
286 {"rb_hash_aset", (RUBY_PROC*)&dll_rb_hash_aset}, | |
287 {"rb_hash_new", (RUBY_PROC*)&dll_rb_hash_new}, | |
288 {"rb_inspect", (RUBY_PROC*)&dll_rb_inspect}, | |
289 {"rb_int2inum", (RUBY_PROC*)&dll_rb_int2inum}, | |
290 {"rb_lastline_get", (RUBY_PROC*)&dll_rb_lastline_get}, | |
291 {"rb_lastline_set", (RUBY_PROC*)&dll_rb_lastline_set}, | |
292 {"rb_load_protect", (RUBY_PROC*)&dll_rb_load_protect}, | |
293 {"rb_num2long", (RUBY_PROC*)&dll_rb_num2long}, | |
294 {"rb_num2ulong", (RUBY_PROC*)&dll_rb_num2ulong}, | |
295 {"rb_obj_alloc", (RUBY_PROC*)&dll_rb_obj_alloc}, | |
296 {"rb_obj_as_string", (RUBY_PROC*)&dll_rb_obj_as_string}, | |
297 {"rb_obj_id", (RUBY_PROC*)&dll_rb_obj_id}, | |
298 {"rb_raise", (RUBY_PROC*)&dll_rb_raise}, | |
299 {"rb_str2cstr", (RUBY_PROC*)&dll_rb_str2cstr}, | |
300 {"rb_str_cat", (RUBY_PROC*)&dll_rb_str_cat}, | |
301 {"rb_str_concat", (RUBY_PROC*)&dll_rb_str_concat}, | |
302 {"rb_str_new", (RUBY_PROC*)&dll_rb_str_new}, | |
303 {"rb_str_new2", (RUBY_PROC*)&dll_rb_str_new2}, | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
304 #if defined(RUBY_VERSION) && RUBY_VERSION >= 19 |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
305 {"rb_errinfo", (RUBY_PROC*)&dll_rb_errinfo}, |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
306 #else |
7 | 307 {"ruby_errinfo", (RUBY_PROC*)&dll_ruby_errinfo}, |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
308 #endif |
7 | 309 {"ruby_init", (RUBY_PROC*)&dll_ruby_init}, |
310 {"ruby_init_loadpath", (RUBY_PROC*)&dll_ruby_init_loadpath}, | |
2076
1c7a66d820e4
updated for version 7.2.360
Bram Moolenaar <bram@zimbu.org>
parents:
1888
diff
changeset
|
311 {"NtInitialize", (RUBY_PROC*)&dll_NtInitialize}, |
7 | 312 #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18 |
313 {"rb_w32_snprintf", (RUBY_PROC*)&dll_rb_w32_snprintf}, | |
314 #endif | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
315 #if defined(RUBY_VERSION) && RUBY_VERSION >= 19 |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
316 {"ruby_script", (RUBY_PROC*)&dll_ruby_script}, |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
317 {"rb_enc_find_index", (RUBY_PROC*)&dll_rb_enc_find_index}, |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
318 {"rb_enc_find", (RUBY_PROC*)&dll_rb_enc_find}, |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
319 {"rb_enc_str_new", (RUBY_PROC*)&dll_rb_enc_str_new}, |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
320 {"rb_sprintf", (RUBY_PROC*)&dll_rb_sprintf}, |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
321 #endif |
7 | 322 {"", NULL}, |
323 }; | |
324 | |
325 /* | |
326 * Free ruby.dll | |
327 */ | |
328 static void | |
329 end_dynamic_ruby() | |
330 { | |
331 if (hinstRuby) | |
332 { | |
333 FreeLibrary(hinstRuby); | |
334 hinstRuby = 0; | |
335 } | |
336 } | |
337 | |
338 /* | |
339 * Load library and get all pointers. | |
340 * Parameter 'libname' provides name of DLL. | |
341 * Return OK or FAIL. | |
342 */ | |
343 static int | |
344 ruby_runtime_link_init(char *libname, int verbose) | |
345 { | |
346 int i; | |
347 | |
348 if (hinstRuby) | |
349 return OK; | |
350 hinstRuby = LoadLibrary(libname); | |
351 if (!hinstRuby) | |
352 { | |
353 if (verbose) | |
354 EMSG2(_(e_loadlib), libname); | |
355 return FAIL; | |
356 } | |
357 | |
358 for (i = 0; ruby_funcname_table[i].ptr; ++i) | |
359 { | |
360 if (!(*ruby_funcname_table[i].ptr = GetProcAddress(hinstRuby, | |
361 ruby_funcname_table[i].name))) | |
362 { | |
363 FreeLibrary(hinstRuby); | |
364 hinstRuby = 0; | |
365 if (verbose) | |
366 EMSG2(_(e_loadfunc), ruby_funcname_table[i].name); | |
367 return FAIL; | |
368 } | |
369 } | |
370 return OK; | |
371 } | |
372 | |
373 /* | |
374 * If ruby is enabled (there is installed ruby on Windows system) return TRUE, | |
375 * else FALSE. | |
376 */ | |
377 int | |
378 ruby_enabled(verbose) | |
379 int verbose; | |
380 { | |
381 return ruby_runtime_link_init(DYNAMIC_RUBY_DLL, verbose) == OK; | |
382 } | |
383 #endif /* defined(DYNAMIC_RUBY) || defined(PROTO) */ | |
384 | |
385 void | |
386 ruby_end() | |
387 { | |
388 #ifdef DYNAMIC_RUBY | |
389 end_dynamic_ruby(); | |
390 #endif | |
391 } | |
392 | |
393 void ex_ruby(exarg_T *eap) | |
394 { | |
395 int state; | |
396 char *script = NULL; | |
397 | |
750 | 398 script = (char *)script_get(eap, eap->arg); |
7 | 399 if (!eap->skip && ensure_ruby_initialized()) |
400 { | |
401 if (script == NULL) | |
402 rb_eval_string_protect((char *)eap->arg, &state); | |
403 else | |
404 rb_eval_string_protect(script, &state); | |
405 if (state) | |
406 error_print(state); | |
407 } | |
408 vim_free(script); | |
409 } | |
410 | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
411 /* |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
412 * In Ruby 1.9 or later, ruby String object has encoding. |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
413 * conversion buffer string of vim to ruby String object using |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
414 * VIM encoding option. |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
415 */ |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
416 static VALUE |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
417 vim_str2rb_enc_str(const char *s) |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
418 { |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
419 #if defined(RUBY_VERSION) && RUBY_VERSION >= 19 |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
420 int isnum; |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
421 long lval; |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
422 char_u *sval; |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
423 rb_encoding *enc; |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
424 |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
425 isnum = get_option_value((char_u *)"enc", &lval, &sval, 0); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
426 if (isnum == 0) |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
427 { |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
428 enc = rb_enc_find((char *)sval); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
429 vim_free(sval); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
430 if (enc) { |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
431 return rb_enc_str_new(s, strlen(s), enc); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
432 } |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
433 } |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
434 #endif |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
435 return rb_str_new2(s); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
436 } |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
437 |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
438 static VALUE |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
439 eval_enc_string_protect(const char *str, int *state) |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
440 { |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
441 #if defined(RUBY_VERSION) && RUBY_VERSION >= 19 |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
442 int isnum; |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
443 long lval; |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
444 char_u *sval; |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
445 rb_encoding *enc; |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
446 VALUE v; |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
447 |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
448 isnum = get_option_value((char_u *)"enc", &lval, &sval, 0); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
449 if (isnum == 0) |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
450 { |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
451 enc = rb_enc_find((char *)sval); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
452 vim_free(sval); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
453 if (enc) |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
454 { |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
455 v = rb_sprintf("#-*- coding:%s -*-\n%s", rb_enc_name(enc), str); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
456 return rb_eval_string_protect(StringValuePtr(v), state); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
457 } |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
458 } |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
459 #endif |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
460 return rb_eval_string_protect(str, state); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
461 } |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
462 |
7 | 463 void ex_rubydo(exarg_T *eap) |
464 { | |
465 int state; | |
466 linenr_T i; | |
467 | |
468 if (ensure_ruby_initialized()) | |
469 { | |
470 if (u_save(eap->line1 - 1, eap->line2 + 1) != OK) | |
471 return; | |
472 for (i = eap->line1; i <= eap->line2; i++) { | |
473 VALUE line, oldline; | |
474 | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
475 line = oldline = vim_str2rb_enc_str((char *)ml_get(i)); |
7 | 476 rb_lastline_set(line); |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
477 eval_enc_string_protect((char *) eap->arg, &state); |
7 | 478 if (state) { |
479 error_print(state); | |
480 break; | |
481 } | |
482 line = rb_lastline_get(); | |
483 if (!NIL_P(line)) { | |
484 if (TYPE(line) != T_STRING) { | |
835 | 485 EMSG(_("E265: $_ must be an instance of String")); |
7 | 486 return; |
487 } | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
488 ml_replace(i, (char_u *) StringValuePtr(line), 1); |
7 | 489 changed(); |
490 #ifdef SYNTAX_HL | |
491 syn_changed(i); /* recompute syntax hl. for this line */ | |
492 #endif | |
493 } | |
494 } | |
495 check_cursor(); | |
496 update_curbuf(NOT_VALID); | |
497 } | |
498 } | |
499 | |
500 void ex_rubyfile(exarg_T *eap) | |
501 { | |
502 int state; | |
503 | |
504 if (ensure_ruby_initialized()) | |
505 { | |
506 rb_load_protect(rb_str_new2((char *) eap->arg), 0, &state); | |
507 if (state) error_print(state); | |
508 } | |
509 } | |
510 | |
511 void ruby_buffer_free(buf_T *buf) | |
512 { | |
502 | 513 if (buf->b_ruby_ref) |
514 { | |
515 rb_hash_aset(objtbl, rb_obj_id((VALUE) buf->b_ruby_ref), Qnil); | |
516 RDATA(buf->b_ruby_ref)->data = NULL; | |
7 | 517 } |
518 } | |
519 | |
520 void ruby_window_free(win_T *win) | |
521 { | |
502 | 522 if (win->w_ruby_ref) |
523 { | |
524 rb_hash_aset(objtbl, rb_obj_id((VALUE) win->w_ruby_ref), Qnil); | |
525 RDATA(win->w_ruby_ref)->data = NULL; | |
7 | 526 } |
527 } | |
528 | |
529 static int ensure_ruby_initialized(void) | |
530 { | |
531 if (!ruby_initialized) | |
532 { | |
533 #ifdef DYNAMIC_RUBY | |
534 if (ruby_enabled(TRUE)) | |
535 { | |
536 #endif | |
2076
1c7a66d820e4
updated for version 7.2.360
Bram Moolenaar <bram@zimbu.org>
parents:
1888
diff
changeset
|
537 #ifdef _WIN32 |
1c7a66d820e4
updated for version 7.2.360
Bram Moolenaar <bram@zimbu.org>
parents:
1888
diff
changeset
|
538 /* suggested by Ariya Mizutani */ |
1c7a66d820e4
updated for version 7.2.360
Bram Moolenaar <bram@zimbu.org>
parents:
1888
diff
changeset
|
539 int argc = 1; |
1c7a66d820e4
updated for version 7.2.360
Bram Moolenaar <bram@zimbu.org>
parents:
1888
diff
changeset
|
540 char *argv[] = {"gvim.exe"}; |
1c7a66d820e4
updated for version 7.2.360
Bram Moolenaar <bram@zimbu.org>
parents:
1888
diff
changeset
|
541 NtInitialize(&argc, &argv); |
1c7a66d820e4
updated for version 7.2.360
Bram Moolenaar <bram@zimbu.org>
parents:
1888
diff
changeset
|
542 #endif |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
543 #if defined(RUBY_VERSION) && RUBY_VERSION >= 19 |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
544 RUBY_INIT_STACK; |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
545 #endif |
7 | 546 ruby_init(); |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
547 #if defined(RUBY_VERSION) && RUBY_VERSION >= 19 |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
548 ruby_script("vim-ruby"); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
549 #endif |
7 | 550 ruby_init_loadpath(); |
551 ruby_io_init(); | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
552 #if defined(RUBY_VERSION) && RUBY_VERSION >= 19 |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
553 rb_enc_find_index("encdb"); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
554 #endif |
7 | 555 ruby_vim_init(); |
556 ruby_initialized = 1; | |
557 #ifdef DYNAMIC_RUBY | |
558 } | |
559 else | |
560 { | |
561 EMSG(_("E266: Sorry, this command is disabled, the Ruby library could not be loaded.")); | |
562 return 0; | |
563 } | |
564 #endif | |
565 } | |
566 return ruby_initialized; | |
567 } | |
568 | |
569 static void error_print(int state) | |
570 { | |
571 #ifndef DYNAMIC_RUBY | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
572 #if !(defined(RUBY_VERSION) && RUBY_VERSION >= 19) |
7 | 573 RUBYEXTERN VALUE ruby_errinfo; |
574 #endif | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
575 #endif |
7 | 576 VALUE eclass; |
577 VALUE einfo; | |
578 char buff[BUFSIZ]; | |
579 | |
580 #define TAG_RETURN 0x1 | |
581 #define TAG_BREAK 0x2 | |
582 #define TAG_NEXT 0x3 | |
583 #define TAG_RETRY 0x4 | |
584 #define TAG_REDO 0x5 | |
585 #define TAG_RAISE 0x6 | |
586 #define TAG_THROW 0x7 | |
587 #define TAG_FATAL 0x8 | |
588 #define TAG_MASK 0xf | |
589 | |
590 switch (state) { | |
591 case TAG_RETURN: | |
835 | 592 EMSG(_("E267: unexpected return")); |
7 | 593 break; |
594 case TAG_NEXT: | |
835 | 595 EMSG(_("E268: unexpected next")); |
7 | 596 break; |
597 case TAG_BREAK: | |
835 | 598 EMSG(_("E269: unexpected break")); |
7 | 599 break; |
600 case TAG_REDO: | |
835 | 601 EMSG(_("E270: unexpected redo")); |
7 | 602 break; |
603 case TAG_RETRY: | |
835 | 604 EMSG(_("E271: retry outside of rescue clause")); |
7 | 605 break; |
606 case TAG_RAISE: | |
607 case TAG_FATAL: | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
608 #if defined(RUBY_VERSION) && RUBY_VERSION >= 19 |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
609 eclass = CLASS_OF(rb_errinfo()); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
610 einfo = rb_obj_as_string(rb_errinfo()); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
611 #else |
7 | 612 eclass = CLASS_OF(ruby_errinfo); |
613 einfo = rb_obj_as_string(ruby_errinfo); | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
614 #endif |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
615 if (eclass == rb_eRuntimeError && RSTRING_LEN(einfo) == 0) { |
835 | 616 EMSG(_("E272: unhandled exception")); |
7 | 617 } |
618 else { | |
619 VALUE epath; | |
620 char *p; | |
621 | |
622 epath = rb_class_path(eclass); | |
272 | 623 vim_snprintf(buff, BUFSIZ, "%s: %s", |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
624 RSTRING_PTR(epath), RSTRING_PTR(einfo)); |
7 | 625 p = strchr(buff, '\n'); |
626 if (p) *p = '\0'; | |
627 EMSG(buff); | |
628 } | |
629 break; | |
630 default: | |
272 | 631 vim_snprintf(buff, BUFSIZ, _("E273: unknown longjmp status %d"), state); |
7 | 632 EMSG(buff); |
633 break; | |
634 } | |
635 } | |
636 | |
1888 | 637 static VALUE vim_message(VALUE self UNUSED, VALUE str) |
7 | 638 { |
639 char *buff, *p; | |
640 | |
641 str = rb_obj_as_string(str); | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
642 buff = ALLOCA_N(char, RSTRING_LEN(str)); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
643 strcpy(buff, RSTRING_PTR(str)); |
7 | 644 p = strchr(buff, '\n'); |
645 if (p) *p = '\0'; | |
646 MSG(buff); | |
647 return Qnil; | |
648 } | |
649 | |
1888 | 650 static VALUE vim_set_option(VALUE self UNUSED, VALUE str) |
7 | 651 { |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
652 do_set((char_u *)StringValuePtr(str), 0); |
7 | 653 update_screen(NOT_VALID); |
654 return Qnil; | |
655 } | |
656 | |
1888 | 657 static VALUE vim_command(VALUE self UNUSED, VALUE str) |
7 | 658 { |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
659 do_cmdline_cmd((char_u *)StringValuePtr(str)); |
7 | 660 return Qnil; |
661 } | |
662 | |
1888 | 663 static VALUE vim_evaluate(VALUE self UNUSED, VALUE str) |
7 | 664 { |
665 #ifdef FEAT_EVAL | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
666 char_u *value = eval_to_string((char_u *)StringValuePtr(str), NULL, TRUE); |
7 | 667 |
750 | 668 if (value != NULL) |
7 | 669 { |
750 | 670 VALUE val = rb_str_new2((char *)value); |
7 | 671 vim_free(value); |
672 return val; | |
673 } | |
674 else | |
675 #endif | |
676 return Qnil; | |
677 } | |
678 | |
679 static VALUE buffer_new(buf_T *buf) | |
680 { | |
502 | 681 if (buf->b_ruby_ref) |
682 { | |
683 return (VALUE) buf->b_ruby_ref; | |
7 | 684 } |
502 | 685 else |
686 { | |
7 | 687 VALUE obj = Data_Wrap_Struct(cBuffer, 0, 0, buf); |
502 | 688 buf->b_ruby_ref = (void *) obj; |
7 | 689 rb_hash_aset(objtbl, rb_obj_id(obj), obj); |
690 return obj; | |
691 } | |
692 } | |
693 | |
694 static buf_T *get_buf(VALUE obj) | |
695 { | |
696 buf_T *buf; | |
697 | |
698 Data_Get_Struct(obj, buf_T, buf); | |
699 if (buf == NULL) | |
700 rb_raise(eDeletedBufferError, "attempt to refer to deleted buffer"); | |
701 return buf; | |
702 } | |
703 | |
704 static VALUE buffer_s_current() | |
705 { | |
706 return buffer_new(curbuf); | |
707 } | |
708 | |
709 static VALUE buffer_s_count() | |
710 { | |
711 buf_T *b; | |
712 int n = 0; | |
713 | |
779 | 714 for (b = firstbuf; b != NULL; b = b->b_next) |
715 { | |
856 | 716 /* Deleted buffers should not be counted |
717 * SegPhault - 01/07/05 */ | |
718 if (b->b_p_bl) | |
779 | 719 n++; |
720 } | |
721 | |
7 | 722 return INT2NUM(n); |
723 } | |
724 | |
1888 | 725 static VALUE buffer_s_aref(VALUE self UNUSED, VALUE num) |
7 | 726 { |
727 buf_T *b; | |
728 int n = NUM2INT(num); | |
729 | |
779 | 730 for (b = firstbuf; b != NULL; b = b->b_next) |
731 { | |
856 | 732 /* Deleted buffers should not be counted |
733 * SegPhault - 01/07/05 */ | |
734 if (!b->b_p_bl) | |
779 | 735 continue; |
736 | |
856 | 737 if (n == 0) |
7 | 738 return buffer_new(b); |
779 | 739 |
856 | 740 n--; |
7 | 741 } |
742 return Qnil; | |
743 } | |
744 | |
745 static VALUE buffer_name(VALUE self) | |
746 { | |
747 buf_T *buf = get_buf(self); | |
748 | |
750 | 749 return buf->b_ffname ? rb_str_new2((char *)buf->b_ffname) : Qnil; |
7 | 750 } |
751 | |
752 static VALUE buffer_number(VALUE self) | |
753 { | |
754 buf_T *buf = get_buf(self); | |
755 | |
756 return INT2NUM(buf->b_fnum); | |
757 } | |
758 | |
759 static VALUE buffer_count(VALUE self) | |
760 { | |
761 buf_T *buf = get_buf(self); | |
762 | |
763 return INT2NUM(buf->b_ml.ml_line_count); | |
764 } | |
765 | |
779 | 766 static VALUE get_buffer_line(buf_T *buf, linenr_T n) |
7 | 767 { |
779 | 768 if (n > 0 && n <= buf->b_ml.ml_line_count) |
769 { | |
750 | 770 char *line = (char *)ml_get_buf(buf, n, FALSE); |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
771 return line ? vim_str2rb_enc_str(line) : Qnil; |
7 | 772 } |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
773 rb_raise(rb_eIndexError, "line number %ld out of range", (long)n); |
1888 | 774 #ifndef __GNUC__ |
779 | 775 return Qnil; /* For stop warning */ |
1888 | 776 #endif |
7 | 777 } |
778 | |
779 | 779 static VALUE buffer_aref(VALUE self, VALUE num) |
7 | 780 { |
781 buf_T *buf = get_buf(self); | |
779 | 782 |
783 if (buf != NULL) | |
784 return get_buffer_line(buf, (linenr_T)NUM2LONG(num)); | |
785 return Qnil; /* For stop warning */ | |
786 } | |
787 | |
788 static VALUE set_buffer_line(buf_T *buf, linenr_T n, VALUE str) | |
789 { | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
790 char *line = StringValuePtr(str); |
896 | 791 aco_save_T aco; |
7 | 792 |
896 | 793 if (n > 0 && n <= buf->b_ml.ml_line_count && line != NULL) |
794 { | |
795 /* set curwin/curbuf for "buf" and save some things */ | |
796 aucmd_prepbuf(&aco, buf); | |
797 | |
7 | 798 if (u_savesub(n) == OK) { |
779 | 799 ml_replace(n, (char_u *)line, TRUE); |
7 | 800 changed(); |
801 #ifdef SYNTAX_HL | |
802 syn_changed(n); /* recompute syntax hl. for this line */ | |
803 #endif | |
804 } | |
896 | 805 |
806 /* restore curwin/curbuf and a few other things */ | |
807 aucmd_restbuf(&aco); | |
808 /* Careful: autocommands may have made "buf" invalid! */ | |
934 | 809 |
7 | 810 update_curbuf(NOT_VALID); |
811 } | |
896 | 812 else |
813 { | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
814 rb_raise(rb_eIndexError, "line number %ld out of range", (long)n); |
1888 | 815 #ifndef __GNUC__ |
7 | 816 return Qnil; /* For stop warning */ |
1888 | 817 #endif |
7 | 818 } |
819 return str; | |
820 } | |
821 | |
779 | 822 static VALUE buffer_aset(VALUE self, VALUE num, VALUE str) |
823 { | |
824 buf_T *buf = get_buf(self); | |
825 | |
826 if (buf != NULL) | |
827 return set_buffer_line(buf, (linenr_T)NUM2LONG(num), str); | |
828 return str; | |
829 } | |
830 | |
7 | 831 static VALUE buffer_delete(VALUE self, VALUE num) |
832 { | |
896 | 833 buf_T *buf = get_buf(self); |
834 long n = NUM2LONG(num); | |
835 aco_save_T aco; | |
7 | 836 |
896 | 837 if (n > 0 && n <= buf->b_ml.ml_line_count) |
838 { | |
839 /* set curwin/curbuf for "buf" and save some things */ | |
840 aucmd_prepbuf(&aco, buf); | |
841 | |
7 | 842 if (u_savedel(n, 1) == OK) { |
843 ml_delete(n, 0); | |
779 | 844 |
856 | 845 /* Changes to non-active buffers should properly refresh |
846 * SegPhault - 01/09/05 */ | |
847 deleted_lines_mark(n, 1L); | |
779 | 848 |
7 | 849 changed(); |
850 } | |
896 | 851 |
852 /* restore curwin/curbuf and a few other things */ | |
853 aucmd_restbuf(&aco); | |
854 /* Careful: autocommands may have made "buf" invalid! */ | |
934 | 855 |
7 | 856 update_curbuf(NOT_VALID); |
857 } | |
896 | 858 else |
859 { | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
860 rb_raise(rb_eIndexError, "line number %ld out of range", n); |
7 | 861 } |
862 return Qnil; | |
863 } | |
864 | |
865 static VALUE buffer_append(VALUE self, VALUE num, VALUE str) | |
866 { | |
896 | 867 buf_T *buf = get_buf(self); |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
868 char *line = StringValuePtr(str); |
896 | 869 long n = NUM2LONG(num); |
870 aco_save_T aco; | |
7 | 871 |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
872 if (line != NULL) { |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
873 rb_raise(rb_eIndexError, "NULL line"); |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
874 } |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
875 else if (n >= 0 && n <= buf->b_ml.ml_line_count) |
896 | 876 { |
877 /* set curwin/curbuf for "buf" and save some things */ | |
878 aucmd_prepbuf(&aco, buf); | |
879 | |
7 | 880 if (u_inssub(n + 1) == OK) { |
881 ml_append(n, (char_u *) line, (colnr_T) 0, FALSE); | |
779 | 882 |
856 | 883 /* Changes to non-active buffers should properly refresh screen |
884 * SegPhault - 12/20/04 */ | |
885 appended_lines_mark(n, 1L); | |
779 | 886 |
856 | 887 changed(); |
7 | 888 } |
896 | 889 |
890 /* restore curwin/curbuf and a few other things */ | |
891 aucmd_restbuf(&aco); | |
892 /* Careful: autocommands may have made "buf" invalid! */ | |
934 | 893 |
7 | 894 update_curbuf(NOT_VALID); |
895 } | |
896 else { | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
897 rb_raise(rb_eIndexError, "line number %ld out of range", n); |
7 | 898 } |
899 return str; | |
900 } | |
901 | |
902 static VALUE window_new(win_T *win) | |
903 { | |
502 | 904 if (win->w_ruby_ref) |
905 { | |
906 return (VALUE) win->w_ruby_ref; | |
7 | 907 } |
502 | 908 else |
909 { | |
7 | 910 VALUE obj = Data_Wrap_Struct(cVimWindow, 0, 0, win); |
502 | 911 win->w_ruby_ref = (void *) obj; |
7 | 912 rb_hash_aset(objtbl, rb_obj_id(obj), obj); |
913 return obj; | |
914 } | |
915 } | |
916 | |
917 static win_T *get_win(VALUE obj) | |
918 { | |
919 win_T *win; | |
920 | |
921 Data_Get_Struct(obj, win_T, win); | |
922 if (win == NULL) | |
923 rb_raise(eDeletedWindowError, "attempt to refer to deleted window"); | |
924 return win; | |
925 } | |
926 | |
927 static VALUE window_s_current() | |
928 { | |
929 return window_new(curwin); | |
930 } | |
931 | |
779 | 932 /* |
933 * Added line manipulation functions | |
934 * SegPhault - 03/07/05 | |
935 */ | |
936 static VALUE line_s_current() | |
937 { | |
938 return get_buffer_line(curbuf, curwin->w_cursor.lnum); | |
939 } | |
940 | |
1888 | 941 static VALUE set_current_line(VALUE self UNUSED, VALUE str) |
779 | 942 { |
943 return set_buffer_line(curbuf, curwin->w_cursor.lnum, str); | |
944 } | |
945 | |
946 static VALUE current_line_number() | |
947 { | |
948 return INT2FIX((int)curwin->w_cursor.lnum); | |
949 } | |
950 | |
951 | |
952 | |
7 | 953 static VALUE window_s_count() |
954 { | |
955 #ifdef FEAT_WINDOWS | |
956 win_T *w; | |
957 int n = 0; | |
958 | |
671 | 959 for (w = firstwin; w != NULL; w = w->w_next) |
7 | 960 n++; |
961 return INT2NUM(n); | |
962 #else | |
963 return INT2NUM(1); | |
964 #endif | |
965 } | |
966 | |
1888 | 967 static VALUE window_s_aref(VALUE self UNUSED, VALUE num) |
7 | 968 { |
969 win_T *w; | |
970 int n = NUM2INT(num); | |
971 | |
972 #ifndef FEAT_WINDOWS | |
973 w = curwin; | |
974 #else | |
975 for (w = firstwin; w != NULL; w = w->w_next, --n) | |
976 #endif | |
977 if (n == 0) | |
978 return window_new(w); | |
979 return Qnil; | |
980 } | |
981 | |
982 static VALUE window_buffer(VALUE self) | |
983 { | |
984 win_T *win = get_win(self); | |
985 | |
986 return buffer_new(win->w_buffer); | |
987 } | |
988 | |
989 static VALUE window_height(VALUE self) | |
990 { | |
991 win_T *win = get_win(self); | |
992 | |
993 return INT2NUM(win->w_height); | |
994 } | |
995 | |
996 static VALUE window_set_height(VALUE self, VALUE height) | |
997 { | |
998 win_T *win = get_win(self); | |
999 win_T *savewin = curwin; | |
1000 | |
1001 curwin = win; | |
1002 win_setheight(NUM2INT(height)); | |
1003 curwin = savewin; | |
1004 return height; | |
1005 } | |
1006 | |
501 | 1007 static VALUE window_width(VALUE self) |
1008 { | |
1009 win_T *win = get_win(self); | |
1010 | |
1011 return INT2NUM(win->w_width); | |
1012 } | |
1013 | |
1014 static VALUE window_set_width(VALUE self, VALUE width) | |
1015 { | |
1016 win_T *win = get_win(self); | |
1017 win_T *savewin = curwin; | |
1018 | |
1019 curwin = win; | |
1020 win_setwidth(NUM2INT(width)); | |
1021 curwin = savewin; | |
1022 return width; | |
1023 } | |
1024 | |
7 | 1025 static VALUE window_cursor(VALUE self) |
1026 { | |
1027 win_T *win = get_win(self); | |
1028 | |
1029 return rb_assoc_new(INT2NUM(win->w_cursor.lnum), INT2NUM(win->w_cursor.col)); | |
1030 } | |
1031 | |
1032 static VALUE window_set_cursor(VALUE self, VALUE pos) | |
1033 { | |
1034 VALUE lnum, col; | |
1035 win_T *win = get_win(self); | |
1036 | |
1037 Check_Type(pos, T_ARRAY); | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
1038 if (RARRAY_LEN(pos) != 2) |
7 | 1039 rb_raise(rb_eArgError, "array length must be 2"); |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
1040 lnum = RARRAY_PTR(pos)[0]; |
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
1041 col = RARRAY_PTR(pos)[1]; |
7 | 1042 win->w_cursor.lnum = NUM2LONG(lnum); |
1043 win->w_cursor.col = NUM2UINT(col); | |
1044 check_cursor(); /* put cursor on an existing line */ | |
1045 update_screen(NOT_VALID); | |
1046 return Qnil; | |
1047 } | |
1048 | |
1888 | 1049 static VALUE f_p(int argc, VALUE *argv, VALUE self UNUSED) |
7 | 1050 { |
1051 int i; | |
1052 VALUE str = rb_str_new("", 0); | |
1053 | |
1054 for (i = 0; i < argc; i++) { | |
1055 if (i > 0) rb_str_cat(str, ", ", 2); | |
1056 rb_str_concat(str, rb_inspect(argv[i])); | |
1057 } | |
2077
d8983769c9dd
updated for version 7.2.361
Bram Moolenaar <bram@zimbu.org>
parents:
2076
diff
changeset
|
1058 MSG(RSTRING_PTR(str)); |
7 | 1059 return Qnil; |
1060 } | |
1061 | |
1062 static void ruby_io_init(void) | |
1063 { | |
1064 #ifndef DYNAMIC_RUBY | |
1065 RUBYEXTERN VALUE rb_stdout; | |
1066 #endif | |
1067 | |
1068 rb_stdout = rb_obj_alloc(rb_cObject); | |
1069 rb_define_singleton_method(rb_stdout, "write", vim_message, 1); | |
1070 rb_define_global_function("p", f_p, -1); | |
1071 } | |
1072 | |
1073 static void ruby_vim_init(void) | |
1074 { | |
1075 objtbl = rb_hash_new(); | |
1076 rb_global_variable(&objtbl); | |
1077 | |
1188 | 1078 /* The Vim module used to be called "VIM", but "Vim" is better. Make an |
1079 * alias "VIM" for backwards compatiblity. */ | |
1080 mVIM = rb_define_module("Vim"); | |
1081 rb_define_const(rb_cObject, "VIM", mVIM); | |
7 | 1082 rb_define_const(mVIM, "VERSION_MAJOR", INT2NUM(VIM_VERSION_MAJOR)); |
1083 rb_define_const(mVIM, "VERSION_MINOR", INT2NUM(VIM_VERSION_MINOR)); | |
1084 rb_define_const(mVIM, "VERSION_BUILD", INT2NUM(VIM_VERSION_BUILD)); | |
1085 rb_define_const(mVIM, "VERSION_PATCHLEVEL", INT2NUM(VIM_VERSION_PATCHLEVEL)); | |
1086 rb_define_const(mVIM, "VERSION_SHORT", rb_str_new2(VIM_VERSION_SHORT)); | |
1087 rb_define_const(mVIM, "VERSION_MEDIUM", rb_str_new2(VIM_VERSION_MEDIUM)); | |
1088 rb_define_const(mVIM, "VERSION_LONG", rb_str_new2(VIM_VERSION_LONG)); | |
1089 rb_define_const(mVIM, "VERSION_LONG_DATE", rb_str_new2(VIM_VERSION_LONG_DATE)); | |
1090 rb_define_module_function(mVIM, "message", vim_message, 1); | |
1091 rb_define_module_function(mVIM, "set_option", vim_set_option, 1); | |
1092 rb_define_module_function(mVIM, "command", vim_command, 1); | |
1093 rb_define_module_function(mVIM, "evaluate", vim_evaluate, 1); | |
1094 | |
1095 eDeletedBufferError = rb_define_class_under(mVIM, "DeletedBufferError", | |
1096 rb_eStandardError); | |
1097 eDeletedWindowError = rb_define_class_under(mVIM, "DeletedWindowError", | |
1098 rb_eStandardError); | |
1099 | |
1100 cBuffer = rb_define_class_under(mVIM, "Buffer", rb_cObject); | |
1101 rb_define_singleton_method(cBuffer, "current", buffer_s_current, 0); | |
1102 rb_define_singleton_method(cBuffer, "count", buffer_s_count, 0); | |
1103 rb_define_singleton_method(cBuffer, "[]", buffer_s_aref, 1); | |
1104 rb_define_method(cBuffer, "name", buffer_name, 0); | |
1105 rb_define_method(cBuffer, "number", buffer_number, 0); | |
1106 rb_define_method(cBuffer, "count", buffer_count, 0); | |
1107 rb_define_method(cBuffer, "length", buffer_count, 0); | |
1108 rb_define_method(cBuffer, "[]", buffer_aref, 1); | |
1109 rb_define_method(cBuffer, "[]=", buffer_aset, 2); | |
1110 rb_define_method(cBuffer, "delete", buffer_delete, 1); | |
1111 rb_define_method(cBuffer, "append", buffer_append, 2); | |
1112 | |
779 | 1113 /* Added line manipulation functions |
1114 * SegPhault - 03/07/05 */ | |
1115 rb_define_method(cBuffer, "line_number", current_line_number, 0); | |
1116 rb_define_method(cBuffer, "line", line_s_current, 0); | |
1117 rb_define_method(cBuffer, "line=", set_current_line, 1); | |
1118 | |
1119 | |
7 | 1120 cVimWindow = rb_define_class_under(mVIM, "Window", rb_cObject); |
1121 rb_define_singleton_method(cVimWindow, "current", window_s_current, 0); | |
1122 rb_define_singleton_method(cVimWindow, "count", window_s_count, 0); | |
1123 rb_define_singleton_method(cVimWindow, "[]", window_s_aref, 1); | |
1124 rb_define_method(cVimWindow, "buffer", window_buffer, 0); | |
1125 rb_define_method(cVimWindow, "height", window_height, 0); | |
1126 rb_define_method(cVimWindow, "height=", window_set_height, 1); | |
501 | 1127 rb_define_method(cVimWindow, "width", window_width, 0); |
1128 rb_define_method(cVimWindow, "width=", window_set_width, 1); | |
7 | 1129 rb_define_method(cVimWindow, "cursor", window_cursor, 0); |
1130 rb_define_method(cVimWindow, "cursor=", window_set_cursor, 1); | |
1131 | |
1132 rb_define_virtual_variable("$curbuf", buffer_s_current, 0); | |
1133 rb_define_virtual_variable("$curwin", window_s_current, 0); | |
1134 } |