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: Can't intercept a character that is going to be inserted.
12 Solution: Add the InsertCharPre autocommand event. (Jakson A. Aquino)
13 Files: runtime/doc/autocmd.txt, runtime/doc/eval.txt,
14 runtime/doc/map.txt, src/edit.c, src/eval.c, src/fileio.c,
18 *** ../mercurial/vim73/runtime/doc/autocmd.txt 2011-04-28 19:01:26.000000000 +0200
19 --- runtime/doc/autocmd.txt 2011-05-19 17:12:17.000000000 +0200
23 |InsertEnter| starting Insert mode
24 |InsertChange| when typing <Insert> while in Insert or Replace mode
25 |InsertLeave| when leaving Insert mode
26 + |InsertCharPre| when a character was typed in Insert mode, before
29 |ColorScheme| after loading a color scheme
34 indicates the new mode.
35 Be careful not to move the cursor or do
36 anything else that the user does not expect.
38 + InsertCharPre When a character is typed in Insert mode,
39 + before inserting the char.
40 + The |v:char| variable indicates the char typed
41 + and can be changed during the event to insert
42 + a different character. When |v:char| is set
43 + to more than one character this text is
45 + It is not allowed to change the text |textlock|.
46 + The event is not triggered when 'paste' is
49 InsertEnter Just before starting Insert mode. Also for
50 Replace mode and Virtual Replace mode. The
51 *** ../mercurial/vim73/runtime/doc/eval.txt 2011-05-19 12:22:41.000000000 +0200
52 --- runtime/doc/eval.txt 2011-05-19 16:55:58.000000000 +0200
56 *v:char* *char-variable*
57 v:char Argument for evaluating 'formatexpr' and used for the typed
58 character when using <expr> in an abbreviation |:map-<expr>|.
59 + It is also used by the |InsertPreChar| event.
61 *v:charconvert_from* *charconvert_from-variable*
63 *** ../mercurial/vim73/runtime/doc/map.txt 2011-05-10 17:17:38.000000000 +0200
64 --- runtime/doc/map.txt 2011-05-19 16:40:34.000000000 +0200
68 For abbreviations |v:char| is set to the character that was typed to trigger
69 the abbreviation. You can use this to decide how to expand the {lhs}. You
70 ! can't change v:char and you should not insert it.
72 Be very careful about side effects! The expression is evaluated while
73 obtaining characters, you may very well make the command dysfunctional.
76 For abbreviations |v:char| is set to the character that was typed to trigger
77 the abbreviation. You can use this to decide how to expand the {lhs}. You
78 ! you should not either insert or change the v:char.
80 Be very careful about side effects! The expression is evaluated while
81 obtaining characters, you may very well make the command dysfunctional.
82 *** ../mercurial/vim73/src/edit.c 2011-05-10 14:22:10.000000000 +0200
83 --- src/edit.c 2011-05-19 17:20:53.000000000 +0200
90 * Insert a nomal character.
93 #ifdef FEAT_SMARTINDENT
94 /* Try to perform smart-indenting. */
102 * Insert a nomal character.
104 ! #ifdef FEAT_AUTOCMD
107 ! /* Trigger the InsertCharPre event. Lock the text to avoid
108 ! * weird things from happening. */
109 ! set_vim_var_char(c);
111 ! if (apply_autocmds(EVENT_INSERTCHARPRE, NULL, NULL,
114 ! /* Get the new value of v:char. If it is more than one
115 ! * character insert it literally. */
116 ! char_u *s = get_vim_var_str(VV_CHAR);
117 ! if (MB_CHARLEN(s) > 1)
119 ! if (stop_arrow() != FAIL)
122 ! AppendToRedobuffLit(s, -1);
130 ! set_vim_var_string(VV_CHAR, NULL, -1);
133 ! /* If the new value is an empty string then don't insert a
139 #ifdef FEAT_SMARTINDENT
140 /* Try to perform smart-indenting. */
148 ! c = mb_ptr2char(p);
152 ins_compl_addleader(c);
160 ins_compl_addleader(c);
163 *** ../mercurial/vim73/src/eval.c 2011-05-19 14:59:07.000000000 +0200
164 --- src/eval.c 2011-05-19 16:40:39.000000000 +0200
167 {VV_NAME("swapname", VAR_STRING), VV_RO},
168 {VV_NAME("swapchoice", VAR_STRING), 0},
169 {VV_NAME("swapcommand", VAR_STRING), VV_RO},
170 ! {VV_NAME("char", VAR_STRING), VV_RO},
171 {VV_NAME("mouse_win", VAR_NUMBER), 0},
172 {VV_NAME("mouse_lnum", VAR_NUMBER), 0},
173 {VV_NAME("mouse_col", VAR_NUMBER), 0},
175 {VV_NAME("swapname", VAR_STRING), VV_RO},
176 {VV_NAME("swapchoice", VAR_STRING), 0},
177 {VV_NAME("swapcommand", VAR_STRING), VV_RO},
178 ! {VV_NAME("char", VAR_STRING), 0},
179 {VV_NAME("mouse_win", VAR_NUMBER), 0},
180 {VV_NAME("mouse_lnum", VAR_NUMBER), 0},
181 {VV_NAME("mouse_col", VAR_NUMBER), 0},
182 *** ../mercurial/vim73/src/fileio.c 2011-05-10 16:41:13.000000000 +0200
183 --- src/fileio.c 2011-05-19 16:40:39.000000000 +0200
187 {"InsertChange", EVENT_INSERTCHANGE},
188 {"InsertEnter", EVENT_INSERTENTER},
189 {"InsertLeave", EVENT_INSERTLEAVE},
190 + {"InsertCharPre", EVENT_INSERTCHARPRE},
191 {"MenuPopup", EVENT_MENUPOPUP},
192 {"QuickFixCmdPost", EVENT_QUICKFIXCMDPOST},
193 {"QuickFixCmdPre", EVENT_QUICKFIXCMDPRE},
194 *** ../mercurial/vim73/src/vim.h 2011-05-10 16:41:13.000000000 +0200
195 --- src/vim.h 2011-05-19 16:40:39.000000000 +0200
199 EVENT_WINENTER, /* after entering a window */
200 EVENT_WINLEAVE, /* before leaving a window */
201 EVENT_ENCODINGCHANGED, /* after changing the 'encoding' option */
202 + EVENT_INSERTCHARPRE, /* before inserting a char */
203 EVENT_CURSORHOLD, /* cursor in same position for a while */
204 EVENT_CURSORHOLDI, /* idem, in Insert mode */
205 EVENT_FUNCUNDEFINED, /* if calling a function which doesn't exist */
206 *** ../vim-7.3.195/src/version.c 2011-05-19 16:35:05.000000000 +0200
207 --- src/version.c 2011-05-19 17:15:41.000000000 +0200
211 { /* Add new patch number below this line */
218 ...for the mess to clean after a party because it means I have
219 been surrounded by friends.
221 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
222 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
223 \\\ an exciting new programming language -- http://www.Zimbu.org ///
224 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///