annotate src/if_ruby.c @ 274:8fa8d7964cf1 v7.0073

updated for version 7.0073
author vimboss
date Thu, 19 May 2005 21:08:39 +0000
parents ddada568db54
children ce2181d14aa0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 * Ruby interface by Shugo Maeda.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 * Do ":help uganda" in Vim to read copying and usage conditions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 * Do ":help credits" in Vim to see a list of people who contributed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 * See README.txt for an overview of the Vim source code.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 #include <stdio.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 #include <string.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 #ifdef _WIN32
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 # if !defined(DYNAMIC_RUBY_VER) || (DYNAMIC_RUBY_VER < 18)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 # define NT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 # ifndef DYNAMIC_RUBY
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 # define IMPORT /* For static dll usage __declspec(dllimport) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 # define RUBYEXTERN __declspec(dllimport)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 #ifndef RUBYEXTERN
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 # define RUBYEXTERN extern
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 * This is tricky. In ruby.h there is (inline) function rb_class_of()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 * definition. This function use these variables. But we want function to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 * use dll_* variables.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 #ifdef DYNAMIC_RUBY
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 # define rb_cFalseClass (*dll_rb_cFalseClass)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 # define rb_cFixnum (*dll_rb_cFixnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 # define rb_cNilClass (*dll_rb_cNilClass)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 # define rb_cSymbol (*dll_rb_cSymbol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 # define rb_cTrueClass (*dll_rb_cTrueClass)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 # if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 * On ver 1.8, all Ruby functions are exported with "__declspce(dllimport)"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 * in ruby.h. But it cause trouble for these variables, because it is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 * defined in this file. When defined this RUBY_EXPORT it modified to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 * "extern" and be able to avoid this problem.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 # define RUBY_EXPORT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 #include <ruby.h>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 #undef EXTERN
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 #undef _
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 /* T_DATA defined both by Ruby and Mac header files, hack around it... */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 #ifdef FEAT_GUI_MAC
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 # define __OPENTRANSPORT__
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 # define __OPENTRANSPORTPROTOCOL__
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 # define __OPENTRANSPORTPROVIDERS__
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 #include "vim.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 #include "version.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 #if defined(PROTO) && !defined(FEAT_RUBY)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 /* Define these to be able to generate the function prototypes. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 # define VALUE int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 # define RUBY_DATA_FUNC int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 static int ruby_initialized = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 static VALUE objtbl;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 static VALUE mVIM;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 static VALUE cBuffer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 static VALUE cVimWindow;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 static VALUE eDeletedBufferError;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 static VALUE eDeletedWindowError;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 static int ensure_ruby_initialized(void);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 static void error_print(int);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81 static void ruby_io_init(void);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 static void ruby_vim_init(void);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 #if defined(DYNAMIC_RUBY) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 #ifdef PROTO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 # define HINSTANCE int /* for generating prototypes */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 * Wrapper defines
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 #define rb_assoc_new dll_rb_assoc_new
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 #define rb_cObject (*dll_rb_cObject)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 #define rb_check_type dll_rb_check_type
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 #define rb_class_path dll_rb_class_path
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 #define rb_data_object_alloc dll_rb_data_object_alloc
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 #define rb_define_class_under dll_rb_define_class_under
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 #define rb_define_const dll_rb_define_const
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 #define rb_define_global_function dll_rb_define_global_function
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100 #define rb_define_method dll_rb_define_method
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 #define rb_define_module dll_rb_define_module
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 #define rb_define_module_function dll_rb_define_module_function
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 #define rb_define_singleton_method dll_rb_define_singleton_method
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 #define rb_define_virtual_variable dll_rb_define_virtual_variable
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105 #define rb_stdout (*dll_rb_stdout)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 #define rb_eArgError (*dll_rb_eArgError)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 #define rb_eIndexError (*dll_rb_eIndexError)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108 #define rb_eRuntimeError (*dll_rb_eRuntimeError)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 #define rb_eStandardError (*dll_rb_eStandardError)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 #define rb_eval_string_protect dll_rb_eval_string_protect
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111 #define rb_global_variable dll_rb_global_variable
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 #define rb_hash_aset dll_rb_hash_aset
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 #define rb_hash_new dll_rb_hash_new
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 #define rb_inspect dll_rb_inspect
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 #define rb_int2inum dll_rb_int2inum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 #define rb_lastline_get dll_rb_lastline_get
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117 #define rb_lastline_set dll_rb_lastline_set
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 #define rb_load_protect dll_rb_load_protect
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119 #define rb_num2long dll_rb_num2long
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 #define rb_num2ulong dll_rb_num2ulong
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121 #define rb_obj_alloc dll_rb_obj_alloc
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 #define rb_obj_as_string dll_rb_obj_as_string
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123 #define rb_obj_id dll_rb_obj_id
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 #define rb_raise dll_rb_raise
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 #define rb_str2cstr dll_rb_str2cstr
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 #define rb_str_cat dll_rb_str_cat
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 #define rb_str_concat dll_rb_str_concat
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 #define rb_str_new dll_rb_str_new
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 #define rb_str_new2 dll_rb_str_new2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 #define ruby_errinfo (*dll_ruby_errinfo)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 #define ruby_init dll_ruby_init
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 #define ruby_init_loadpath dll_ruby_init_loadpath
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 # define rb_w32_snprintf dll_rb_w32_snprintf
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 * Pointers for dynamic link
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 static VALUE (*dll_rb_assoc_new) (VALUE, VALUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141 static VALUE *dll_rb_cFalseClass;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 static VALUE *dll_rb_cFixnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143 static VALUE *dll_rb_cNilClass;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144 static VALUE *dll_rb_cObject;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145 static VALUE *dll_rb_cSymbol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 static VALUE *dll_rb_cTrueClass;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147 static void (*dll_rb_check_type) (VALUE,int);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148 static VALUE (*dll_rb_class_path) (VALUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 static VALUE (*dll_rb_data_object_alloc) (VALUE, void*, RUBY_DATA_FUNC, RUBY_DATA_FUNC);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150 static VALUE (*dll_rb_define_class_under) (VALUE, const char*, VALUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151 static void (*dll_rb_define_const) (VALUE,const char*,VALUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152 static void (*dll_rb_define_global_function) (const char*,VALUE(*)(),int);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153 static void (*dll_rb_define_method) (VALUE,const char*,VALUE(*)(),int);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154 static VALUE (*dll_rb_define_module) (const char*);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155 static void (*dll_rb_define_module_function) (VALUE,const char*,VALUE(*)(),int);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156 static void (*dll_rb_define_singleton_method) (VALUE,const char*,VALUE(*)(),int);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157 static void (*dll_rb_define_virtual_variable) (const char*,VALUE(*)(),void(*)());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158 static VALUE *dll_rb_stdout;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 static VALUE *dll_rb_eArgError;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160 static VALUE *dll_rb_eIndexError;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 static VALUE *dll_rb_eRuntimeError;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162 static VALUE *dll_rb_eStandardError;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163 static VALUE (*dll_rb_eval_string_protect) (const char*, int*);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 static void (*dll_rb_global_variable) (VALUE*);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 static VALUE (*dll_rb_hash_aset) (VALUE, VALUE, VALUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166 static VALUE (*dll_rb_hash_new) (void);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167 static VALUE (*dll_rb_inspect) (VALUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168 static VALUE (*dll_rb_int2inum) (long);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169 static VALUE (*dll_rb_int2inum) (long);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170 static VALUE (*dll_rb_lastline_get) (void);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 static void (*dll_rb_lastline_set) (VALUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 static void (*dll_rb_load_protect) (VALUE, int, int*);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173 static long (*dll_rb_num2long) (VALUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174 static unsigned long (*dll_rb_num2ulong) (VALUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175 static VALUE (*dll_rb_obj_alloc) (VALUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176 static VALUE (*dll_rb_obj_as_string) (VALUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177 static VALUE (*dll_rb_obj_id) (VALUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178 static void (*dll_rb_raise) (VALUE, const char*, ...);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179 static char *(*dll_rb_str2cstr) (VALUE,int*);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180 static VALUE (*dll_rb_str_cat) (VALUE, const char*, long);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181 static VALUE (*dll_rb_str_concat) (VALUE, VALUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182 static VALUE (*dll_rb_str_new) (const char*, long);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183 static VALUE (*dll_rb_str_new2) (const char*);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184 static VALUE *dll_ruby_errinfo;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185 static void (*dll_ruby_init) (void);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186 static void (*dll_ruby_init_loadpath) (void);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187 #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188 static int (*dll_rb_w32_snprintf)(char*, size_t, const char*, ...);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
189 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
191 static HINSTANCE hinstRuby = 0; /* Instance of ruby.dll */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
192
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
194 * Table of name to function pointer of python.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
196 #define RUBY_PROC FARPROC
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197 static struct
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
198 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
199 char *name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
200 RUBY_PROC *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
201 } ruby_funcname_table[] =
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
202 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
203 {"rb_assoc_new", (RUBY_PROC*)&dll_rb_assoc_new},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
204 {"rb_cFalseClass", (RUBY_PROC*)&dll_rb_cFalseClass},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
205 {"rb_cFixnum", (RUBY_PROC*)&dll_rb_cFixnum},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206 {"rb_cNilClass", (RUBY_PROC*)&dll_rb_cNilClass},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207 {"rb_cObject", (RUBY_PROC*)&dll_rb_cObject},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
208 {"rb_cSymbol", (RUBY_PROC*)&dll_rb_cSymbol},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
209 {"rb_cTrueClass", (RUBY_PROC*)&dll_rb_cTrueClass},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
210 {"rb_check_type", (RUBY_PROC*)&dll_rb_check_type},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211 {"rb_class_path", (RUBY_PROC*)&dll_rb_class_path},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
212 {"rb_data_object_alloc", (RUBY_PROC*)&dll_rb_data_object_alloc},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
213 {"rb_define_class_under", (RUBY_PROC*)&dll_rb_define_class_under},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
214 {"rb_define_const", (RUBY_PROC*)&dll_rb_define_const},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
215 {"rb_define_global_function", (RUBY_PROC*)&dll_rb_define_global_function},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
216 {"rb_define_method", (RUBY_PROC*)&dll_rb_define_method},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
217 {"rb_define_module", (RUBY_PROC*)&dll_rb_define_module},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
218 {"rb_define_module_function", (RUBY_PROC*)&dll_rb_define_module_function},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
219 {"rb_define_singleton_method", (RUBY_PROC*)&dll_rb_define_singleton_method},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
220 {"rb_define_virtual_variable", (RUBY_PROC*)&dll_rb_define_virtual_variable},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
221 {"rb_stdout", (RUBY_PROC*)&dll_rb_stdout},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
222 {"rb_eArgError", (RUBY_PROC*)&dll_rb_eArgError},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
223 {"rb_eIndexError", (RUBY_PROC*)&dll_rb_eIndexError},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
224 {"rb_eRuntimeError", (RUBY_PROC*)&dll_rb_eRuntimeError},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
225 {"rb_eStandardError", (RUBY_PROC*)&dll_rb_eStandardError},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
226 {"rb_eval_string_protect", (RUBY_PROC*)&dll_rb_eval_string_protect},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
227 {"rb_global_variable", (RUBY_PROC*)&dll_rb_global_variable},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228 {"rb_hash_aset", (RUBY_PROC*)&dll_rb_hash_aset},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
229 {"rb_hash_new", (RUBY_PROC*)&dll_rb_hash_new},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
230 {"rb_inspect", (RUBY_PROC*)&dll_rb_inspect},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
231 {"rb_int2inum", (RUBY_PROC*)&dll_rb_int2inum},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232 {"rb_lastline_get", (RUBY_PROC*)&dll_rb_lastline_get},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
233 {"rb_lastline_set", (RUBY_PROC*)&dll_rb_lastline_set},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234 {"rb_load_protect", (RUBY_PROC*)&dll_rb_load_protect},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
235 {"rb_num2long", (RUBY_PROC*)&dll_rb_num2long},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236 {"rb_num2ulong", (RUBY_PROC*)&dll_rb_num2ulong},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
237 {"rb_obj_alloc", (RUBY_PROC*)&dll_rb_obj_alloc},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
238 {"rb_obj_as_string", (RUBY_PROC*)&dll_rb_obj_as_string},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
239 {"rb_obj_id", (RUBY_PROC*)&dll_rb_obj_id},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240 {"rb_raise", (RUBY_PROC*)&dll_rb_raise},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
241 {"rb_str2cstr", (RUBY_PROC*)&dll_rb_str2cstr},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
242 {"rb_str_cat", (RUBY_PROC*)&dll_rb_str_cat},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
243 {"rb_str_concat", (RUBY_PROC*)&dll_rb_str_concat},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
244 {"rb_str_new", (RUBY_PROC*)&dll_rb_str_new},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
245 {"rb_str_new2", (RUBY_PROC*)&dll_rb_str_new2},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246 {"ruby_errinfo", (RUBY_PROC*)&dll_ruby_errinfo},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
247 {"ruby_init", (RUBY_PROC*)&dll_ruby_init},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248 {"ruby_init_loadpath", (RUBY_PROC*)&dll_ruby_init_loadpath},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
249 #if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 18
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250 {"rb_w32_snprintf", (RUBY_PROC*)&dll_rb_w32_snprintf},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
251 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252 {"", NULL},
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
253 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
254
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
255 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
256 * Free ruby.dll
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
257 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
258 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
259 end_dynamic_ruby()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
260 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
261 if (hinstRuby)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
262 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
263 FreeLibrary(hinstRuby);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264 hinstRuby = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
265 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
266 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
267
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
268 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
269 * Load library and get all pointers.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
270 * Parameter 'libname' provides name of DLL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271 * Return OK or FAIL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
274 ruby_runtime_link_init(char *libname, int verbose)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
275 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
276 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
277
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
278 if (hinstRuby)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
279 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
280 hinstRuby = LoadLibrary(libname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
281 if (!hinstRuby)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
282 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
283 if (verbose)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
284 EMSG2(_(e_loadlib), libname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
285 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
286 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
287
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
288 for (i = 0; ruby_funcname_table[i].ptr; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
289 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
290 if (!(*ruby_funcname_table[i].ptr = GetProcAddress(hinstRuby,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
291 ruby_funcname_table[i].name)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
292 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
293 FreeLibrary(hinstRuby);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
294 hinstRuby = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
295 if (verbose)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
296 EMSG2(_(e_loadfunc), ruby_funcname_table[i].name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
297 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
298 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
299 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
300 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
301 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
302
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
303 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
304 * If ruby is enabled (there is installed ruby on Windows system) return TRUE,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
305 * else FALSE.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
306 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
307 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
308 ruby_enabled(verbose)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
309 int verbose;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
310 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
311 return ruby_runtime_link_init(DYNAMIC_RUBY_DLL, verbose) == OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
312 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
313 #endif /* defined(DYNAMIC_RUBY) || defined(PROTO) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
314
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
315 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
316 ruby_end()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
317 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
318 #ifdef DYNAMIC_RUBY
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
319 end_dynamic_ruby();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
320 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
321 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
322
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
323 void ex_ruby(exarg_T *eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
324 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
325 int state;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
326 char *script = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
327
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
328 script = script_get(eap, eap->arg);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
329 if (!eap->skip && ensure_ruby_initialized())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
330 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
331 if (script == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
332 rb_eval_string_protect((char *)eap->arg, &state);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
333 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
334 rb_eval_string_protect(script, &state);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
335 if (state)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
336 error_print(state);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
337 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
338 vim_free(script);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
339 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
340
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
341 void ex_rubydo(exarg_T *eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
342 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
343 int state;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
344 linenr_T i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
345
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
346 if (ensure_ruby_initialized())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
347 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
348 if (u_save(eap->line1 - 1, eap->line2 + 1) != OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
349 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
350 for (i = eap->line1; i <= eap->line2; i++) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
351 VALUE line, oldline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
352
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
353 line = oldline = rb_str_new2(ml_get(i));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
354 rb_lastline_set(line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
355 rb_eval_string_protect((char *) eap->arg, &state);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
356 if (state) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
357 error_print(state);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
358 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
359 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
360 line = rb_lastline_get();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
361 if (!NIL_P(line)) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
362 if (TYPE(line) != T_STRING) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
363 EMSG("E265: $_ must be an instance of String");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
364 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
365 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
366 ml_replace(i, (char_u *) STR2CSTR(line), 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
367 changed();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
368 #ifdef SYNTAX_HL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
369 syn_changed(i); /* recompute syntax hl. for this line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
370 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
371 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
372 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
373 check_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
374 update_curbuf(NOT_VALID);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
375 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
376 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
377
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
378 void ex_rubyfile(exarg_T *eap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
379 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
380 int state;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
381
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
382 if (ensure_ruby_initialized())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
383 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
384 rb_load_protect(rb_str_new2((char *) eap->arg), 0, &state);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
385 if (state) error_print(state);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
386 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
387 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
388
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
389 void ruby_buffer_free(buf_T *buf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
390 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
391 if (buf->ruby_ref) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
392 rb_hash_aset(objtbl, rb_obj_id((VALUE) buf->ruby_ref), Qnil);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
393 RDATA(buf->ruby_ref)->data = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
394 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
395 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
396
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
397 void ruby_window_free(win_T *win)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
398 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
399 if (win->ruby_ref) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
400 rb_hash_aset(objtbl, rb_obj_id((VALUE) win->ruby_ref), Qnil);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
401 RDATA(win->ruby_ref)->data = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
402 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
403 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
404
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
405 static int ensure_ruby_initialized(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
406 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
407 if (!ruby_initialized)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
408 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
409 #ifdef DYNAMIC_RUBY
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
410 if (ruby_enabled(TRUE))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
411 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
412 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
413 ruby_init();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
414 ruby_init_loadpath();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
415 ruby_io_init();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
416 ruby_vim_init();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
417 ruby_initialized = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
418 #ifdef DYNAMIC_RUBY
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
419 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
420 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
421 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
422 EMSG(_("E266: Sorry, this command is disabled, the Ruby library could not be loaded."));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
423 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
424 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
425 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
426 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
427 return ruby_initialized;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
428 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
429
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
430 static void error_print(int state)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
431 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
432 #ifndef DYNAMIC_RUBY
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
433 RUBYEXTERN VALUE ruby_errinfo;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
434 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
435 VALUE eclass;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
436 VALUE einfo;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
437 char buff[BUFSIZ];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
438
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
439 #define TAG_RETURN 0x1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
440 #define TAG_BREAK 0x2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
441 #define TAG_NEXT 0x3
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
442 #define TAG_RETRY 0x4
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
443 #define TAG_REDO 0x5
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
444 #define TAG_RAISE 0x6
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
445 #define TAG_THROW 0x7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
446 #define TAG_FATAL 0x8
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
447 #define TAG_MASK 0xf
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
448
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
449 switch (state) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
450 case TAG_RETURN:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
451 EMSG("E267: unexpected return");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
452 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
453 case TAG_NEXT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
454 EMSG("E268: unexpected next");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
455 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
456 case TAG_BREAK:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
457 EMSG("E269: unexpected break");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
458 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
459 case TAG_REDO:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
460 EMSG("E270: unexpected redo");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
461 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
462 case TAG_RETRY:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
463 EMSG("E271: retry outside of rescue clause");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
464 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
465 case TAG_RAISE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
466 case TAG_FATAL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
467 eclass = CLASS_OF(ruby_errinfo);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
468 einfo = rb_obj_as_string(ruby_errinfo);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
469 if (eclass == rb_eRuntimeError && RSTRING(einfo)->len == 0) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
470 EMSG("E272: unhandled exception");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
471 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
472 else {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
473 VALUE epath;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
474 char *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
475
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
476 epath = rb_class_path(eclass);
272
ddada568db54 updated for version 7.0073
vimboss
parents: 7
diff changeset
477 vim_snprintf(buff, BUFSIZ, "%s: %s",
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
478 RSTRING(epath)->ptr, RSTRING(einfo)->ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
479 p = strchr(buff, '\n');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
480 if (p) *p = '\0';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
481 EMSG(buff);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
482 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
483 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
484 default:
272
ddada568db54 updated for version 7.0073
vimboss
parents: 7
diff changeset
485 vim_snprintf(buff, BUFSIZ, _("E273: unknown longjmp status %d"), state);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
486 EMSG(buff);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
487 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
488 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
489 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
490
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
491 static VALUE vim_message(VALUE self, VALUE str)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
492 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
493 char *buff, *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
494
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
495 str = rb_obj_as_string(str);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
496 buff = ALLOCA_N(char, RSTRING(str)->len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
497 strcpy(buff, RSTRING(str)->ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
498 p = strchr(buff, '\n');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
499 if (p) *p = '\0';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
500 MSG(buff);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
501 return Qnil;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
502 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
503
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
504 static VALUE vim_set_option(VALUE self, VALUE str)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
505 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
506 do_set((char_u *)STR2CSTR(str), 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
507 update_screen(NOT_VALID);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
508 return Qnil;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
509 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
510
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
511 static VALUE vim_command(VALUE self, VALUE str)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
512 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
513 do_cmdline_cmd((char_u *)STR2CSTR(str));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
514 return Qnil;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
515 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
516
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
517 static VALUE vim_evaluate(VALUE self, VALUE str)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
518 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
519 #ifdef FEAT_EVAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
520 char_u *value = eval_to_string((char_u *)STR2CSTR(str), NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
521
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
522 if (value)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
523 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
524 VALUE val = rb_str_new2(value);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
525 vim_free(value);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
526 return val;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
527 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
528 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
529 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
530 return Qnil;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
531 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
532
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
533 static VALUE buffer_new(buf_T *buf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
534 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
535 if (buf->ruby_ref) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
536 return (VALUE) buf->ruby_ref;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
537 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
538 else {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
539 VALUE obj = Data_Wrap_Struct(cBuffer, 0, 0, buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
540 buf->ruby_ref = (void *) obj;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
541 rb_hash_aset(objtbl, rb_obj_id(obj), obj);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
542 return obj;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
543 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
544 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
545
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
546 static buf_T *get_buf(VALUE obj)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
547 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
548 buf_T *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
549
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
550 Data_Get_Struct(obj, buf_T, buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
551 if (buf == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
552 rb_raise(eDeletedBufferError, "attempt to refer to deleted buffer");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
553 return buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
554 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
555
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
556 static VALUE buffer_s_current()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
557 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
558 return buffer_new(curbuf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
559 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
560
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
561 static VALUE buffer_s_count()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
562 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
563 buf_T *b;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
564 int n = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
565
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
566 for (b = firstbuf; b; b = b->b_next) n++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
567 return INT2NUM(n);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
568 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
569
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
570 static VALUE buffer_s_aref(VALUE self, VALUE num)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
571 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
572 buf_T *b;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
573 int n = NUM2INT(num);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
574
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
575 for (b = firstbuf; b; b = b->b_next, --n) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
576 if (n == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
577 return buffer_new(b);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
578 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
579 return Qnil;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
580 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
581
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
582 static VALUE buffer_name(VALUE self)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
583 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
584 buf_T *buf = get_buf(self);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
585
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
586 return buf->b_ffname ? rb_str_new2(buf->b_ffname) : Qnil;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
587 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
588
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
589 static VALUE buffer_number(VALUE self)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
590 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
591 buf_T *buf = get_buf(self);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
592
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
593 return INT2NUM(buf->b_fnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
594 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
595
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
596 static VALUE buffer_count(VALUE self)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
597 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
598 buf_T *buf = get_buf(self);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
599
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
600 return INT2NUM(buf->b_ml.ml_line_count);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
601 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
602
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
603 static VALUE buffer_aref(VALUE self, VALUE num)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
604 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
605 buf_T *buf = get_buf(self);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
606 long n = NUM2LONG(num);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
607
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
608 if (n > 0 && n <= buf->b_ml.ml_line_count) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
609 char *line = ml_get_buf(buf, n, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
610 return line ? rb_str_new2(line) : Qnil;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
611 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
612 else {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
613 rb_raise(rb_eIndexError, "index %d out of buffer", n);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
614 return Qnil; /* For stop warning */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
615 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
616 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
617
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
618 static VALUE buffer_aset(VALUE self, VALUE num, VALUE str)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
619 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
620 buf_T *buf = get_buf(self);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
621 buf_T *savebuf = curbuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
622 char *line = STR2CSTR(str);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
623 long n = NUM2LONG(num);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
624
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
625 if (n > 0 && n <= buf->b_ml.ml_line_count && line != NULL) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
626 curbuf = buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
627 if (u_savesub(n) == OK) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
628 ml_replace(n, (char_u *) line, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
629 changed();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
630 #ifdef SYNTAX_HL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
631 syn_changed(n); /* recompute syntax hl. for this line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
632 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
633 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
634 curbuf = savebuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
635 update_curbuf(NOT_VALID);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
636 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
637 else {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
638 rb_raise(rb_eIndexError, "index %d out of buffer", n);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
639 return Qnil; /* For stop warning */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
640 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
641 return str;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
642 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
643
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
644 static VALUE buffer_delete(VALUE self, VALUE num)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
645 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
646 buf_T *buf = get_buf(self);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
647 buf_T *savebuf = curbuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
648 long n = NUM2LONG(num);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
649
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
650 if (n > 0 && n <= buf->b_ml.ml_line_count) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
651 curbuf = buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
652 if (u_savedel(n, 1) == OK) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
653 mark_adjust(n, n, MAXLNUM, -1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
654 ml_delete(n, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
655 changed();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
656 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
657 curbuf = savebuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
658 update_curbuf(NOT_VALID);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
659 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
660 else {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
661 rb_raise(rb_eIndexError, "index %d out of buffer", n);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
662 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
663 return Qnil;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
664 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
665
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
666 static VALUE buffer_append(VALUE self, VALUE num, VALUE str)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
667 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
668 buf_T *buf = get_buf(self);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
669 buf_T *savebuf = curbuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
670 char *line = STR2CSTR(str);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
671 long n = NUM2LONG(num);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
672
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
673 if (n >= 0 && n <= buf->b_ml.ml_line_count && line != NULL) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
674 curbuf = buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
675 if (u_inssub(n + 1) == OK) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
676 mark_adjust(n + 1, MAXLNUM, 1L, 0L);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
677 ml_append(n, (char_u *) line, (colnr_T) 0, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
678 changed();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
679 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
680 curbuf = savebuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
681 update_curbuf(NOT_VALID);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
682 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
683 else {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
684 rb_raise(rb_eIndexError, "index %d out of buffer", n);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
685 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
686 return str;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
687 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
688
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
689 static VALUE window_new(win_T *win)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
690 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
691 if (win->ruby_ref) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
692 return (VALUE) win->ruby_ref;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
693 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
694 else {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
695 VALUE obj = Data_Wrap_Struct(cVimWindow, 0, 0, win);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
696 win->ruby_ref = (void *) obj;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
697 rb_hash_aset(objtbl, rb_obj_id(obj), obj);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
698 return obj;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
699 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
700 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
701
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
702 static win_T *get_win(VALUE obj)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
703 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
704 win_T *win;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
705
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
706 Data_Get_Struct(obj, win_T, win);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
707 if (win == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
708 rb_raise(eDeletedWindowError, "attempt to refer to deleted window");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
709 return win;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
710 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
711
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
712 static VALUE window_s_current()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
713 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
714 return window_new(curwin);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
715 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
716
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
717 static VALUE window_s_count()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
718 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
719 #ifdef FEAT_WINDOWS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
720 win_T *w;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
721 int n = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
722
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
723 for (w = firstwin; w; w = w->w_next)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
724 n++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
725 return INT2NUM(n);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
726 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
727 return INT2NUM(1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
728 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
729 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
730
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
731 static VALUE window_s_aref(VALUE self, VALUE num)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
732 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
733 win_T *w;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
734 int n = NUM2INT(num);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
735
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
736 #ifndef FEAT_WINDOWS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
737 w = curwin;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
738 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
739 for (w = firstwin; w != NULL; w = w->w_next, --n)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
740 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
741 if (n == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
742 return window_new(w);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
743 return Qnil;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
744 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
745
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
746 static VALUE window_buffer(VALUE self)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
747 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
748 win_T *win = get_win(self);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
749
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
750 return buffer_new(win->w_buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
751 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
752
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
753 static VALUE window_height(VALUE self)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
754 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
755 win_T *win = get_win(self);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
756
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
757 return INT2NUM(win->w_height);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
758 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
759
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
760 static VALUE window_set_height(VALUE self, VALUE height)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
761 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
762 win_T *win = get_win(self);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
763 win_T *savewin = curwin;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
764
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
765 curwin = win;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
766 win_setheight(NUM2INT(height));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
767 curwin = savewin;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
768 return height;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
769 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
770
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
771 static VALUE window_cursor(VALUE self)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
772 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
773 win_T *win = get_win(self);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
774
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
775 return rb_assoc_new(INT2NUM(win->w_cursor.lnum), INT2NUM(win->w_cursor.col));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
776 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
777
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
778 static VALUE window_set_cursor(VALUE self, VALUE pos)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
779 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
780 VALUE lnum, col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
781 win_T *win = get_win(self);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
782
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
783 Check_Type(pos, T_ARRAY);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
784 if (RARRAY(pos)->len != 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
785 rb_raise(rb_eArgError, "array length must be 2");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
786 lnum = RARRAY(pos)->ptr[0];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
787 col = RARRAY(pos)->ptr[1];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
788 win->w_cursor.lnum = NUM2LONG(lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
789 win->w_cursor.col = NUM2UINT(col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
790 check_cursor(); /* put cursor on an existing line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
791 update_screen(NOT_VALID);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
792 return Qnil;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
793 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
794
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
795 static VALUE f_p(int argc, VALUE *argv, VALUE self)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
796 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
797 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
798 VALUE str = rb_str_new("", 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
799
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
800 for (i = 0; i < argc; i++) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
801 if (i > 0) rb_str_cat(str, ", ", 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
802 rb_str_concat(str, rb_inspect(argv[i]));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
803 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
804 MSG(RSTRING(str)->ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
805 return Qnil;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
806 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
807
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
808 static void ruby_io_init(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
809 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
810 #ifndef DYNAMIC_RUBY
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
811 RUBYEXTERN VALUE rb_stdout;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
812 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
813
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
814 rb_stdout = rb_obj_alloc(rb_cObject);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
815 rb_define_singleton_method(rb_stdout, "write", vim_message, 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
816 rb_define_global_function("p", f_p, -1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
817 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
818
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
819 static void ruby_vim_init(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
820 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
821 objtbl = rb_hash_new();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
822 rb_global_variable(&objtbl);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
823
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
824 mVIM = rb_define_module("VIM");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
825 rb_define_const(mVIM, "VERSION_MAJOR", INT2NUM(VIM_VERSION_MAJOR));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
826 rb_define_const(mVIM, "VERSION_MINOR", INT2NUM(VIM_VERSION_MINOR));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
827 rb_define_const(mVIM, "VERSION_BUILD", INT2NUM(VIM_VERSION_BUILD));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
828 rb_define_const(mVIM, "VERSION_PATCHLEVEL", INT2NUM(VIM_VERSION_PATCHLEVEL));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
829 rb_define_const(mVIM, "VERSION_SHORT", rb_str_new2(VIM_VERSION_SHORT));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
830 rb_define_const(mVIM, "VERSION_MEDIUM", rb_str_new2(VIM_VERSION_MEDIUM));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
831 rb_define_const(mVIM, "VERSION_LONG", rb_str_new2(VIM_VERSION_LONG));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
832 rb_define_const(mVIM, "VERSION_LONG_DATE", rb_str_new2(VIM_VERSION_LONG_DATE));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
833 rb_define_module_function(mVIM, "message", vim_message, 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
834 rb_define_module_function(mVIM, "set_option", vim_set_option, 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
835 rb_define_module_function(mVIM, "command", vim_command, 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
836 rb_define_module_function(mVIM, "evaluate", vim_evaluate, 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
837
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
838 eDeletedBufferError = rb_define_class_under(mVIM, "DeletedBufferError",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
839 rb_eStandardError);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
840 eDeletedWindowError = rb_define_class_under(mVIM, "DeletedWindowError",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
841 rb_eStandardError);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
842
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
843 cBuffer = rb_define_class_under(mVIM, "Buffer", rb_cObject);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
844 rb_define_singleton_method(cBuffer, "current", buffer_s_current, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
845 rb_define_singleton_method(cBuffer, "count", buffer_s_count, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
846 rb_define_singleton_method(cBuffer, "[]", buffer_s_aref, 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
847 rb_define_method(cBuffer, "name", buffer_name, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
848 rb_define_method(cBuffer, "number", buffer_number, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
849 rb_define_method(cBuffer, "count", buffer_count, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
850 rb_define_method(cBuffer, "length", buffer_count, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
851 rb_define_method(cBuffer, "[]", buffer_aref, 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
852 rb_define_method(cBuffer, "[]=", buffer_aset, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
853 rb_define_method(cBuffer, "delete", buffer_delete, 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
854 rb_define_method(cBuffer, "append", buffer_append, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
855
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
856 cVimWindow = rb_define_class_under(mVIM, "Window", rb_cObject);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
857 rb_define_singleton_method(cVimWindow, "current", window_s_current, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
858 rb_define_singleton_method(cVimWindow, "count", window_s_count, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
859 rb_define_singleton_method(cVimWindow, "[]", window_s_aref, 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
860 rb_define_method(cVimWindow, "buffer", window_buffer, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
861 rb_define_method(cVimWindow, "height", window_height, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
862 rb_define_method(cVimWindow, "height=", window_set_height, 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
863 rb_define_method(cVimWindow, "cursor", window_cursor, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
864 rb_define_method(cVimWindow, "cursor=", window_set_cursor, 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
865
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
866 rb_define_virtual_variable("$curbuf", buffer_s_current, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
867 rb_define_virtual_variable("$curwin", window_s_current, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
868 }