1 To: [email protected] |
|
2 Subject: Patch 7.2.266 |
|
3 Fcc: outbox |
|
4 From: Bram Moolenaar <[email protected]> |
|
5 Mime-Version: 1.0 |
|
6 Content-Type: text/plain; charset=UTF-8 |
|
7 Content-Transfer-Encoding: 8bit |
|
8 ------------ |
|
9 |
|
10 Patch 7.2.266 |
|
11 Problem: When an expression abbreviation is triggered, the typed character |
|
12 is unknown. |
|
13 Solution: Make the typed character available in v:char. |
|
14 Files: runtime/doc/map.txt, src/eval.c, src/getchar.c, src/ops.c, |
|
15 src/proto/eval.pro |
|
16 |
|
17 |
|
18 *** ../vim-7.2.265/runtime/doc/map.txt 2008-08-09 19:36:49.000000000 +0200 |
|
19 --- runtime/doc/map.txt 2009-09-23 19:39:19.000000000 +0200 |
|
20 *************** |
|
21 *** 224,229 **** |
|
22 --- 224,233 ---- |
|
23 The result of the InsertDot() function will be inserted. It could check the |
|
24 text before the cursor and start omni completion when some condition is met. |
|
25 |
|
26 + For abbreviations |v:char| is set to the character that was typed to trigger |
|
27 + the abbreviation. You can use this to decide how to expand the {lhs}. You |
|
28 + can't change v:char and you should not insert it. |
|
29 + |
|
30 Be very careful about side effects! The expression is evaluated while |
|
31 obtaining characters, you may very well make the command dysfunctional. |
|
32 For this reason the following is blocked: |
|
33 *** ../vim-7.2.265/src/eval.c 2009-06-03 14:25:47.000000000 +0200 |
|
34 --- src/eval.c 2009-09-23 19:36:32.000000000 +0200 |
|
35 *************** |
|
36 *** 18101,18106 **** |
|
37 --- 18101,18131 ---- |
|
38 } |
|
39 |
|
40 /* |
|
41 + * Set v:char to character "c". |
|
42 + */ |
|
43 + void |
|
44 + set_vim_var_char(c) |
|
45 + int c; |
|
46 + { |
|
47 + #ifdef FEAT_MBYTE |
|
48 + char_u buf[MB_MAXBYTES]; |
|
49 + #else |
|
50 + char_u buf[2]; |
|
51 + #endif |
|
52 + |
|
53 + #ifdef FEAT_MBYTE |
|
54 + if (has_mbyte) |
|
55 + buf[(*mb_char2bytes)(c, buf)] = NUL; |
|
56 + else |
|
57 + #endif |
|
58 + { |
|
59 + buf[0] = c; |
|
60 + buf[1] = NUL; |
|
61 + } |
|
62 + set_vim_var_string(VV_CHAR, buf, -1); |
|
63 + } |
|
64 + |
|
65 + /* |
|
66 * Set v:count to "count" and v:count1 to "count1". |
|
67 * When "set_prevcount" is TRUE first set v:prevcount from v:count. |
|
68 */ |
|
69 *** ../vim-7.2.265/src/getchar.c 2009-07-14 13:44:43.000000000 +0200 |
|
70 --- src/getchar.c 2009-09-23 19:35:54.000000000 +0200 |
|
71 *************** |
|
72 *** 129,135 **** |
|
73 static void validate_maphash __ARGS((void)); |
|
74 static void showmap __ARGS((mapblock_T *mp, int local)); |
|
75 #ifdef FEAT_EVAL |
|
76 ! static char_u *eval_map_expr __ARGS((char_u *str)); |
|
77 #endif |
|
78 |
|
79 /* |
|
80 --- 129,135 ---- |
|
81 static void validate_maphash __ARGS((void)); |
|
82 static void showmap __ARGS((mapblock_T *mp, int local)); |
|
83 #ifdef FEAT_EVAL |
|
84 ! static char_u *eval_map_expr __ARGS((char_u *str, int c)); |
|
85 #endif |
|
86 |
|
87 /* |
|
88 *************** |
|
89 *** 2446,2452 **** |
|
90 if (tabuf.typebuf_valid) |
|
91 { |
|
92 vgetc_busy = 0; |
|
93 ! s = eval_map_expr(mp->m_str); |
|
94 vgetc_busy = save_vgetc_busy; |
|
95 } |
|
96 else |
|
97 --- 2446,2452 ---- |
|
98 if (tabuf.typebuf_valid) |
|
99 { |
|
100 vgetc_busy = 0; |
|
101 ! s = eval_map_expr(mp->m_str, NUL); |
|
102 vgetc_busy = save_vgetc_busy; |
|
103 } |
|
104 else |
|
105 *************** |
|
106 *** 4367,4375 **** |
|
107 * abbreviation, but is not inserted into the input stream. |
|
108 */ |
|
109 j = 0; |
|
110 - /* special key code, split up */ |
|
111 if (c != Ctrl_RSB) |
|
112 { |
|
113 if (IS_SPECIAL(c) || c == K_SPECIAL) |
|
114 { |
|
115 tb[j++] = K_SPECIAL; |
|
116 --- 4367,4375 ---- |
|
117 * abbreviation, but is not inserted into the input stream. |
|
118 */ |
|
119 j = 0; |
|
120 if (c != Ctrl_RSB) |
|
121 { |
|
122 + /* special key code, split up */ |
|
123 if (IS_SPECIAL(c) || c == K_SPECIAL) |
|
124 { |
|
125 tb[j++] = K_SPECIAL; |
|
126 *************** |
|
127 *** 4398,4404 **** |
|
128 } |
|
129 #ifdef FEAT_EVAL |
|
130 if (mp->m_expr) |
|
131 ! s = eval_map_expr(mp->m_str); |
|
132 else |
|
133 #endif |
|
134 s = mp->m_str; |
|
135 --- 4398,4404 ---- |
|
136 } |
|
137 #ifdef FEAT_EVAL |
|
138 if (mp->m_expr) |
|
139 ! s = eval_map_expr(mp->m_str, c); |
|
140 else |
|
141 #endif |
|
142 s = mp->m_str; |
|
143 *************** |
|
144 *** 4434,4441 **** |
|
145 * special characters. |
|
146 */ |
|
147 static char_u * |
|
148 ! eval_map_expr(str) |
|
149 char_u *str; |
|
150 { |
|
151 char_u *res; |
|
152 char_u *p; |
|
153 --- 4434,4442 ---- |
|
154 * special characters. |
|
155 */ |
|
156 static char_u * |
|
157 ! eval_map_expr(str, c) |
|
158 char_u *str; |
|
159 + int c; /* NUL or typed character for abbreviation */ |
|
160 { |
|
161 char_u *res; |
|
162 char_u *p; |
|
163 *************** |
|
164 *** 4452,4457 **** |
|
165 --- 4453,4459 ---- |
|
166 #ifdef FEAT_EX_EXTRA |
|
167 ++ex_normal_lock; |
|
168 #endif |
|
169 + set_vim_var_char(c); /* set v:char to the typed character */ |
|
170 save_cursor = curwin->w_cursor; |
|
171 p = eval_to_string(str, NULL, FALSE); |
|
172 --textlock; |
|
173 *** ../vim-7.2.265/src/ops.c 2009-07-01 18:04:30.000000000 +0200 |
|
174 --- src/ops.c 2009-09-23 19:11:40.000000000 +0200 |
|
175 *************** |
|
176 *** 4473,4483 **** |
|
177 int use_sandbox = was_set_insecurely((char_u *)"formatexpr", |
|
178 OPT_LOCAL); |
|
179 int r; |
|
180 - #ifdef FEAT_MBYTE |
|
181 - char_u buf[MB_MAXBYTES]; |
|
182 - #else |
|
183 - char_u buf[2]; |
|
184 - #endif |
|
185 |
|
186 /* |
|
187 * Set v:lnum to the first line number and v:count to the number of lines. |
|
188 --- 4473,4478 ---- |
|
189 *************** |
|
190 *** 4485,4501 **** |
|
191 */ |
|
192 set_vim_var_nr(VV_LNUM, lnum); |
|
193 set_vim_var_nr(VV_COUNT, count); |
|
194 ! |
|
195 ! #ifdef FEAT_MBYTE |
|
196 ! if (has_mbyte) |
|
197 ! buf[(*mb_char2bytes)(c, buf)] = NUL; |
|
198 ! else |
|
199 ! #endif |
|
200 ! { |
|
201 ! buf[0] = c; |
|
202 ! buf[1] = NUL; |
|
203 ! } |
|
204 ! set_vim_var_string(VV_CHAR, buf, -1); |
|
205 |
|
206 /* |
|
207 * Evaluate the function. |
|
208 --- 4480,4486 ---- |
|
209 */ |
|
210 set_vim_var_nr(VV_LNUM, lnum); |
|
211 set_vim_var_nr(VV_COUNT, count); |
|
212 ! set_vim_var_char(c); |
|
213 |
|
214 /* |
|
215 * Evaluate the function. |
|
216 *** ../vim-7.2.265/src/proto/eval.pro 2008-11-20 16:11:03.000000000 +0100 |
|
217 --- src/proto/eval.pro 2009-09-23 19:36:30.000000000 +0200 |
|
218 *************** |
|
219 *** 61,66 **** |
|
220 --- 61,67 ---- |
|
221 long get_vim_var_nr __ARGS((int idx)); |
|
222 char_u *get_vim_var_str __ARGS((int idx)); |
|
223 list_T *get_vim_var_list __ARGS((int idx)); |
|
224 + void set_vim_var_char __ARGS((int c)); |
|
225 void set_vcount __ARGS((long count, long count1, int set_prevcount)); |
|
226 void set_vim_var_string __ARGS((int idx, char_u *val, int len)); |
|
227 void set_vim_var_list __ARGS((int idx, list_T *val)); |
|
228 *** ../vim-7.2.265/src/version.c 2009-09-30 13:23:57.000000000 +0200 |
|
229 --- src/version.c 2009-09-30 15:11:29.000000000 +0200 |
|
230 *************** |
|
231 *** 678,679 **** |
|
232 --- 678,681 ---- |
|
233 { /* Add new patch number below this line */ |
|
234 + /**/ |
|
235 + 266, |
|
236 /**/ |
|
237 |
|
238 -- |
|
239 Life would be so much easier if we could just look at the source code. |
|
240 |
|
241 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\ |
|
242 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ |
|
243 \\\ download, build and distribute -- http://www.A-A-P.org /// |
|
244 \\\ help me help AIDS victims -- http://ICCF-Holland.org /// |
|