zsh-workers
 help / color / mirror / code / Atom feed
* Minor change for new isearch code
@ 1996-05-12 18:48 Wayne Davison
  1996-05-13  1:12 ` Zoltan Hidvegi
  0 siblings, 1 reply; 5+ messages in thread
From: Wayne Davison @ 1996-05-12 18:48 UTC (permalink / raw)
  To: Zsh hacking and development

Here's a minor tweak for the incremental search code based on my last
patch.  It just makes the startup case where you begin the search from
somewhere in the history a little more efficient by using the metafied
history entry directly rather than building one from "line".

Index: zle_hist.c
@@ -637,7 +637,7 @@
 	s = curhistline = metafy(UTOSCP(line), ll, META_DUP);
     }
     else
-	s = metafy(UTOSCP(line), ll, META_USEHEAP);
+	s = qgetevent(histline);
     bindtab = mainbindtab;
     pos = metalen(s, cs);
     for (;;) {

..wayne..



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Minor change for new isearch code
  1996-05-12 18:48 Minor change for new isearch code Wayne Davison
@ 1996-05-13  1:12 ` Zoltan Hidvegi
  1996-05-13 11:22   ` Wayne Davison
  0 siblings, 1 reply; 5+ messages in thread
From: Zoltan Hidvegi @ 1996-05-13  1:12 UTC (permalink / raw)
  To: Wayne Davison; +Cc: zsh-workers

[-- Attachment #1: Type: application/pgp, Size: 5198 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Minor change for new isearch code
  1996-05-13  1:12 ` Zoltan Hidvegi
@ 1996-05-13 11:22   ` Wayne Davison
  1996-05-14  3:11     ` Zoltan Hidvegi
  0 siblings, 1 reply; 5+ messages in thread
From: Wayne Davison @ 1996-05-13 11:22 UTC (permalink / raw)
  To: Zoltan Hidvegi; +Cc: zsh-workers

Zoltan Hidvegi writes:
> If I go back in the history, modify a line and start an isearch the
> modifications will disappear.

This is actually a more widespread problem in zsh than just the isearch
code.  If I start to edit a history line and go to another history line
via something like Ctrl-P (previous line in emacs mode) my modifications
will also disappear.  I would like to see this fixed for all functions.

How about this.  Unapply your last patch to zle_hist.c and apply this one
instead.  This code creates a function remember_edits() that remembers
the edits to whatever history line we're on and stashes the real history
line in a linked list for later retrieval (I used a linked list just
because it was memory efficient).  When the user presses return a new
function called forget_edits() restores all the edited history lines to
their original values.

I put a call to remember_edits() in quite a few functions in zle_hist.c,
but if you like this code, there are undoubtedly more functions that will
need to call it.  Also, there may be other functions besides the ones
that had "accept" in their name that require the forget_edits() call.

..wayne..
---8<------8<------8<------8<---cut here--->8------>8------>8------>8---
Index: zle_hist.c
@@ -32,6 +32,62 @@
 #define ZLE
 #include "zsh.h"
 
+struct modified {
+    struct modified *next;
+    char *text;
+    int histnum;
+} *hist_mods;
+
+/**/
+void
+remember_edits(void)
+{
+    if (histline == curhist) {
+	zsfree(curhistline);
+	curhistline = metafy(UTOSCP(line), ll, META_DUP);
+    }
+    else {
+	struct modified *node = hist_mods, *prev = NULL;
+	Histent ent = gethistent(histline);
+
+	while (node && node->histnum < histline) {
+	    prev = node;
+	    node = node->next;
+	}
+	if (!node || node->histnum != histline) {
+	    struct modified *newnode = (struct modified *)zalloc(sizeof *node);
+
+	    newnode->next = node;
+	    newnode->histnum = histline;
+	    newnode->text = ent->text;
+	    if (!prev)
+		hist_mods = newnode;
+	    else
+		prev->next = newnode;
+	} else
+	    free(ent->text);
+
+	ent->text = metafy(UTOSCP(line), ll, META_DUP);
+    }
+}
+
+/**/
+void
+forget_edits(void)
+{
+    struct modified *node, *next;
+    Histent ent;
+
+    for (node = hist_mods; node; node = next) {
+	next = node->next;
+	ent = gethistent(node->histnum);
+	free(ent->text);
+	ent->text = node->text;
+	free((char*)node);
+    }
+    hist_mods = NULL;
+}
+
 /**/
 void
 uphistory(void)
