]> granicus.if.org Git - vim/commitdiff
updated for version 7.3.196 v7.3.196
authorBram Moolenaar <Bram@vim.org>
Thu, 19 May 2011 15:25:41 +0000 (17:25 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 19 May 2011 15:25:41 +0000 (17:25 +0200)
Problem:    Can't intercept a character that is going to be inserted.
Solution:   Add the InsertCharPre autocommand event. (Jakson A. Aquino)

runtime/doc/autocmd.txt
runtime/doc/eval.txt
runtime/doc/map.txt
src/edit.c
src/eval.c
src/fileio.c
src/version.c
src/vim.h

index d40df23416a2c6557851282d0a0b7e06f0560d98..145ecf624bf9594667e99098a59a0de2602d7a67 100644 (file)
@@ -299,6 +299,8 @@ Name                        triggered by ~
 |InsertEnter|          starting Insert mode
 |InsertChange|         when typing <Insert> while in Insert or Replace mode
 |InsertLeave|          when leaving Insert mode
+|InsertCharPre|                when a character was typed in Insert mode, before
+                       inserting it
 
 |ColorScheme|          after loading a color scheme
 
@@ -657,6 +659,17 @@ InsertChange                       When typing <Insert> while in Insert or
                                indicates the new mode.
                                Be careful not to move the cursor or do
                                anything else that the user does not expect.
+                                                       *InsertCharPre*
+InsertCharPre                  When a character is typed in Insert mode,
+                               before inserting the char.
+                               The |v:char| variable indicates the char typed
+                               and can be changed during the event to insert
+                               a different character.  When |v:char| is set
+                               to more than one character this text is
+                               inserted literally.
+                               It is not allowed to change the text |textlock|.
+                               The event is not triggered when 'paste' is
+                               set.
                                                        *InsertEnter*
 InsertEnter                    Just before starting Insert mode.  Also for
                                Replace mode and Virtual Replace mode.  The
index 50da2de66d980c8f32910fd70d37d85bce115272..db5ae56360ffc06345efaa95071f2ae323e0fc06 100644 (file)
@@ -1293,6 +1293,7 @@ v:beval_winnr     The number of the window, over which the mouse pointer is. Only
                                        *v:char* *char-variable*
 v:char         Argument for evaluating 'formatexpr' and used for the typed
                character when using <expr> in an abbreviation |:map-<expr>|.
+               It is also used by the |InsertPreChar| event.
 
                        *v:charconvert_from* *charconvert_from-variable*
 v:charconvert_from
index ec21d15ff035142e4b07a3047453553a06484dc4..ceb29013d06cc1b02339e09396d39bd392819d3b 100644 (file)
@@ -226,7 +226,7 @@ text before the cursor and start omni completion when some condition is met.
 
 For abbreviations |v:char| is set to the character that was typed to trigger
 the abbreviation.  You can use this to decide how to expand the {lhs}.  You
-can't change v:char and you should not insert it.
+you should not either insert or change the v:char.
 
 Be very careful about side effects!  The expression is evaluated while
 obtaining characters, you may very well make the command dysfunctional.
index a43c0a2c16b5c7b0719a70ad6e8d0c8c4b00534c..711bfccc9f092386f14837951e560b4551e7e30b 100644 (file)
@@ -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);
 }
 
index 64ed72ae0b16a48bb0d82d4b03a6393fb846df17..2432ad39502e99cd35ba85eab11b2e6a8ee65266 100644 (file)
@@ -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},
index b4fbdfbac979ceb040216eb1a4146a35c938fa37..6355c7911b29b40dfbf3a06d9c41ef40b5275ac4 100644 (file)
@@ -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},
index 968bbb355b6be6c82c1c1acafa444ee07cda5d9e..66de09ee53b919cc84f79cef7daa7c30699a3d49 100644 (file)
@@ -709,6 +709,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    196,
 /**/
     195,
 /**/
index 490206a7e9ed8f51012ad0a25caea6429c36e1e2..9fc1070b6ebb1604eec50bbae7f70aa4382ceadb 100644 (file)
--- 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 */