From: Wayne Davison <wayne@clari.net>
To: zsh-workers@math.gatech.edu
Subject: PATCH: some minor fixes for zle_hist.c (3.1.4)
Date: Wed, 10 Jun 1998 03:56:27 -0700 [thread overview]
Message-ID: <199806101056.DAA06694@bebop.clari.net> (raw)
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---
next reply other threads:[~1998-06-10 11:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-06-10 10:56 Wayne Davison [this message]
1998-06-12 7:43 ` Bart Schaefer
1998-06-12 17:30 ` Wayne Davison
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=199806101056.DAA06694@bebop.clari.net \
--to=wayne@clari.net \
--cc=zsh-workers@math.gatech.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).