summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2011-05-19 17:25:41 +0200
committerBram Moolenaar <Bram@vim.org>2011-05-19 17:25:41 +0200
commite659c95b01b04b353e60d728d32bcb17f8ff832c (patch)
tree3323ea64a3ce4a6129ba7d0de5114e0ded35b6c8 /src
parent496f9517cb2630cd902be85e51e3ab395a194e85 (diff)
downloadvim-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')
-rw-r--r--src/edit.c43
-rw-r--r--src/eval.c2
-rw-r--r--src/fileio.c1
-rw-r--r--src/version.c2
-rw-r--r--src/vim.h1
5 files changed, 42 insertions, 7 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);
}
diff --git a/src/eval.c b/src/eval.c
index 64ed72ae0..2432ad395 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -352,7 +352,7 @@ static struct vimvar
{VV_NAME("swapname", VAR_STRING), VV_RO},
{VV_NAME("swapchoice", VAR_STRING), 0},
{VV_NAME("swapcommand", VAR_STRING), VV_RO},
- {VV_NAME("char", VAR_STRING), VV_RO},
+ {VV_NAME("char", VAR_STRING), 0},
{VV_NAME("mouse_win", VAR_NUMBER), 0},
{VV_NAME("mouse_lnum", VAR_NUMBER), 0},
{VV_NAME("mouse_col", VAR_NUMBER), 0},
diff --git a/src/fileio.c b/src/fileio.c
index b4fbdfbac..6355c7911 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -7662,6 +7662,7 @@ static struct event_name
{"InsertChange", EVENT_INSERTCHANGE},
{"InsertEnter", EVENT_INSERTENTER},
{"InsertLeave", EVENT_INSERTLEAVE},
+ {"InsertCharPre", EVENT_INSERTCHARPRE},
{"MenuPopup", EVENT_MENUPOPUP},
{"QuickFixCmdPost", EVENT_QUICKFIXCMDPOST},
{"QuickFixCmdPre", EVENT_QUICKFIXCMDPRE},
diff --git a/src/version.c b/src/version.c
index 968bbb355..66de09ee5 100644
--- a/src/version.c
+++ b/src/version.c
@@ -710,6 +710,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 196,
+/**/
195,
/**/
194,
diff --git a/src/vim.h b/src/vim.h
index 490206a7e..9fc1070b6 100644
--- a/src/vim.h
+++ b/src/vim.h
@@ -1274,6 +1274,7 @@ enum auto_event
EVENT_WINENTER, /* after entering a window */
EVENT_WINLEAVE, /* before leaving a window */
EVENT_ENCODINGCHANGED, /* after changing the 'encoding' option */
+ EVENT_INSERTCHARPRE, /* before inserting a char */
EVENT_CURSORHOLD, /* cursor in same position for a while */
EVENT_CURSORHOLDI, /* idem, in Insert mode */
EVENT_FUNCUNDEFINED, /* if calling a function which doesn't exist */