4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
11 Problem: When an expression abbreviation is triggered, the typed character
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,
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
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.
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.
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
41 + * Set v:char to character "c".
48 + char_u buf[MB_MAXBYTES];
55 + buf[(*mb_char2bytes)(c, buf)] = NUL;
62 + set_vim_var_string(VV_CHAR, buf, -1);
66 * Set v:count to "count" and v:count1 to "count1".
67 * When "set_prevcount" is TRUE first set v:prevcount from v:count.
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
73 static void validate_maphash __ARGS((void));
74 static void showmap __ARGS((mapblock_T *mp, int local));
76 ! static char_u *eval_map_expr __ARGS((char_u *str));
81 static void validate_maphash __ARGS((void));
82 static void showmap __ARGS((mapblock_T *mp, int local));
84 ! static char_u *eval_map_expr __ARGS((char_u *str, int c));
90 if (tabuf.typebuf_valid)
93 ! s = eval_map_expr(mp->m_str);
94 vgetc_busy = save_vgetc_busy;
98 if (tabuf.typebuf_valid)
101 ! s = eval_map_expr(mp->m_str, NUL);
102 vgetc_busy = save_vgetc_busy;
107 * abbreviation, but is not inserted into the input stream.
110 - /* special key code, split up */
113 if (IS_SPECIAL(c) || c == K_SPECIAL)
117 * abbreviation, but is not inserted into the input stream.
122 + /* special key code, split up */
123 if (IS_SPECIAL(c) || c == K_SPECIAL)
131 ! s = eval_map_expr(mp->m_str);
139 ! s = eval_map_expr(mp->m_str, c);
145 * special characters.
154 * special characters.
157 ! eval_map_expr(str, c)
159 + int c; /* NUL or typed character for abbreviation */
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);
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
177 int use_sandbox = was_set_insecurely((char_u *)"formatexpr",
181 - char_u buf[MB_MAXBYTES];
187 * Set v:lnum to the first line number and v:count to the number of lines.
192 set_vim_var_nr(VV_LNUM, lnum);
193 set_vim_var_nr(VV_COUNT, count);
197 ! buf[(*mb_char2bytes)(c, buf)] = NUL;
204 ! set_vim_var_string(VV_CHAR, buf, -1);
207 * Evaluate the function.
210 set_vim_var_nr(VV_LNUM, lnum);
211 set_vim_var_nr(VV_COUNT, count);
212 ! set_vim_var_char(c);
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
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
233 { /* Add new patch number below this line */
239 Life would be so much easier if we could just look at the source code.
241 /// Bram Moolenaar -- Bram@Moolenaar.net -- 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 ///