Pasting code into vim and forgetting to set paste can have annoying
results.  This patch detects the 'really fast typing' that happens when
something is pasted in, and turns on paste mode.  It provides an option
'autopaste' (default false) which controls the behavior.

Patch is attached.  Hope this is useful.
-- 
Ian Kilgore
`echo "[EMAIL PROTECTED]" | tr pzfwxt ikagno`

diff -cr vim70.orig/src/getchar.c vim70/src/getchar.c
*** vim70.orig/src/getchar.c    2006-09-12 21:47:30.000000000 -0400
--- vim70/src/getchar.c 2006-09-12 21:53:35.000000000 -0400
***************
*** 1495,1500 ****
--- 1495,1507 ----
      int
  vgetc()
  {
+     static time_t last_call = 0;
+     static int cps = 0;
+     char_u sPaste[] = "paste";
+     time_t now;
+     if (p_apa)
+       now = time(NULL);
+ 
      int               c, c2;
  #ifdef FEAT_MBYTE
      int               n;
***************
*** 1502,1507 ****
--- 1509,1527 ----
      int               i;
  #endif
  
+     if (p_apa && !p_paste) {
+       if (last_call == now)
+         ++cps;
+       else
+         cps = 0;
+       if (cps >= 30) {
+         cps = 0;
+       do_set(&sPaste, 0);
+       showmode();
+       }
+       last_call = now;
+     }
+ 
      /*
       * If a character was put back with vungetc, it was already processed.
       * Return it directly.
diff -cr vim70.orig/src/option.c vim70/src/option.c
*** vim70.orig/src/option.c     2006-09-12 21:47:30.000000000 -0400
--- vim70/src/option.c  2006-09-12 21:54:07.000000000 -0400
***************
*** 529,534 ****
--- 529,537 ----
      {"autoindent",  "ai",   P_BOOL|P_VI_DEF,
                            (char_u *)&p_ai, PV_AI,
                            {(char_u *)FALSE, (char_u *)0L}},
+     {"autopaste",   "apa",  P_BOOL|P_VI_DEF,
+                             (char_u *)&p_apa, PV_NONE,
+                             {(char_u *)FALSE, (char_u *)0L}},
      {"autoprint",   "ap",   P_BOOL|P_VI_DEF,
                            (char_u *)NULL, PV_NONE,
                            {(char_u *)FALSE, (char_u *)0L}},
diff -cr vim70.orig/src/option.h vim70/src/option.h
*** vim70.orig/src/option.h     2006-09-12 21:47:30.000000000 -0400
--- vim70/src/option.h  2006-09-12 21:54:23.000000000 -0400
***************
*** 312,317 ****
--- 312,318 ----
  #if defined(FEAT_GUI) && defined(MACOS_X)
  EXTERN int    *p_antialias;   /* 'antialias' */
  #endif
+ EXTERN int      p_apa;          /* 'autopaste' */
  EXTERN int    p_ar;           /* 'autoread' */
  EXTERN int    p_aw;           /* 'autowrite' */
  EXTERN int    p_awa;          /* 'autowriteall' */

Attachment: signature.asc
Description: Digital signature

Reply via email to