about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSven Wischnowsky <wischnow@users.sourceforge.net>2000-05-05 07:42:36 +0000
committerSven Wischnowsky <wischnow@users.sourceforge.net>2000-05-05 07:42:36 +0000
commitc844ad87127784e504dea096323262b9cda35837 (patch)
tree1ceb3a7385d453531362bc37f601c4aad5e51d21
parentc05f118fc2f40d8e4b1b73926c5d74a6dc14281a (diff)
downloadzsh-c844ad87127784e504dea096323262b9cda35837.tar.gz
zsh-c844ad87127784e504dea096323262b9cda35837.tar.xz
zsh-c844ad87127784e504dea096323262b9cda35837.zip
Wayne: fix for print -s when called from widget; added lines are not immediately available, though (11171)
-rw-r--r--ChangeLog4
-rw-r--r--Src/builtin.c2
-rw-r--r--Src/hist.c69
3 files changed, 49 insertions, 26 deletions
diff --git a/ChangeLog b/ChangeLog
index df1759dc0..34b5d21aa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2000-05-05  Sven Wischnowsky  <wischnow@informatik.hu-berlin.de>
 
+	* Wayne: 11171: Src/builtin.c, Src/hist.c: fix for print -s when
+	called from widget; added lines are not immediately available,
+	though
+
 	* 11172: Src/Zle/computil.c: fix for completion arguments of
  	options, don't use all of them at once
 	
diff --git a/Src/builtin.c b/Src/builtin.c
index bca0ab33f..68155d2c6 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -2777,7 +2777,7 @@ bin_print(char *name, char **args, char *ops, int func)
 	int nwords = 0, nlen, iwords;
 	char **pargs = args;
 
-	ent = prepnexthistent(zleactive ? curhist++ : ++curhist);
+	ent = prepnexthistent();
 	while (*pargs++)
 	    nwords++;
 	if ((ent->nwords = nwords)) {
diff --git a/Src/hist.c b/Src/hist.c
index e869e3a2e..9f35c4cd2 100644
--- a/Src/hist.c
+++ b/Src/hist.c
@@ -704,6 +704,36 @@ nohwe(void)
 {
 }
 
+/* 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 @@ hbegin(int dohist)
     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 @@ gethistent(int ev, int nearmatch)
 
 /**/
 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 @@ prepnexthistent(int histnum)
 	}
 	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 @@ hend(void)
 	  "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 @@ hend(void)
 	    freehistdata(he, 0);
 	} else {
 	    keepflags = 0;
-	    he = prepnexthistent(++curhist);
+	    he = prepnexthistent();
 	}
 
 	he->text = ztrdup(chline);
@@ -1777,7 +1796,7 @@ readhistfile(char *fn, int err, int readflags)
 		lasthist.stim = stim;
 	    }
 
-	    he = prepnexthistent(++curhist);
+	    he = prepnexthistent();
 	    he->text = ztrdup(pt);
 	    he->flags = newflags;
 	    if ((he->stim = stim) == 0)