* History !# substitutions
@ 1996-05-29 5:33 Bart Schaefer
1996-05-29 8:19 ` Peter Stephenson
0 siblings, 1 reply; 8+ messages in thread
From: Bart Schaefer @ 1996-05-29 5:33 UTC (permalink / raw)
To: zsh-workers
The !# substitution, which shuffles words from the current command line,
has always been a bit flaky in zsh, but now it seems to be broken entirely.
zagzig% echo foo bar !#:1
zsh: no words available from current command
(It should have echoed "foo bar foo".)
I'm not sure when this broke, but it was sometime before beta15-hzoli14.
I suspect it's related to the behavior of "fc" in the "fed" function that
was posted here a few days ago, because they both want the "current"
history event, which in some sense hasn't happened yet.
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.nbn.com/people/lantern
New male in /home/schaefer:
>N 2 Justin William Schaefer Sat May 11 03:43 53/4040 "Happy Birthday"
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: History !# substitutions 1996-05-29 5:33 History !# substitutions Bart Schaefer @ 1996-05-29 8:19 ` Peter Stephenson 1996-05-29 15:20 ` Peter Stephenson 0 siblings, 1 reply; 8+ messages in thread From: Peter Stephenson @ 1996-05-29 8:19 UTC (permalink / raw) To: zsh-workers > The !# substitution, which shuffles words from the current command line, > has always been a bit flaky in zsh, but now it seems to be broken entirely. > > zagzig% echo foo bar !#:1 > zsh: no words available from current command Profuse apologies: this no doubt came in why I upgraded the word-selection part of the history mechanism and didn't know enough about !# to make it work. The following seems to do the trick; do let me know of unforeseen behaviour. (I've deleted that particular error message since `no such word in event' seems to describe the remaining occasions when there is an error entirely adequately.) I hope flakiness can now be avoided entirely. *** Src/hist.c.curhist Fri May 10 22:22:30 1996 --- Src/hist.c Wed May 29 10:12:15 1996 *************** *** 1111,1131 **** getargs(Histent elist, int arg1, int arg2) { char *ret; ! int pos1; ! if (arg1 >= elist->nwords || arg2 >= elist->nwords) { /* remember, argN is indexed from 0, nwords is total no. of words */ inerrflush(); ! if (!elist->nwords) ! zerr("no words available from current command", NULL, 0); ! else ! zerr("no such word in event", NULL, 0); return NULL; } ! pos1 = elist->words[2*arg1]; ret = dupstring(elist->text + pos1); ! ret[elist->words[2*arg2+1] - pos1] = '\0'; return ret; } --- 1111,1137 ---- getargs(Histent elist, int arg1, int arg2) { char *ret; ! short *words; ! int pos1, nwords; ! if (elist == curhistent) { ! words = chwords; ! nwords = chwordpos/2; ! } else { ! words = elist->words; ! nwords = elist->nwords; ! } ! ! if (arg1 >= nwords || arg2 >= nwords) { /* remember, argN is indexed from 0, nwords is total no. of words */ inerrflush(); ! zerr("no such word in event", NULL, 0); return NULL; } ! pos1 = words[2*arg1]; ret = dupstring(elist->text + pos1); ! ret[words[2*arg2+1] - pos1] = '\0'; return ret; } -- Peter Stephenson <pws@ifh.de> Tel: +49 33762 77366 WWW: http://www.ifh.de/~pws/ Fax: +49 33762 77330 Deutches Electronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen DESY-IfH, 15735 Zeuthen, Germany. ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: History !# substitutions 1996-05-29 8:19 ` Peter Stephenson @ 1996-05-29 15:20 ` Peter Stephenson 1996-05-30 4:40 ` Bart Schaefer 0 siblings, 1 reply; 8+ messages in thread From: Peter Stephenson @ 1996-05-29 15:20 UTC (permalink / raw) To: zsh-workers pws@ifh.de wrote: > I hope flakiness can now be avoided entirely. Did I really say that? This additional patch fixes up things like % print !#:$:s/i/o/o pronto which even after the last patch was choking because the number of words available was not being counted properly, so it couldn't count back from the end of the line. At this point, the end of the line is the last word to be slurped, which may or may not be obvious. I think this is useful, since you quite often need to do things to the previous word on the line. It's not consistent with lines other than the current one, but if it does anything, it has to be this. I added to the manual entry in case it's not clear. (If the manual entry is wrong it's a bug.) *** Src/hist.c.nwords Wed May 29 10:12:15 1996 --- Src/hist.c Wed May 29 16:58:24 1996 *************** *** 181,186 **** --- 181,198 ---- return 0; } + /* Get the maximum no. of words for a history entry. */ + + /**/ + int + getargc(Histent ehist) + { + if (ehist == curhistent) + return chwordpos ? chwordpos/2-1 : 0; + else + return ehist->nwords-1; + } + /* Perform history substitution, returning the next character afterwards. */ /**/ *************** *** 199,205 **** isfirstch = 0; inungetc(hatchar); if (!(ehist = gethist(defev)) ! || !(sline = getargs(ehist, 0, ehist->nwords-1)) || getsubsargs(sline) || !hsubl) return -1; subst(&sline, hsubl, hsubr, 0); --- 211,217 ---- isfirstch = 0; inungetc(hatchar); if (!(ehist = gethist(defev)) ! || !(sline = getargs(ehist, 0, getargc(ehist))) || getsubsargs(sline) || !hsubl) return -1; subst(&sline, hsubl, hsubr, 0); *************** *** 318,331 **** /* extract the relevant arguments */ ! argc = ehist->nwords - 1; if (c == ':') { cflag = 1; c = ingetc(); if (c == '%' && marg != -1) { if (!evset) { ehist = gethist(defev = mev); ! argc = ehist->nwords-1; } else { zerr("Ambiguous history reference", NULL, 0); while (c != '\n' && !lexstop) --- 330,343 ---- /* extract the relevant arguments */ ! argc = getargc(ehist); if (c == ':') { cflag = 1; c = ingetc(); if (c == '%' && marg != -1) { if (!evset) { ehist = gethist(defev = mev); ! argc = getargc(ehist); } else { zerr("Ambiguous history reference", NULL, 0); while (c != '\n' && !lexstop) *** Doc/zshexpn.man.nwords Wed May 29 17:14:23 1996 --- Doc/zshexpn.man Wed May 29 17:16:09 1996 *************** *** 804,810 **** .IR str . .TP .B !# ! Refer to the current command line typed in so far. .TP .BR !{ .\|.\|. } Insulate a history reference from adjacent characters (if necessary). --- 804,812 ---- .IR str . .TP .B !# ! Refer to the current command line typed in so far. The line is ! treated as if it were complete up to and including the word before the ! one with the !# reference. .TP .BR !{ .\|.\|. } Insulate a history reference from adjacent characters (if necessary). -- Peter Stephenson <pws@ifh.de> Tel: +49 33762 77366 WWW: http://www.ifh.de/~pws/ Fax: +49 33762 77330 Deutches Electronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen DESY-IfH, 15735 Zeuthen, Germany. ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: History !# substitutions 1996-05-29 15:20 ` Peter Stephenson @ 1996-05-30 4:40 ` Bart Schaefer 1996-05-30 8:33 ` Peter Stephenson 0 siblings, 1 reply; 8+ messages in thread From: Bart Schaefer @ 1996-05-30 4:40 UTC (permalink / raw) To: Peter Stephenson, zsh-workers On May 29, 10:19am, Peter Stephenson wrote: } Subject: Re: History !# substitutions } } > The !# substitution, which shuffles words from the current command line, } > has always been a bit flaky in zsh, but now it seems to be broken entirely. On May 29, 5:20pm, Peter Stephenson wrote: } Subject: Re: History !# substitutions } } pws@ifh.de wrote: } > I hope flakiness can now be avoided entirely. } } Did I really say that? You did, but thank you anyway. This is the least flaky I can ever recall it being. The only thing that still doesn't work is completion of a reference into the current command, and even that now works a lot better than it used to. Here's zsh 2.4.300: zipx1[22] echo foo bar !#:1 ba<TAB> zsh: no such word in event zipx1[22] echo foo bar ^ cursor here Here's beta19 with your two patches: zigzag% echo foo bar !#:1 ba<TAB> [BEEP][cursor doesn't move] Much better, but still not perfect. I realize it probably can't expand to the correct word, but could it at least ignore the history error and continue completing stuff on the rest of the line? -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.nbn.com/people/lantern New male in /home/schaefer: >N 2 Justin William Schaefer Sat May 11 03:43 53/4040 "Happy Birthday" ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: History !# substitutions 1996-05-30 4:40 ` Bart Schaefer @ 1996-05-30 8:33 ` Peter Stephenson 1996-05-30 14:58 ` Bart Schaefer 1996-05-30 15:11 ` Zefram 0 siblings, 2 replies; 8+ messages in thread From: Peter Stephenson @ 1996-05-30 8:33 UTC (permalink / raw) To: Zsh hackers list schaefer@candle.brasslantern.com wrote: > zigzag% echo foo bar !#:1 ba<TAB> > [BEEP][cursor doesn't move] > > Much better, but still not perfect. I realize it probably can't expand > to the correct word, but could it at least ignore the history error and > continue completing stuff on the rest of the line? I think a judicious `stophist = 1' in get_comp_string() should fix this. At this point, any valid history expansion has been done, and the lexrestore() will fix up the real history, so this should be pretty harmless otherwise. I changed the code, then found there was a bug in menu completion: hitting tab repeatedly added an extra space each time. Then I tried it with the old version and discovered it was there anyway. Has this been reported and fixed while I was asleep? % setopt menucomplete % print zle<TAB><TAB><TAB><TAB><TAB><Ctrl-e> produces % print zle_misc.c _ ^ cursor here. This is something to do with the code in do_single() around line 3343 of zle_tricky.c where something called singlec is used to determine whether a space or slash should be added. I don't know enough about what this does to fix it. Here's the (probably correct, as far as patches to zle_tricky.c go :-/) patch for ignoring previous history entries when completing. *** Src/zle_tricky.c.hstop Thu May 30 10:18:25 1996 --- Src/zle_tricky.c Thu May 30 10:19:43 1996 *************** *** 936,941 **** --- 936,942 ---- lexsave(); inpush(dupstrspace((char *) linptr), 0); strinbeg(); + stophist = 1; pushheap(); heapalloc(); i = tt0 = cp = rd = 0; -- Peter Stephenson <pws@ifh.de> Tel: +49 33762 77366 WWW: http://www.ifh.de/~pws/ Fax: +49 33762 77330 Deutches Electronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen DESY-IfH, 15735 Zeuthen, Germany. ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: History !# substitutions 1996-05-30 8:33 ` Peter Stephenson @ 1996-05-30 14:58 ` Bart Schaefer 1996-05-30 15:11 ` Zefram 1 sibling, 0 replies; 8+ messages in thread From: Bart Schaefer @ 1996-05-30 14:58 UTC (permalink / raw) To: Peter Stephenson, Zsh hackers list On May 30, 10:33am, Peter Stephenson wrote: } Subject: Re: History !# substitutions } } schaefer@candle.brasslantern.com wrote: } > zigzag% echo foo bar !#:1 ba<TAB> } > [BEEP][cursor doesn't move] } > } > Much better, but still not perfect. I realize it probably can't expand } > to the correct word, but could it at least ignore the history error and } > continue completing stuff on the rest of the line? } } I think a judicious `stophist = 1' in get_comp_string() should fix this. Works like a champ! Thanks again! } I changed the code, then found there was a bug in menu completion: } hitting tab repeatedly added an extra space each time. Then I tried } it with the old version and discovered it was there anyway. Has this } been reported and fixed while I was asleep? It's worse than that; look: zagzig% echo foo co bar<C-b><C-b><C-b><C-b><TAB><TAB><TAB><TAB> zagzig% echo foo config bar zagzig% echo foo config.cache barr zagzig% echo foo config.guess barrr zagzig% echo foo config.h barrrr Seems to be an off-by-one error in the length of the string, not just a space or slash being appended. -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.nbn.com/people/lantern New male in /home/schaefer: >N 2 Justin William Schaefer Sat May 11 03:43 53/4040 "Happy Birthday" ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: History !# substitutions 1996-05-30 8:33 ` Peter Stephenson 1996-05-30 14:58 ` Bart Schaefer @ 1996-05-30 15:11 ` Zefram 1996-05-30 16:11 ` Barton E. Schaefer 1 sibling, 1 reply; 8+ messages in thread From: Zefram @ 1996-05-30 15:11 UTC (permalink / raw) To: Peter Stephenson; +Cc: zsh-workers >I changed the code, then found there was a bug in menu completion: >hitting tab repeatedly added an extra space each time. Then I tried >it with the old version and discovered it was there anyway. Has this >been reported and fixed while I was asleep? Yes. It's a result of the line no longer being NUL terminated when editing normally -- when the completion code (which *does* have a NUL at the end of the line) calls a normal editing function, the NUL doesn't get moved appropriately. I sent a patch for it a few days ago. -zefram ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: History !# substitutions 1996-05-30 15:11 ` Zefram @ 1996-05-30 16:11 ` Barton E. Schaefer 0 siblings, 0 replies; 8+ messages in thread From: Barton E. Schaefer @ 1996-05-30 16:11 UTC (permalink / raw) To: Zefram, Peter Stephenson, zsh-workers On May 30, 4:11pm, Zefram wrote: } Subject: Re: History !# substitutions } } >I changed the code, then found there was a bug in menu completion: } >hitting tab repeatedly added an extra space each time. Then I tried } >it with the old version and discovered it was there anyway. Has this } >been reported and fixed while I was asleep? } } Yes. It's a result of the line no longer being NUL terminated when } editing normally -- when the completion code (which *does* have a NUL } at the end of the line) calls a normal editing function, the NUL } doesn't get moved appropriately. I sent a patch for it a few days } ago. Sorry, Zefram, but I have that patch applied and I'm still seeing the behavior I reported (duplication of the last character on the line ever time TAB is pressed somewhere in the middle of the line). -- Bart Schaefer Vice President, Technology, Z-Code Software schaefer@z-code.com Division of NCD Software Corporation http://www.well.com/www/barts http://www.ncdsoft.com/ZMail/ ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~1996-05-30 16:27 UTC | newest] Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 1996-05-29 5:33 History !# substitutions Bart Schaefer 1996-05-29 8:19 ` Peter Stephenson 1996-05-29 15:20 ` Peter Stephenson 1996-05-30 4:40 ` Bart Schaefer 1996-05-30 8:33 ` Peter Stephenson 1996-05-30 14:58 ` Bart Schaefer 1996-05-30 15:11 ` Zefram 1996-05-30 16:11 ` Barton E. Schaefer
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).