Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

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.
> 
> 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@xxxxxx>       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.




Messages sorted by: Reverse Date, Date, Thread, Author