diff options
author | Bram Moolenaar <Bram@vim.org> | 2011-05-19 17:25:41 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2011-05-19 17:25:41 +0200 |
commit | e659c95b01b04b353e60d728d32bcb17f8ff832c (patch) | |
tree | 3323ea64a3ce4a6129ba7d0de5114e0ded35b6c8 /src/edit.c | |
parent | 496f9517cb2630cd902be85e51e3ab395a194e85 (diff) | |
download | vim-git-e659c95b01b04b353e60d728d32bcb17f8ff832c.tar.gz |
updated for version 7.3.196v7.3.196
Problem: Can't intercept a character that is going to be inserted.
Solution: Add the InsertCharPre autocommand event. (Jakson A. Aquino)
Diffstat (limited to 'src/edit.c')
-rw-r--r-- | src/edit.c | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/src/edit.c b/src/edit.c index a43c0a2c1..711bfccc9 100644 --- a/src/edit.c +++ b/src/edit.c @@ -1381,10 +1381,45 @@ docomplete: goto do_intr; #endif +normalchar: /* * Insert a nomal character. */ -normalchar: +#ifdef FEAT_AUTOCMD + if (!p_paste) + { + /* Trigger the InsertCharPre event. Lock the text to avoid + * weird things from happening. */ + set_vim_var_char(c); + ++textlock; + if (apply_autocmds(EVENT_INSERTCHARPRE, NULL, NULL, + FALSE, curbuf)) + { + /* Get the new value of v:char. If it is more than one + * character insert it literally. */ + char_u *s = get_vim_var_str(VV_CHAR); + if (MB_CHARLEN(s) > 1) + { + if (stop_arrow() != FAIL) + { + ins_str(s); + AppendToRedobuffLit(s, -1); + } + c = NUL; + } + else + c = PTR2CHAR(s); + } + + set_vim_var_string(VV_CHAR, NULL, -1); + --textlock; + + /* If the new value is an empty string then don't insert a + * char. */ + if (c == NUL) + break; + } +#endif #ifdef FEAT_SMARTINDENT /* Try to perform smart-indenting. */ ins_try_si(c); @@ -3491,11 +3526,7 @@ ins_compl_addfrommatch() return; } p += len; -#ifdef FEAT_MBYTE - c = mb_ptr2char(p); -#else - c = *p; -#endif + c = PTR2CHAR(p); ins_compl_addleader(c); } |