Calling an mg command with zero iterations (C-u 0) seems non-sensical
but what should happen if you did? Currently some commands honour the
0 [ie. do nothing], others do not, they partially complete or complete
as if 1 had been passed. For example try and insert 0 characters via:
C-u 0 a
The function that inserts characters has an 'if' statement that
handles 0 being passed and returns before any characters are
inserted. Now try to move to the beginning of a line:
C-u 0 C-a
The case for zero iterations isn't handled and the cursor goes to the
beginning of the line. Now try tranposing 0 paragraphs:
C-u 0 M-x tranpose-paragraphs
The cursor moves to the end of the current paragraph and no
transposing is completed.
This diff makes functions that honour multiple* iterations but
currently do not honour zero iterations, honour 0 iterations.
Comments/oks?
-lum
* Functions that do not honour multiple (or non-single) iterations are
not included, e.g: M-<.
Also the tranpose-chars (C-t) function doesn't honour multiple
iterations, but probably should so it has been included in this diff.
Index: basic.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/basic.c,v
retrieving revision 1.46
diff -u -p -u -p -r1.46 basic.c
--- basic.c 26 Sep 2015 21:51:58 -0000 1.46
+++ basic.c 7 Oct 2015 14:19:24 -0000
@@ -28,6 +28,9 @@
int
gotobol(int f, int n)
{
+ if (n == 0)
+ return (TRUE);
+
curwp->w_doto = 0;
return (TRUE);
}
@@ -72,6 +75,9 @@ backchar(int f, int n)
int
gotoeol(int f, int n)
{
+ if (n == 0)
+ return (TRUE);
+
curwp->w_doto = llength(curwp->w_dotp);
return (TRUE);
}
Index: paragraph.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/paragraph.c,v
retrieving revision 1.40
diff -u -p -u -p -r1.40 paragraph.c
--- paragraph.c 26 Sep 2015 15:03:15 -0000 1.40
+++ paragraph.c 7 Oct 2015 14:19:25 -0000
@@ -142,6 +142,9 @@ fillpara(int f, int n)
struct line *eopline; /* pointer to line just past EOP
*/
char wbuf[MAXWORD]; /* buffer for current word */
+ if (n == 0)
+ return (TRUE);
+
undo_boundary_enable(FFRAND, 0);
/* record the pointer to the line just past the EOP */
@@ -267,6 +270,9 @@ killpara(int f, int n)
{
int lineno, status;
+ if (n == 0)
+ return (TRUE);
+
if (findpara() == FALSE)
return (TRUE);
@@ -298,6 +304,9 @@ markpara(int f, int n)
{
int i = 0;
+ if (n == 0)
+ return (TRUE);
+
clearmark(FFARG, 0);
if (findpara() == FALSE)
@@ -325,6 +334,9 @@ transposepara(int f, int n)
{
int i = 0, status;
char flg;
+
+ if (n == 0)
+ return (TRUE);
/* find a paragraph, set mark, then goto the end */
gotobop(FFRAND, 1);
Index: util.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/util.c,v
retrieving revision 1.36
diff -u -p -u -p -r1.36 util.c
--- util.c 29 Sep 2015 03:19:24 -0000 1.36
+++ util.c 7 Oct 2015 14:19:25 -0000
@@ -117,6 +117,9 @@ twiddle(int f, int n)
struct line *dotp;
int doto, cr;
+ if (n == 0)
+ return (TRUE);
+
dotp = curwp->w_dotp;
doto = curwp->w_doto;