To: [email protected]
Subject: Patch 7.2b.025
Fcc: outbox
From: Bram Moolenaar <[email protected]>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
------------

Patch 7.2b.025
Problem:    When the CursorHold event triggers a pending count is lost.
           (Juergen Kraemer)
Solution:   Save the counts and restore them.
Files:      src/normal.c, src/structs.h


*** ../vim-7.2b.024/src/normal.c        Sat Jul 26 16:03:55 2008
--- src/normal.c        Thu Jul 31 22:03:08 2008
***************
*** 581,586 ****
--- 581,590 ----

     vim_memset(&ca, 0, sizeof(ca));   /* also resets ca.retval */
     ca.oap = oap;
+
+     /* Use a count remembered from before entering an operator.  After typing
+      * "3d" we return from normal_cmd() and come back here, the "3" is
+      * remembered in "opcount". */
     ca.opcount = opcount;

 #ifdef FEAT_SNIFF
***************
*** 606,614 ****
--- 610,633 ----
     }
 #endif

+     /* When not finishing an operator and no register name typed, reset the
+      * count. */
     if (!finish_op && !oap->regname)
       ca.opcount = 0;

+ #ifdef FEAT_AUTOCMD
+     /* Restore counts from before receiving K_CURSORHOLD.  This means after
+      * typing "3", handling K_CURSORHOLD and then typing "2" we get "32", not
+      * "3 * 2". */
+     if (oap->prev_opcount > 0 || oap->prev_count0 > 0)
+     {
+       ca.opcount = oap->prev_opcount;
+       ca.count0 = oap->prev_count0;
+       oap->prev_opcount = 0;
+       oap->prev_count0 = 0;
+     }
+ #endif
+
 #ifdef FEAT_VISUAL
     mapped_len = typebuf_maplen();
 #endif
***************
*** 744,759 ****
       }
     }

!     /*
!      * If we're in the middle of an operator (including after entering a yank
!      * buffer with '"') AND we had a count before the operator, then that
!      * count overrides the current value of ca.count0.
!      * What this means effectively, is that commands like "3dw" get turned
!      * into "d3w" which makes things fall into place pretty neatly.
!      * If you give a count before AND after the operator, they are multiplied.
!      */
!     if (ca.opcount != 0)
     {
       if (ca.count0)
           ca.count0 *= ca.opcount;
       else
--- 763,789 ----
       }
     }

! #ifdef FEAT_AUTOCMD
!     if (c == K_CURSORHOLD)
     {
+       /* Save the count values so that ca.opcount and ca.count0 are exactly
+        * the same when coming back here after handling K_CURSORHOLD. */
+       oap->prev_opcount = ca.opcount;
+       oap->prev_count0 = ca.count0;
+     }
+     else
+ #endif
+       if (ca.opcount != 0)
+     {
+       /*
+        * If we're in the middle of an operator (including after entering a
+        * yank buffer with '"') AND we had a count before the operator, then
+        * that count overrides the current value of ca.count0.
+        * What this means effectively, is that commands like "3dw" get turned
+        * into "d3w" which makes things fall into place pretty neatly.
+        * If you give a count before AND after the operator, they are
+        * multiplied.
+        */
       if (ca.count0)
           ca.count0 *= ca.opcount;
       else
***************
*** 798,804 ****

     if (text_locked() && (nv_cmds[idx].cmd_flags & NV_NCW))
     {
!       /* This command is not allowed wile editing a ccmdline: beep. */
       clearopbeep(oap);
       text_locked_msg();
       goto normal_end;
--- 828,834 ----

     if (text_locked() && (nv_cmds[idx].cmd_flags & NV_NCW))
     {
!       /* This command is not allowed while editing a ccmdline: beep. */
       clearopbeep(oap);
       text_locked_msg();
       goto normal_end;
***************
*** 1274,1280 ****
 #endif

 #ifdef FEAT_CMDL_INFO
!     if (oap->op_type == OP_NOP && oap->regname == 0)
       clear_showcmd();
 #endif

--- 1304,1314 ----
 #endif

 #ifdef FEAT_CMDL_INFO
!     if (oap->op_type == OP_NOP && oap->regname == 0
! # ifdef FEAT_AUTOCMD
!           && ca.cmdchar != K_CURSORHOLD
! # endif
!           )
       clear_showcmd();
 #endif

*** ../vim-7.2b.024/src/structs.h       Tue Jun 24 23:57:58 2008
--- src/structs.h       Wed Jul 30 22:02:50 2008
***************
*** 2076,2081 ****
--- 2076,2085 ----
 #endif
     colnr_T   start_vcol;     /* start col for block mode operator */
     colnr_T   end_vcol;       /* end col for block mode operator */
+ #ifdef FEAT_AUTOCMD
+     long      prev_opcount;   /* ca.opcount saved for K_CURSORHOLD */
+     long      prev_count0;    /* ca.count0 saved for K_CURSORHOLD */
+ #endif
 } oparg_T;

 /*
*** ../vim-7.2b.024/src/version.c       Tue Jul 29 12:21:01 2008
--- src/version.c       Thu Jul 31 21:59:16 2008
***************
*** 678,679 ****
--- 678,681 ----
 {   /* Add new patch number below this line */
+ /**/
+     25,
 /**/

--
CRONE:  Who sent you?
ARTHUR: The Knights Who Say Ni!
CRONE:  Aaaagh!  (she looks around in rear) No!  We have no shrubberies here.
                "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
\\\            help me help AIDS victims -- http://ICCF-Holland.org    ///