Anthony was right that I was a bit anxious :-).  My previous patch
generated a problem, it counted also consecutive blank lines.  This new
patch fixes that:


Index: vi/v_paragraph.c
===================================================================
RCS file: /cvs/src/usr.bin/vi/vi/v_paragraph.c,v
retrieving revision 1.9
diff -u -p -r1.9 v_paragraph.c
--- vi/v_paragraph.c    18 Apr 2017 01:45:35 -0000      1.9
+++ vi/v_paragraph.c    22 Aug 2023 10:09:10 -0000
@@ -103,17 +103,13 @@ v_paragraphf(SCR *sp, VICMD *vp)
                goto eof;
 
        /*
-        * If we start in text, we want to switch states
-        * (2 * N - 1) times, in non-text, (2 * N) times.
+        * If we start in text, we want to switch states.
         */
        cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
-       cnt *= 2;
        if (len == 0 || v_isempty(p, len))
                pstate = P_INBLANK;
-       else {
-               --cnt;
+       else
                pstate = P_INTEXT;
-       }
 
        for (;;) {
                lastlno = lno;
@@ -127,6 +123,8 @@ v_paragraphf(SCR *sp, VICMD *vp)
                case P_INBLANK:
                        if (len == 0 || v_isempty(p, len))
                                break;
+                       else
+                               ++cnt;
                        if (--cnt) {
                                pstate = P_INTEXT;
                                break;
@@ -247,15 +245,12 @@ v_paragraphb(SCR *sp, VICMD *vp)
                goto sof;
 
        /*
-        * If we start in text, we want to switch states
-        * (2 * N - 1) times, in non-text, (2 * N) times.
+        * If we start in text, we want to switch states.
         */
        cnt = F_ISSET(vp, VC_C1SET) ? vp->count : 1;
-       cnt *= 2;
        if (len == 0 || v_isempty(p, len))
                pstate = P_INBLANK;
        else {
-               --cnt;
                pstate = P_INTEXT;
 
                /*
@@ -276,6 +271,7 @@ v_paragraphb(SCR *sp, VICMD *vp)
                        break;
                case P_INBLANK:
                        if (len != 0 && !v_isempty(p, len)) {
+                               ++cnt;
                                if (!--cnt)
                                        goto found;
                                pstate = P_INTEXT;


-- 
Walter

Reply via email to