From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from euclid.skiles.gatech.edu (list@euclid.skiles.gatech.edu [130.207.146.50]) by melb.werple.net.au (8.7.5/8.7.3) with ESMTP id NAA04324 for ; Tue, 14 May 1996 13:26:55 +1000 (EST) Received: (from list@localhost) by euclid.skiles.gatech.edu (8.7.3/8.7.3) id XAA04997; Mon, 13 May 1996 23:13:30 -0400 (EDT) Resent-Date: Mon, 13 May 1996 23:13:30 -0400 (EDT) From: Zoltan Hidvegi Message-Id: <199605140311.FAA01491@hzoli.ppp.cs.elte.hu> Subject: Re: Minor change for new isearch code To: wayne@tenor.clarinet.com (Wayne Davison) Date: Tue, 14 May 1996 05:11:30 +0200 (MET DST) Cc: zsh-workers@math.gatech.edu (Zsh hacking and development) In-Reply-To: <199605131122.EAA04552@tenor.clari.net> from Wayne Davison at "May 13, 96 04:22:27 am" X-Mailer: ELM [version 2.4ME+ PL11 (25)] MIME-Version: 1.0 Content-Type: application/pgp; format=text; x-action=sign Content-Transfer-Encoding: 7bit Resent-Message-ID: <"7ilVV.0._D1.Pf_bn"@euclid> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/1065 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu -----BEGIN PGP SIGNED MESSAGE----- > 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. I like the idea but I do not like the implementations details. Here is a complete revision of the patches in articles 1062 and 1063 from Wayne. Undo my previous patch if you want to try this. It also fixes infer-next-history to make it work as documented and do not dump core. Zoltan *** Src/zsh.h 1996/05/13 02:15:45 2.10 --- Src/zsh.h 1996/05/14 02:13:41 *************** *** 849,854 **** --- 849,855 ---- struct histent { char *text; /* the history line itself */ + char *zle_text; /* the edited history line */ time_t stim; /* command started time (datestamp) */ time_t ftim; /* command finished time */ short *words; /* Position of words in history */ *** Src/utils.c 1996/05/13 02:15:45 2.20 --- Src/utils.c 1996/05/14 02:57:27 *************** *** 2949,2954 **** --- 2949,2969 ---- return 1; } + /* Return zero if the metafied string s differs and the non-metafied, * + * len-long string r are the same. Return -1 if r is a prefix of s * + * and return 1 otherwise. */ + + /**/ + int + metadiffer(char const *s, char const *r, int len) + { + while (len-- && *s && *r++ == (*s == Meta ? *++s ^ 32 : *s)) + s++; + if (*s && len < 0) + return -1; + return len >= 0; + } + /* Return the unmetafied length of a metafied string. */ /**/ *** Src/zle_hist.c 1996/05/12 11:31:09 2.9 --- Src/zle_hist.c 1996/05/14 02:45:42 *************** *** 34,39 **** --- 34,69 ---- /**/ void + remember_edits(void) + { + if (histline == curhist) { + zsfree(curhistline); + curhistline = metafy(UTOSCP(line), ll, META_DUP); + } + else { + Histent ent = gethistent(histline); + + if (metadiffer(ent->zle_text ? ent->zle_text : ent->text, line, ll)) { + zsfree(ent->zle_text); + ent->zle_text = metafy(UTOSCP(line), ll, META_DUP); + } + } + } + + /**/ + void + forget_edits(void) + { + int i; + + for (i = 0; i < histentct; i++) { + zsfree(histentarr[i].zle_text); + histentarr[i].zle_text = NULL; + } + } + + /**/ + void uphistory(void) { char *s; *************** *** 43,54 **** downhistory(); return; } ! if (histline == curhist) { ! zsfree(curhistline); ! curhistline = metafy(UTOSCP(line), ll, META_DUP); ! } histline -= mult; ! if (!(s = qgetevent(histline))) { if (unset(NOHISTBEEP)) feep(); histline += mult; --- 73,81 ---- downhistory(); return; } ! remember_edits(); histline -= mult; ! if (!(s = zle_get_event(histline))) { if (unset(NOHISTBEEP)) feep(); histline += mult; *************** *** 281,287 **** { char *s; ! if (!(s = qgetevent(histline + 1))) { feep(); return; } --- 308,314 ---- { char *s; ! if (!(s = zle_get_event(histline + 1))) { feep(); return; } *************** *** 301,308 **** uphistory(); return; } histline += mult; ! if (!(s = qgetevent(histline))) { if (unset(NOHISTBEEP)) feep(); histline -= mult; --- 328,336 ---- uphistory(); return; } + remember_edits(); histline += mult; ! if (!(s = zle_get_event(histline))) { if (unset(NOHISTBEEP)) feep(); histline -= mult; *************** *** 320,329 **** int t0, ohistline = histline; char *s; ! if (histline == curhist) { ! zsfree(curhistline); ! curhistline = metafy(UTOSCP(line), ll, META_DUP); ! } if (lastcmd & ZLE_HISTSEARCH) t0 = histpos; else { --- 348,354 ---- int t0, ohistline = histline; char *s; ! remember_edits(); if (lastcmd & ZLE_HISTSEARCH) t0 = histpos; else { *************** *** 334,346 **** histpos = t0; for (;;) { histline--; ! if (!(s = qgetevent(histline))) { feep(); histline = ohistline; return; } ! if (strlen(UTOSCP(s)) > t0 ! && !strncmp(s, UTOSCP(line), t0) && strcmp(s, UTOSCP(line))) break; } setline(s); --- 359,372 ---- histpos = t0; for (;;) { histline--; ! if (!(s = zle_get_event(histline))) { feep(); histline = ohistline; return; } ! if (strlen(UTOSCP(s)) > t0 && ! metadiffer(s, UTOSCP(line), t0) < 1 && ! metadiffer(s, UTOSCP(line), ll)) break; } setline(s); *************** *** 353,362 **** int t0, ohistline = histline; char *s; ! if (histline == curhist) { ! zsfree(curhistline); ! curhistline = metafy(UTOSCP(line), ll, META_DUP); ! } if (lastcmd & ZLE_HISTSEARCH) t0 = histpos; else { --- 379,385 ---- int t0, ohistline = histline; char *s; ! remember_edits(); if (lastcmd & ZLE_HISTSEARCH) t0 = histpos; else { *************** *** 367,379 **** histpos = t0; for (;;) { histline++; ! if (!(s = qgetevent(histline))) { feep(); histline = ohistline; return; } ! if (strlen(UTOSCP(s)) > t0 ! && !strncmp(s, UTOSCP(line), t0) && strcmp(s, UTOSCP(line))) break; } setline(s); --- 390,403 ---- histpos = t0; for (;;) { histline++; ! if (!(s = zle_get_event(histline))) { feep(); histline = ohistline; return; } ! if ((histline == curhist || strlen(UTOSCP(s)) > t0) && ! metadiffer(s, UTOSCP(line), t0) < 1 && ! metadiffer(s, UTOSCP(line), ll)) break; } setline(s); *************** *** 395,405 **** { char *s; ! if (histline == curhist) { ! zsfree(curhistline); ! curhistline = metafy(UTOSCP(line), ll, META_DUP); ! } ! if (!(s = qgetevent(firsthist()))) { if (unset(NOHISTBEEP)) feep(); return; --- 419,426 ---- { char *s; ! remember_edits(); ! if (!(s = zle_get_event(firsthist()))) { if (unset(NOHISTBEEP)) feep(); return; *************** *** 426,431 **** --- 447,453 ---- if (unset(NOHISTBEEP)) feep(); } else { + remember_edits(); histline = curhist; setline(curhistline); } *************** *** 481,492 **** char * qgetevent(int ev) { - if (ev > curhist) - return NULL; return ((ev == curhist) ? curhistline : quietgetevent(ev)); } /**/ void pushline(void) { --- 503,529 ---- char * qgetevent(int ev) { return ((ev == curhist) ? curhistline : quietgetevent(ev)); } /**/ + char * + zle_get_event(int ev) + { + Histent ent; + + if (ev == curhist) + return curhistline; + if (! (ent = quietgethist(ev))) + return NULL; + if (ent->zle_text) + return ent->zle_text; + return ent->text; + } + + + + /**/ void pushline(void) { *************** *** 630,641 **** 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 = metafy(UTOSCP(line), ll, META_USEHEAP); bindtab = mainbindtab; pos = metalen(s, cs); for (;;) { --- 667,674 ---- strcpy(ibuf, ISEARCH_PROMPT); memcpy(ibuf + NORM_PROMPT_POS, (dir == 1) ? "fwd" : "bck", 3); ! remember_edits(); ! s = zle_get_event(histline); bindtab = mainbindtab; pos = metalen(s, cs); for (;;) { *************** *** 678,684 **** break; } histline += dir; ! if (!(s = qgetevent(histline))) { if (sbptr == (int)isrch_spots[top_spot-1].len && (isrch_spots[top_spot-1].flags & ISS_FAILING)) top_spot--; --- 711,717 ---- break; } histline += dir; ! if (!(s = zle_get_event(histline))) { if (sbptr == (int)isrch_spots[top_spot-1].len && (isrch_spots[top_spot-1].flags & ISS_FAILING)) top_spot--; *************** *** 708,714 **** if ((cmd = getkeycmd()) < 0 || cmd == z_sendbreak) { int i; get_isrch_spot(0, &histline, &pos, &i, &sbptr, &dir, &nomatch); ! s = qgetevent(histline); setline(s); cs = i; break; --- 741,747 ---- if ((cmd = getkeycmd()) < 0 || cmd == z_sendbreak) { int i; get_isrch_spot(0, &histline, &pos, &i, &sbptr, &dir, &nomatch); ! s = zle_get_event(histline); setline(s); cs = i; break; *************** *** 734,740 **** statusline = ibuf; skip_pos = 1; } ! s = qgetevent(histline); if (!sbptr || (sbptr == 1 && sbuf[0] == '^')) { int i = cs; setline(s); --- 767,773 ---- statusline = ibuf; skip_pos = 1; } ! s = zle_get_event(histline); if (!sbptr || (sbptr == 1 && sbuf[0] == '^')) { int i = cs; setline(s); *************** *** 850,873 **** infernexthistory(void) { int t0; ! char *s, *t; - if (!(t = qgetevent(histline - 1))) { - feep(); - return; - } for (t0 = histline - 2;; t0--) { if (!(s = qgetevent(t0))) { feep(); return; } ! if (!strcmp(s, t)) break; } if (!(s = qgetevent(t0 + 1))) { feep(); return; } histline = t0 + 1; setline(s); } --- 883,903 ---- infernexthistory(void) { int t0; ! char *s; for (t0 = histline - 2;; t0--) { if (!(s = qgetevent(t0))) { feep(); return; } ! if (! metadiffer(s, line, ll)) break; } if (!(s = qgetevent(t0 + 1))) { feep(); return; } + remember_edits(); histline = t0 + 1; setline(s); } *************** *** 886,894 **** cs = findbol(); return; } - zsfree(curhistline); - curhistline = metafy(UTOSCP(line), ll, META_DUP); } if (!gotmult) mult = curhist; if (!(s = qgetevent(mult))) --- 916,923 ---- cs = findbol(); return; } } + remember_edits(); if (!gotmult) mult = curhist; if (!(s = qgetevent(mult))) *************** *** 1022,1034 **** return; } t0 = strlen(visrchstr); ! if (histline == curhist) { ! zsfree(curhistline); ! curhistline = metafy(UTOSCP(line), ll, META_DUP); ! } for (;;) { histline += visrchsense; ! if (!(s = qgetevent(histline))) { feep(); histline = ohistline; return; --- 1051,1060 ---- return; } t0 = strlen(visrchstr); ! remember_edits(); for (;;) { histline += visrchsense; ! if (!(s = zle_get_event(histline))) { feep(); histline = ohistline; return; *************** *** 1065,1084 **** int ohistline = histline; char *s; ! if (histline == curhist) { ! zsfree(curhistline); ! curhistline = metafy(UTOSCP(line), ll, META_DUP); ! } for (;;) { histline--; ! if (!(s = qgetevent(histline))) { feep(); histline = ohistline; return; } ! if (strlen((char *)s) > cs && ! !memcmp(s, (char *)line, cs) && ! (strlen((char *)s) > ll || memcmp(s, (char *)line, ll))) break; } --- 1091,1107 ---- int ohistline = histline; char *s; ! remember_edits(); for (;;) { histline--; ! if (!(s = zle_get_event(histline))) { feep(); histline = ohistline; return; } ! if (ztrlen((char *)s) > cs && ! metadiffer(s, (char *)line, cs) < 1 && ! metadiffer(s, (char *)line, ll)) break; } *************** *** 1097,1116 **** int ohistline = histline; char *s; ! if (histline == curhist) { ! zsfree(curhistline); ! curhistline = metafy(UTOSCP(line), ll, META_DUP); ! } for (;;) { histline++; ! if (!(s = qgetevent(histline))) { feep(); histline = ohistline; return; } ! if ((histline == curhist || strlen((char *)s) > cs) && ! !memcmp(s, (char *)line, cs) && ! (strlen((char *)s) > ll || memcmp(s, (char *)line, ll))) break; } --- 1120,1136 ---- int ohistline = histline; char *s; ! remember_edits(); for (;;) { histline++; ! if (!(s = zle_get_event(histline))) { feep(); histline = ohistline; return; } ! if ((histline == curhist || ztrlen((char *)s) > cs) && ! metadiffer(s, (char *)line, cs) < 1 && ! metadiffer(s, (char *)line, ll)) break; } *** Src/zle_main.c 1996/05/10 21:01:56 2.10 --- Src/zle_main.c 1996/05/14 02:11:13 *************** *** 495,500 **** --- 495,501 ---- line[ll++] = '\n'; line = metafy(line, ll, META_REALLOC); } + forget_edits(); errno = old_errno; return line; } -----BEGIN PGP SIGNATURE----- Version: 2.6.3i Charset: noconv iQCVAwUBMZf5xwupSCiLN749AQEe9QP/WFNMoiZvIfePhQnzd/TJaiTzqIGiGhgC Q6z1/b4dEe3X88cNbVUCNkgeb8EBwAamSJ/RN6g+QadA5gGxMEWETXK1BkykSTL7 h2rKJpldG90GL7gsp6m0+3odmPtXUrmYHb1DQ1RYpzaY1bJ6HYrcH66etBUVoHFv NO/eD7S7odQ= =FL+C -----END PGP SIGNATURE-----