On Wed, Sep 13, 2006 at 11:27:43AM +0300, Yakov Lerner wrote:
> Nice. So simple. I have couple of comments.
> 
Thank you :)

> 1. Don't you need to reset 'paste' back to 'nopaste' when
> high cps stops ?
> 
There is a hastily coded version of the patch that does this, but I
don't like it.  It seems hackier (most likely my fault), and stranger to
use.  That is, as far as I know, inavoidable, since I have to wait until
at least one second after the paste ends and the user starts typing
before I can know to end the paste.  I'm open to suggestions as to how
to do that better.  I'll attach both patches this time.

> 2. It would be better if cps be settable, not hardcoded to 30.
> Maybe value of 'autopaste' can be made the cps boundary
> 'set autopaste=30', value 0 disables ?
> 
Good idea.  Fixed in this version.

> 3. Regarding line do_set(&sPaste, 0); I think typical vim style
> is to write do_set("paste", 0); then
>                 char_u sPaste[] = "paste";
>                 do_set(&sPaste, 0);
> 
That's what I was doing before, but do_set appears to write to the first
argument.  When I did do_set("paste", 0), it would segfault.

It appears that everywhere else in vim where do_set is used, a variable
is passed to it as well.  If anyone knows a less hacky way to do that,
I'd be happy to use that instead.

Thanks again for your suggestions.
-- 
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:56:14.000000000 -0400
--- vim70/src/getchar.c 2006-09-13 07:08:42.000000000 -0400
***************
*** 1495,1500 ****
--- 1495,1509 ----
      int
  vgetc()
  {
+     static time_t last_call = 0;
+     static int cps = 0;
+     char_u sPaste[] = "paste";        // do_set writes to the first arguement.
+     time_t now;
+     if (p_apa)
+       now = time(NULL);
+ 
      int               c, c2;
  #ifdef FEAT_MBYTE
      int               n;
***************
*** 1502,1507 ****
--- 1511,1535 ----
      int               i;
  #endif
  
+     if (p_apa && !p_paste) {
+       if (last_call == now)
+         ++cps;
+       else
+         cps = 0;
+ 
+       if (cps >= p_apa) {
+         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:56:14.000000000 -0400
--- vim70/src/option.c  2006-09-13 07:08:06.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_NUM|P_VI_DEF,
+                             (char_u *)&p_apa, PV_NONE,
+                             {(char_u *)0L, (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:56:14.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' */
diff -cr vim70.orig/src/getchar.c vim70/src/getchar.c
*** vim70.orig/src/getchar.c    2006-09-12 21:56:14.000000000 -0400
--- vim70/src/getchar.c 2006-09-13 07:08:42.000000000 -0400
***************
*** 1495,1500 ****
--- 1495,1509 ----
      int
  vgetc()
  {
+     static time_t last_call = 0;
+     static int cps = 0;
+     static char autopasting = 0;
+     char_u sPaste[] = "paste";        // do_set writes to the first arguement.
+     char_u sNopaste[] = "nopaste";
+     time_t now;
+     if (p_apa)
+       now = time(NULL);
+ 
      int               c, c2;
  #ifdef FEAT_MBYTE
      int               n;
***************
*** 1502,1507 ****
--- 1511,1535 ----
      int               i;
  #endif
  
+     if (p_apa) {
+       if (last_call == now)
+         ++cps;
+       else
+         cps = 0;
+ 
+       if (cps >= p_apa && autopasting == 0 && !p_paste) {
+       autopasting = 1;
+       do_set(&sPaste, 0);
+       showmode();
+       }
+       if (cps < p_apa && autopasting == 1) {
+         do_set(&sNopaste, 0);
+       autopasting = 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:56:14.000000000 -0400
--- vim70/src/option.c  2006-09-13 07:08:06.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_NUM|P_VI_DEF,
+                             (char_u *)&p_apa, PV_NONE,
+                             {(char_u *)0L, (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:56:14.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