From: Wayne Davison <wayne@clari.net>
To: Zsh Workers <zsh-workers@sunsite.auc.dk>
Subject: PATCH: History bug with "print -s"
Date: Fri, 5 May 2000 00:25:23 -0700 (PDT) [thread overview]
Message-ID: <Pine.GSO.4.21.0005050005350.18195-100000@house.clari.net> (raw)
In-Reply-To: <1000504173903.ZM28133@candle.brasslantern.com>
Appended is a patch that should fix the funkiness associated with
running "print -s" while zle is active. I've done some very basic
testing, and it appears to work fine.
However, if "print -s" is supposed to make the line immediately
available for history browsing (before pressing return), that is not
happening. I can check into this next, but I don't have time to do
that right now.
The following diff is based on an unpatched 3.1.7-pre-2.
..wayne..
---8<------8<------8<------8<---cut here--->8------>8------>8------>8---
Index: Src/builtin.c
@@ -2777,7 +2777,7 @@
int nwords = 0, nlen, iwords;
char **pargs = args;
- ent = prepnexthistent(++curhist);
+ ent = prepnexthistent();
while (*pargs++)
nwords++;
if ((ent->nwords = nwords)) {
Index: Src/hist.c
@@ -704,6 +704,36 @@
{
}
+/* these functions handle adding/removing curline to/from the hist_ring */
+
+static void
+linkcurline(void)
+{
+ if (!hist_ring)
+ hist_ring = curline.up = curline.down = &curline;
+ else {
+ curline.up = hist_ring;
+ curline.down = hist_ring->down;
+ hist_ring->down = hist_ring->down->up = &curline;
+ hist_ring = &curline;
+ }
+ curline.histnum = ++curhist;
+}
+
+static void
+unlinkcurline(void)
+{
+ curline.up->down = curline.down;
+ curline.down->up = curline.up;
+ if (hist_ring == &curline) {
+ if (!histlinect)
+ hist_ring = NULL;
+ else
+ hist_ring = curline.up;
+ }
+ curhist--;
+}
+
/* initialize the history mechanism */
/**/
@@ -745,15 +775,7 @@
if (interact && isset(SHINSTDIN) && !strin) {
histactive = HA_ACTIVE;
attachtty(mypgrp);
- if (!hist_ring)
- hist_ring = curline.up = curline.down = &curline;
- else {
- curline.up = hist_ring;
- curline.down = hist_ring->down;
- hist_ring->down = hist_ring->down->up = &curline;
- hist_ring = &curline;
- }
- curline.histnum = ++curhist;
+ linkcurline();
defev = addhistnum(curhist, -1, HIST_FOREIGN);
} else
histactive = HA_ACTIVE | HA_NOINC;
@@ -883,9 +905,13 @@
/**/
Histent
-prepnexthistent(int histnum)
+prepnexthistent(void)
{
Histent he;
+ int curline_in_ring = hist_ring == &curline;
+
+ if (curline_in_ring)
+ unlinkcurline();
if (histlinect < histsiz) {
he = (Histent)zcalloc(sizeof *he);
@@ -920,8 +946,10 @@
}
freehistdata(hist_ring = he, 0);
}
- hist_ring->histnum = histnum;
- return hist_ring;
+ he->histnum = ++curhist;
+ if (curline_in_ring)
+ linkcurline();
+ return he;
}
/* say we're done using the history mechanism */
@@ -937,17 +965,8 @@
"BUG: chline is NULL in hend()");
if (histdone & HISTFLAG_SETTY)
settyinfo(&shttyinfo);
- if (!(histactive & HA_NOINC)) {
- curline.up->down = curline.down;
- curline.down->up = curline.up;
- if (hist_ring == &curline) {
- if (!histlinect)
- hist_ring = NULL;
- else
- hist_ring = curline.up;
- }
- curhist--;
- }
+ if (!(histactive & HA_NOINC))
+ unlinkcurline();
if (histactive & (HA_NOSTORE|HA_NOINC)) {
zfree(chline, hlinesz);
zfree(chwords, chwordlen*sizeof(short));
@@ -1023,7 +1042,7 @@
freehistdata(he, 0);
} else {
keepflags = 0;
- he = prepnexthistent(++curhist);
+ he = prepnexthistent();
}
he->text = ztrdup(chline);
@@ -1777,7 +1796,7 @@
lasthist.stim = stim;
}
- he = prepnexthistent(++curhist);
+ he = prepnexthistent();
he->text = ztrdup(pt);
he->flags = newflags;
if ((he->stim = stim) == 0)
---8<------8<------8<------8<---cut here--->8------>8------>8------>8---
next prev parent reply other threads:[~2000-05-05 7:25 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-05-04 15:34 PATCH: Re: History bug (Re: Completion debugging) Sven Wischnowsky
2000-05-04 17:39 ` Bart Schaefer
2000-05-04 20:55 ` Wayne Davison
2000-05-05 7:25 ` Wayne Davison [this message]
2000-05-05 7:44 PATCH: History bug with "print -s" Sven Wischnowsky
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=Pine.GSO.4.21.0005050005350.18195-100000@house.clari.net \
--to=wayne@clari.net \
--cc=zsh-workers@sunsite.auc.dk \
/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).