Hi.

When set autocmd InsertCharPre like following, It should work with all
key typings to insert 'f' at all.

  autocmd InsertCharPre * let v:char = 'f'

But often, it show other characters (not 'f') in the screen.
This causes by two problems.

1. Typing keys while popup menu is shown are not handled in normally.
  When popup menu is shown, key types are handled to decide of candidate.
  And it behave independently.

2. Keys are grabbed at once for speed up.
  See the comment arround edit.c:5864.

    /*
     * If there's any pending input, grab up to INPUT_BUFLEN at once.
     * This speeds up normal text input considerably.
     * Don't do this when 'cindent' or 'indentexpr' is set, because we might
     * need to re-indent at a ':', or any other character (but not what
     * 'paste' is set)..
     * Don't do this when there is InsertCharPre autocommand defined,
     * because we need to fire the event for every character.
     */

  So, some key types don't fire InsertCharPre.
  It should be disabled while InsertCharPre is working.

Below is a patch. Please check and include.

https://gist.github.com/1303301

diff -r 37ecb8ff4560 src/edit.c
--- a/src/edit.c Thu Oct 20 22:22:38 2011 +0200
+++ b/src/edit.c Fri Oct 21 16:19:52 2011 +0900
@@ -784,7 +784,17 @@
  * completion: Add to "compl_leader". */
  if (ins_compl_accept_char(c))
  {
-    ins_compl_addleader(c);
+    set_vim_var_char(c);
+    ++textlock;
+    if (apply_autocmds(EVENT_INSERTCHARPRE, NULL, NULL,
+   FALSE, curbuf))
+    {
+ c = PTR2CHAR(get_vim_var_str(VV_CHAR));
+    }
+    if (c)
+ ins_compl_addleader(c);
+    set_vim_var_string(VV_CHAR, NULL, -1);
+    --textlock;
     continue;
  }
 
@@ -1393,31 +1403,37 @@
 #ifdef FEAT_AUTOCMD
     if (!p_paste)
     {
+ int executed;
  /* 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))
+ executed = apply_autocmds(EVENT_INSERTCHARPRE, NULL, NULL,
+    FALSE, curbuf);
+ --textlock;
+ if (executed)
  {
     /* 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)
     {
- if (stop_arrow() != FAIL)
+ char_u *str = get_vim_var_str(VV_CHAR);
+ char_u *ptr = str;
+ while (*ptr != NUL)
  {
-    ins_str(s);
-    AppendToRedobuffLit(s, -1);
+    c = PTR2CHAR(ptr);
+    if (c == CAR || c == K_KENTER || c == NL)
+ ins_eol(c);
+    else
+ ins_char(c);
+    ptr += (*mb_ptr2len)(ptr);
  }
- c = NUL;
+ AppendToRedobuffLit(str, -1);
     }
-    else
- c = PTR2CHAR(s);
+    c = NUL;
  }
 
  set_vim_var_string(VV_CHAR, NULL, -1);
- --textlock;
 
  /* If the new value is an empty string then don't insert a
  * char. */
@@ -5867,6 +5883,8 @@
      * Don't do this when 'cindent' or 'indentexpr' is set, because we 
might
      * need to re-indent at a ':', or any other character (but not what
      * 'paste' is set)..
+     * Don't do this when there is InsertCharPre autocommand defined,
+     * because we need to fire the event for every character.
      */
 #ifdef USE_ON_FLY_SCROLL
     dont_scroll = FALSE; /* allow scrolling here */
@@ -5884,6 +5902,9 @@
 #ifdef FEAT_RIGHTLEFT
     && !p_ri
 #endif
+#ifdef FEAT_AUTOCMD
+    && !has_insertcharpre()
+#endif
        )
     {
 #define INPUT_BUFLEN 100
diff -r 37ecb8ff4560 src/fileio.c
--- a/src/fileio.c Thu Oct 20 22:22:38 2011 +0200
+++ b/src/fileio.c Fri Oct 21 16:19:52 2011 +0900
@@ -6247,6 +6247,11 @@
 #ifdef VMS
  vms_remove_version(retval); /* we do not need versions here */
 #endif
+#ifdef WIN3264
+ /* Avoids to make strange filename of NTFS stream like 'foo:bar.swp' */
+ if ((e = vim_strchr(retval, ':')) != NULL && !after_pathsep(retval, e))
+    *e = NUL;
+#endif
     }
 
     /*
@@ -9092,6 +9097,15 @@
     return (first_autopat[(int)EVENT_CURSORMOVEDI] != NULL);
 }
 
+/*
+ * Return TRUE when there is a InsertCharPre autocommand defined.
+ */
+    int
+has_insertcharpre()
+{
+    return (first_autopat[(int)EVENT_INSERTCHARPRE] != NULL);
+}
+
     static int
 apply_autocmds_group(event, fname, fname_io, force, group, buf, eap)
     event_T event;
diff -r 37ecb8ff4560 src/proto/fileio.pro
--- a/src/proto/fileio.pro Thu Oct 20 22:22:38 2011 +0200
+++ b/src/proto/fileio.pro Fri Oct 21 16:19:52 2011 +0900
@@ -43,6 +43,7 @@
 int trigger_cursorhold __ARGS((void));
 int has_cursormoved __ARGS((void));
 int has_cursormovedI __ARGS((void));
+int has_insertcharpre __ARGS((void));
 void block_autocmds __ARGS((void));
 void unblock_autocmds __ARGS((void));
 int has_autocmd __ARGS((event_T event, char_u *sfname, buf_T *buf));


-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Raspunde prin e-mail lui