Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: some minor fixes for zle_hist.c (3.1.4)



I've fixed a couple minor bugs in zle_hist.c in 3.1.4:

 + The up-line and down-line code was duplicated in multiple spots
   in zle_hist.c, and among the different versions there was one
   inconsistency which I believe is a bug.  The code in the
   {up,down}lineorsearch() functions had this test:

	    if (cs && invicmdmode())
		cs--;

   rather than this one found in the {up,down}lineorhistory()
   functions:

	    if (cs > findbol() && invicmdmode())
		cs--;

   I believe the former is a bug when moving through a multi-line
   history entry.

   Rather than just fix this inconsistency, I decided to integrate
   the up-line code into its own function, upline(), and the down-
   line code into its own function, downline().

 + In viuplineorhistory(), if zmult was negative it called
   downlineorhistory() rather than vidownlineorhistory().  Similarly,
   vidownlineorhistory() called the wrong up-line function.

   Rather than just fix this inconsistency, I decided to eliminate
   the duplicated code by having the vi versions of these functions
   call the normal versions and just tweak cs afterwards.  This
   results in identical functionality, as far as I could tell.

   My new code does ensure that the vi{up,down}lineorhistory
   functions don't change lastcol since the old functions left it
   alone, but I'm not sure that this is really necessary.

This patch can be applied before or after applying my previous
patch for historysearch{for,back}ward.

..wayne..

---8<------8<------8<------8<---cut here--->8------>8------>8------>8---
Index: zle_hist.c
@@ -96,16 +96,16 @@
 }
 
 /**/
-void
-uplineorhistory(void)
+int
+upline(void)
 {
-    int ocs = cs, n = zmult;
+    int n = zmult;
 
     if (n < 0) {
-	zmult = -n;
-	downlineorhistory();
-	zmult = n;
-	return;
+	zmult = -zmult;
+	n = downline();
+	zmult = -zmult;
+	return n;
     }
     if (lastcol == -1)
 	lastcol = cs - findbol();
@@ -117,18 +117,7 @@
 	cs = findbol();
 	n--;
     }
-    if (n) {
-	int m = zmult;
-
-	cs = ocs;
-	if (virangeflag || !histallowed) {
-	    feep();
-	    return;
-	}
-	zmult = n;
-	uphistory();
-	zmult = m;
-    } else {
+    if (!n) {
 	int x = findeol();
 
 	if ((cs += lastcol) >= x) {
@@ -137,28 +126,15 @@
 		cs--;
 	}
     }
+    return n;
 }
 
 /**/
 void
-viuplineorhistory(void)
+uplineorhistory(void)
 {
-    int ocs = cs, n = zmult;
-
-    if (n < 0) {
-	zmult = -n;
-	downlineorhistory();
-	zmult = n;
-	return;
-    }
-    cs = findbol();
-    while (n) {
-	if (!cs)
-	    break;
-	cs--;
-	cs = findbol();
-	n--;
-    }
+    int ocs = cs;
+    int n = upline();
     if (n) {
 	int m = zmult;
 
@@ -171,6 +147,15 @@
 	uphistory();
 	zmult = m;
     }
+}
+
+/**/
+void
+viuplineorhistory(void)
+{
+    int col = lastcol;
+    uplineorhistory();
+    lastcol = col;
     vifirstnonblank();
 }
 
@@ -179,24 +164,8 @@
 void
 uplineorsearch(void)
 {
-    int ocs = cs, n = zmult;
-
-    if (n < 0) {
-	zmult = -n;
-	downlineorsearch();
-	zmult = n;
-	return;
-    }
-    if (lastcol == -1)
-	lastcol = cs - findbol();
-    cs = findbol();
-    while (n) {
-	if (!cs)
-	    break;
-	cs--;
-	cs = findbol();
-	n--;
-    }
+    int ocs = cs;
+    int n = upline();
     if (n) {
 	int m = zmult;
 
@@ -208,28 +177,20 @@
 	zmult = n;
 	historysearchbackward();
 	zmult = m;
-    } else {
-	int x = findeol();
-
-	if ((cs += lastcol) >= x) {
-	    cs = x;
-	    if (cs && invicmdmode())
-		cs--;
-	}
     }
 }
 
 /**/
-void
-downlineorhistory(void)
+int
+downline(void)
 {
-    int ocs = cs, n = zmult;
+    int n = zmult;
 
     if (n < 0) {
-	zmult = -n;
-	uplineorhistory();
-	zmult = n;
-	return;
+	zmult = -zmult;
+	n = upline();
+	zmult = -zmult;
+	return n;
     }
     if (lastcol == -1)
 	lastcol = cs - findbol();
@@ -241,18 +202,7 @@
 	cs = x + 1;
 	n--;
     }
-    if (n) {
-	int m = zmult;
-
-	cs = ocs;
-	if (virangeflag || !histallowed) {
-	    feep();
-	    return;
-	}
-	zmult = n;
-	downhistory();
-	zmult = m;
-    } else {
+    if (!n) {
 	int x = findeol();
 
 	if ((cs += lastcol) >= x) {
@@ -261,28 +211,15 @@
 		cs--;
 	}
     }
+    return n;
 }
 
 /**/
 void
-vidownlineorhistory(void)
+downlineorhistory(void)
 {
-    int ocs = cs, n = zmult;
-
-    if (n < 0) {
-	zmult = -n;
-	uplineorhistory();
-	zmult = n;
-	return;
-    }
-    while (n) {
-	int x = findeol();
-
-	if (x == ll)
-	    break;
-	cs = x + 1;
-	n--;
-    }
+    int ocs = cs;
+    int n = downline();
     if (n) {
 	int m = zmult;
 
@@ -295,6 +232,15 @@
 	downhistory();
 	zmult = m;
     }
+}
+
+/**/
+void
+vidownlineorhistory(void)
+{
+    int col = lastcol;
+    downlineorhistory();
+    lastcol = col;
     vifirstnonblank();
 }
 
@@ -302,24 +248,8 @@
 void
 downlineorsearch(void)
 {
-    int ocs = cs, n = zmult;
-
-    if (n < 0) {
-	zmult = -n;
-	uplineorsearch();
-	zmult = n;
-	return;
-    }
-    if (lastcol == -1)
-	lastcol = cs - findbol();
-    while (n) {
-	int x = findeol();
-
-	if (x == ll)
-	    break;
-	cs = x + 1;
-	n--;
-    }
+    int ocs = cs;
+    int n = downline();
     if (n) {
 	int m = zmult;
 
@@ -331,14 +261,6 @@
 	zmult = n;
 	historysearchforward();
 	zmult = m;
-    } else {
-	int x = findeol();
-
-	if ((cs += lastcol) >= x) {
-	    cs = x;
-	    if (cs && invicmdmode())
-		cs--;
-	}
     }
 }
 
---8<------8<------8<------8<---cut here--->8------>8------>8------>8---



Messages sorted by: Reverse Date, Date, Thread, Author