@@ -43,10 +99,7 @@
 	downhistory();
 	return;
     }
-    if (histline == curhist) {
-	zsfree(curhistline);
-	curhistline = metafy(UTOSCP(line), ll, META_DUP);
-    }
+    remember_edits();
     histline -= mult;
     if (!(s = qgetevent(histline))) {
 	if (unset(NOHISTBEEP))
@@ -281,6 +334,7 @@
 {
     char *s;
 
+    forget_edits();
     if (!(s = qgetevent(histline + 1))) {
 	feep();
 	return;
@@ -301,6 +355,7 @@
 	uphistory();
 	return;
     }
+    remember_edits();
     histline += mult;
     if (!(s = qgetevent(histline))) {
 	if (unset(NOHISTBEEP))
@@ -320,10 +375,7 @@
     int t0, ohistline = histline;
     char *s;
 
-    if (histline == curhist) {
-	zsfree(curhistline);
-	curhistline = metafy(UTOSCP(line), ll, META_DUP);
-    }
+    remember_edits();
     if (lastcmd & ZLE_HISTSEARCH)
 	t0 = histpos;
     else {
@@ -353,10 +405,7 @@
     int t0, ohistline = histline;
     char *s;
 
-    if (histline == curhist) {
-	zsfree(curhistline);
-	curhistline = metafy(UTOSCP(line), ll, META_DUP);
-    }
+    remember_edits();
     if (lastcmd & ZLE_HISTSEARCH)
 	t0 = histpos;
     else {
@@ -395,10 +444,7 @@
 {
     char *s;
 
-    if (histline == curhist) {
-	zsfree(curhistline);
-	curhistline = metafy(UTOSCP(line), ll, META_DUP);
-    }
+    remember_edits();
     if (!(s = qgetevent(firsthist()))) {
 	if (unset(NOHISTBEEP))
 	    feep();
@@ -632,12 +678,8 @@
 
     strcpy(ibuf, ISEARCH_PROMPT);
     memcpy(ibuf + NORM_PROMPT_POS, (dir == 1) ? "fwd" : "bck", 3);
-    if (histline == curhist) {
-	zsfree(curhistline);
-	s = curhistline = metafy(UTOSCP(line), ll, META_DUP);
-    }
-    else
-	s = qgetevent(histline);
+    remember_edits();
+    s = qgetevent(histline);
     bindtab = mainbindtab;
     pos = metalen(s, cs);
     for (;;) {
@@ -834,6 +876,7 @@
     int t0;
     char *s;
 
+    forget_edits();
     done = 1;
     for (t0 = histline - 2;; t0--) {
 	if (!(s = qgetevent(t0)))
@@ -1024,10 +1067,7 @@
 	return;
     }
     t0 = strlen(visrchstr);
-    if (histline == curhist) {
-	zsfree(curhistline);
-	curhistline = metafy(UTOSCP(line), ll, META_DUP);
-    }
+    remember_edits();
     for (;;) {
 	histline += visrchsense;
 	if (!(s = qgetevent(histline))) {
@@ -1067,10 +1107,7 @@
     int ohistline = histline;
     char *s;
 
-    if (histline == curhist) {
-	zsfree(curhistline);
-	curhistline = metafy(UTOSCP(line), ll, META_DUP);
-    }
+    remember_edits();
     for (;;) {
 	histline--;
 	if (!(s = qgetevent(histline))) {
@@ -1098,10 +1135,7 @@
     int ohistline = histline;
     char *s;
 
-    if (histline == curhist) {
-	zsfree(curhistline);
-	curhistline = metafy(UTOSCP(line), ll, META_DUP);
-    }
+    remember_edits();
     for (;;) {
 	histline++;
 	if (!(s = qgetevent(histline))) {
Index: zle_misc.c
@@ -256,6 +256,7 @@
 void
 acceptline(void)
 {
+    forget_edits();
     done = 1;
 }
 
@@ -265,6 +266,7 @@
 {
     pushnode(bufstack, ztrdup((char *)line));
     stackcs = cs;
+    forget_edits();
     done = 1;
 }
 
---8<------8<------8<------8<---cut here--->8------>8------>8------>8---



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Minor change for new isearch code
  1996-05-13 11:22   ` Wayne Davison
@ 1996-05-14  3:11     ` Zoltan Hidvegi
  1996-05-14 17:21       ` Wayne Davison
  0 siblings, 1 reply; 5+ messages in thread
From: Zoltan Hidvegi @ 1996-05-14  3:11 UTC (permalink / raw)
  To: Wayne Davison; +Cc: Zsh hacking and development

[-- Attachment #1: Type: application/pgp, Size: 14747 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Minor change for new isearch code
  1996-05-14  3:11     ` Zoltan Hidvegi
@ 1996-05-14 17:21       ` Wayne Davison
  0 siblings, 0 replies; 5+ messages in thread
From: Wayne Davison @ 1996-05-14 17:21 UTC (permalink / raw)
  To: Zoltan Hidvegi; +Cc: Zsh hacking and development

Zoltan Hidvegi writes:
> Here is a complete revision of the patches in articles 1062 and 1063
> from Wayne.

Fair enough.  You missed a couple strlen() -> ztrlen() changes
in the history-search-* functions, however.  BUT, since your
new metadiffer() function can differentiate between an exact match
and a substring match, the ztrlen() call isn't even needed if we
disallow the 0 return value.  My patch is appended.

This patch also corrects a minor typo in the comment prior to
metadiffer() and moves the assignment of histpos (a trivial
optimization).

..wayne..
---8<------8<------8<------8<---cut here--->8------>8------>8------>8---
Index: utils.c
@@ -2948,7 +2948,7 @@
 	return 1;
 }
 
-/* Return zero if the metafied string s differs and the non-metafied, *
+/* Return zero if the metafied string s and the non-metafied,         *
  * len-long string r are the same.  Return -1 if r is a prefix of s   *
  * and return 1 otherwise.                                            */
 
Index: zle_hist.c
@@ -355,8 +355,8 @@
 	for (t0 = 0; t0 < ll && !iblank(line[t0]); t0++);
 	if (t0 < ll)
 	    t0++;
+	histpos = t0;
     }
-    histpos = t0;
     for (;;) {
 	histline--;
 	if (!(s = zle_get_event(histline))) {
@@ -364,8 +364,7 @@
 	    histline = ohistline;
 	    return;
 	}
-	if (strlen(UTOSCP(s)) > t0 &&
-	    metadiffer(s, UTOSCP(line), t0) < 1 &&
+	if (metadiffer(s, UTOSCP(line), t0) < 0 &&
 	    metadiffer(s, UTOSCP(line), ll))
 	    break;
     }
@@ -386,8 +385,8 @@
 	for (t0 = 0; t0 < ll && !iblank(line[t0]); t0++);
 	if (t0 < ll)
 	    t0++;
+	histpos = t0;
     }
-    histpos = t0;
     for (;;) {
 	histline++;
 	if (!(s = zle_get_event(histline))) {
@@ -395,8 +394,7 @@
 	    histline = ohistline;
 	    return;
 	}
-	if ((histline == curhist || strlen(UTOSCP(s)) > t0) && 
-	    metadiffer(s, UTOSCP(line), t0) < 1 &&
+	if (metadiffer(s, UTOSCP(line), t0) < (histline == curhist) &&
 	    metadiffer(s, UTOSCP(line), ll))
 	    break;
     }
@@ -1101,8 +1099,7 @@
 	    histline = ohistline;
 	    return;
 	}
-	if (ztrlen((char *)s) > cs &&
-	    metadiffer(s, (char *)line, cs) < 1 &&
+	if (metadiffer(s, (char *)line, cs) < 0 &&
 	    metadiffer(s, (char *)line, ll))
 	    break;
     }
@@ -1130,8 +1127,7 @@
 	    histline = ohistline;
 	    return;
 	}
-	if ((histline == curhist || ztrlen((char *)s) > cs) &&
-	    metadiffer(s, (char *)line, cs) < 1 &&
+	if (metadiffer(s, (char *)line, cs) < (histline == curhist) &&
 	    metadiffer(s, (char *)line, ll))
 	    break;
     }
---8<------8<------8<------8<---cut here--->8------>8------>8------>8---



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~1996-05-14 17:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-05-12 18:48 Minor change for new isearch code Wayne Davison
1996-05-13  1:12 ` Zoltan Hidvegi
1996-05-13 11:22   ` Wayne Davison
1996-05-14  3:11     ` Zoltan Hidvegi
1996-05-14 17:21       ` Wayne Davison

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).