Hi Anthony,

It's about this:

  https://marc.info/?l=openbsd-bugs&m=169100763926909&w=2

I'm addressing you because, besides that none answered (summertime?
:-),) I applied my patch to nvi in ports also.  I been using both vi and
nvi for a while and, as far as I can tell, with my patch nvi does
exactly what's expected, and I haven't notice any regressions.

I guess that the reason most people didn't notice this bug is they don't
use nvi to edit and reviewing +200 pages books with groff (yeah, I'm
crazy.)  Simply put: a week ago I hit 2d} in a groff file and instead of
two paragraphs I deleted three.  I use nvi to so, for me that's a
dangerous issue :-).

By the way, while "vim" behaves a bit better it's still not fully
consistent.  If in vim you put the cursor in the first blank line before
a roff paragraph, the '[count]}' command moves the cursor to 'count-1'.
Of course, since you don't have blank lines in a roff file (and with vim
everyone uses the visual mode), none would even realize about this
issue.

Here you have a new version (the only difference is I modified the
comment right above the first change.)  Both, base vi and ports nvi
version.  Could you take a look, please?


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    18 Aug 2023 14:22:24 -0000
@@ -103,15 +103,12 @@ 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;
                pstate = P_INTEXT;
        }
 
@@ -125,6 +122,7 @@ v_paragraphf(SCR *sp, VICMD *vp)
                        INTEXT_CHECK;
                        break;
                case P_INBLANK:
+                       ++cnt;
                        if (len == 0 || v_isempty(p, len))
                                break;
                        if (--cnt) {
@@ -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;
 
                /*
@@ -275,6 +270,7 @@ v_paragraphb(SCR *sp, VICMD *vp)
                        INTEXT_CHECK;
                        break;
                case P_INBLANK:
+                       ++cnt;
                        if (len != 0 && !v_isempty(p, len)) {
                                if (!--cnt)
                                        goto found;



NVI PORTS VERSION OF THE SAME PATCH
----------------------------------------------------------------------

Index: vi/v_paragraph.c
--- vi/v_paragraph.c.orig
+++ vi/v_paragraph.c
@@ -101,15 +101,12 @@ 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;
                pstate = P_INTEXT;
        }
 
@@ -123,6 +120,7 @@ v_paragraphf(SCR *sp, VICMD *vp)
                        INTEXT_CHECK;
                        break;
                case P_INBLANK:
+                       ++cnt;
                        if (len == 0 || v_isempty(p, len))
                                break;
                        if (--cnt) {
@@ -245,15 +243,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;
 
                /*
@@ -273,6 +268,7 @@ v_paragraphb(SCR *sp, VICMD *vp)
                        INTEXT_CHECK;
                        break;
                case P_INBLANK:
+                       ++cnt;
                        if (len != 0 && !v_isempty(p, len)) {
                                if (!--cnt)
                                        goto found;

-- 
Walter

Reply via email to