1 To: vim_dev@googlegroups.com
4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
11 Problem: The InsertCharPre autocommand event is not triggered during
12 completion and when typing several characters quickly.
13 Solution: Also trigger InsertCharPre during completion. Do not read ahead
14 when an InsertCharPre autocommand is defined. (Yasuhiro Matsumoto)
15 Files: src/edit.c, src/fileio.c, src/proto/fileio.pro
18 *** ../vim-7.3.460/src/edit.c 2012-02-04 23:34:57.000000000 +0100
19 --- src/edit.c 2012-02-29 18:17:31.000000000 +0100
23 static void ins_try_si __ARGS((int c));
25 static colnr_T get_nolist_virtcol __ARGS((void));
27 + static char_u *do_insert_char_pre __ARGS((int c));
30 static colnr_T Insstart_textlen; /* length of line when insert started */
31 static colnr_T Insstart_blank_vcol; /* vcol for first inserted blank */
34 * completion: Add to "compl_leader". */
35 if (ins_compl_accept_char(c))
37 ! ins_compl_addleader(c);
42 * completion: Add to "compl_leader". */
43 if (ins_compl_accept_char(c))
46 ! /* Trigger InsertCharPre. */
47 ! char_u *str = do_insert_char_pre(c);
52 ! for (p = str; *p != NUL; mb_ptr_adv(p))
53 ! ins_compl_addleader(PTR2CHAR(p));
58 ! ins_compl_addleader(c);
67 ! /* Trigger the InsertCharPre event. Lock the text to avoid
68 ! * weird things from happening. */
69 ! set_vim_var_char(c);
71 ! if (apply_autocmds(EVENT_INSERTCHARPRE, NULL, NULL,
74 ! /* Get the new value of v:char. If it is more than one
75 ! * character insert it literally. */
76 ! char_u *s = get_vim_var_str(VV_CHAR);
77 ! if (MB_CHARLEN(s) > 1)
79 ! if (stop_arrow() != FAIL)
82 ! AppendToRedobuffLit(s, -1);
90 ! set_vim_var_string(VV_CHAR, NULL, -1);
93 ! /* If the new value is an empty string then don't insert a
102 ! /* Trigger InsertCharPre. */
103 ! char_u *str = do_insert_char_pre(c);
108 ! if (*str != NUL && stop_arrow() != FAIL)
110 ! /* Insert the new value of v:char literally. */
111 ! for (p = str; *p != NUL; mb_ptr_adv(p))
114 ! if (c == CAR || c == K_KENTER || c == NL)
119 ! AppendToRedobuffLit(str, -1);
125 ! /* If the new value is already inserted or an empty string
126 ! * then don't insert any character. */
133 * Don't do this when 'cindent' or 'indentexpr' is set, because we might
134 * need to re-indent at a ':', or any other character (but not what
136 + * Don't do this when there an InsertCharPre autocommand is defined,
137 + * because we need to fire the event for every character.
139 #ifdef USE_ON_FLY_SCROLL
140 dont_scroll = FALSE; /* allow scrolling here */
144 #ifdef FEAT_RIGHTLEFT
147 + #ifdef FEAT_AUTOCMD
148 + && !has_insertcharpre()
152 #define INPUT_BUFLEN 100
157 return curwin->w_virtcol;
160 + #ifdef FEAT_AUTOCMD
162 + * Handle the InsertCharPre autocommand.
163 + * "c" is the character that was typed.
164 + * Return a pointer to allocated memory with the replacement string.
165 + * Return NULL to continue inserting "c".
168 + do_insert_char_pre(c)
173 + /* Return quickly when there is nothing to do. */
174 + if (!has_insertcharpre())
177 + /* Lock the text to avoid weird things from happening. */
179 + set_vim_var_char(c); /* set v:char */
181 + if (apply_autocmds(EVENT_INSERTCHARPRE, NULL, NULL, FALSE, curbuf))
182 + /* Get the new value of v:char. It may be empty or more than one
184 + res = vim_strsave(get_vim_var_str(VV_CHAR));
188 + set_vim_var_string(VV_CHAR, NULL, -1); /* clear v:char */
194 *** ../vim-7.3.460/src/fileio.c 2012-02-12 20:13:55.000000000 +0100
195 --- src/fileio.c 2012-02-29 17:50:32.000000000 +0100
199 return (first_autopat[(int)EVENT_CURSORMOVEDI] != NULL);
203 + * Return TRUE when there is an InsertCharPre autocommand defined.
206 + has_insertcharpre()
208 + return (first_autopat[(int)EVENT_INSERTCHARPRE] != NULL);
212 apply_autocmds_group(event, fname, fname_io, force, group, buf, eap)
214 *** ../vim-7.3.460/src/proto/fileio.pro 2012-02-12 20:13:55.000000000 +0100
215 --- src/proto/fileio.pro 2012-02-29 17:50:38.000000000 +0100
219 int trigger_cursorhold __ARGS((void));
220 int has_cursormoved __ARGS((void));
221 int has_cursormovedI __ARGS((void));
222 + int has_insertcharpre __ARGS((void));
223 void block_autocmds __ARGS((void));
224 void unblock_autocmds __ARGS((void));
225 int has_autocmd __ARGS((event_T event, char_u *sfname, buf_T *buf));
226 *** ../vim-7.3.460/src/version.c 2012-02-29 16:56:35.000000000 +0100
227 --- src/version.c 2012-02-29 18:15:34.000000000 +0100
231 { /* Add new patch number below this line */
237 "Computers in the future may weigh no more than 1.5 tons."
238 Popular Mechanics, 1949
240 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
241 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
242 \\\ an exciting new programming language -- http://www.Zimbu.org ///
243 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///