lichray / nvi2

A multibyte fork of the nvi editor for BSD
Other
144 stars 34 forks source link

vi(1) moves 2x amount of paragraphs with 'para' options #118

Closed lichray closed 1 year ago

lichray commented 1 year ago

Reported by: Walter Alejandro Iglesias wai@roquesor.com

Using the move forward with paragraphs separated by tags (those in para options) as in the example below doesn't move the cursor to the right place.

Example:

Open with vi(1) a file containing the following lines. Put your cursor at the '1' or in the empty line right above, and try using '}' (move to next paragraph) with different number prefixes (placing again the cursor at "1" each time).

1

2

3

4

5

6

There it works as expected. Now repeat the same on these lines (keeping paragraphs option untouched):

.PP
1
.PP
2
.PP
3
.PP
4
.PP
5
.PP
6

The prefixes in this case will move your cursor to "prefix + prefix - 1" paragraphs. This is:

and so on.

Finally, repeat the same steps on these lines:

.PP 1
.PP 2
.PP 3
.PP 4
.PP 5
.PP 6
.PP 7
.PP 8

Now the cursor will go "prefix *= 2"

It behaves in the same fashion moving to previous paragraphs.

I took a look to this file:

/usr/src/usr.bin/vi/vi/v_paragraph.c

But I wasn't able to understand what it does. Especially this part:

/*
 * If we start in text, we want to switch states
 * (2 * N - 1) times, in non-text, (2 * N) times.
 */
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;
}