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

Re: !cmd <TAB> doesn't work in 3.0.3-test3



Vinnie Shelton wrote:
> When I backed out Peter's patch (article 2748), !cmd<TAB> worked again.
> 
> !cmd<TAB> no longer completes is 3.03.0.3-test3.

Yes, I didn't handle multiple histories on top of one another
properly:  curhist got incremented too many times.  I've also improved
readability with some #define's for histactive.  (In my defence, for
some weird reason it worked OK after running my own initialisation
files.)

*** Src/hist.c.hist1	Wed Jan  8 14:58:02 1997
--- Src/hist.c	Thu Jan  9 10:18:41 1997
***************
*** 32,50 ****
  #include "zsh.h"
  
  /*
!  * Note on histactive: bit 0 says the history mechanism is active;
!  * bit 1 says junk the line being processed by the history
!  * when finished with it if (histactive & 1); bit 2 says we have already
!  * junked a line when !(histactive & 1).
!  *
!  * Note on curhist: with !(histactive & 1), this points to the
!  * last line actually added to the history list.  With (histactive & 1),
   * the line does not get added to the list until hend(), if at all.
   * However, curhist is incremented to reflect the current line anyway.
   * Thus if the line is not added to the list, curhist must be
   * decremented in hend().
   */
  
  extern int cs, ll;
  
  /* Array of word beginnings and endings in current history line. */
--- 32,51 ----
  #include "zsh.h"
  
  /*
!  * Note on curhist: with history active, this points to the
!  * last line actually added to the history list.  With history inactive,
   * the line does not get added to the list until hend(), if at all.
   * However, curhist is incremented to reflect the current line anyway.
   * Thus if the line is not added to the list, curhist must be
   * decremented in hend().
   */
  
+ /* Bits of histactive variable */
+ #define HA_ACTIVE	(1<<0)	/* History mechanism is active */
+ #define HA_NOSTORE	(1<<1)	/* Don't store the line when finished */
+ #define HA_JUNKED	(1<<2)	/* Last history line was already junked */
+ #define HA_NOINC	(1<<3)	/* Don't store, curhist not incremented */
+ 
  extern int cs, ll;
  
  /* Array of word beginnings and endings in current history line. */
***************
*** 597,607 ****
      if (interact && isset(SHINSTDIN) && !strin) {
  	attachtty(mypgrp);
  	defev = curhist;
! 	histactive = 1;
      } else
! 	histactive = 3;
! 
!     curhist++;
  }
  
  /* say we're done using the history mechanism */
--- 598,607 ----
      if (interact && isset(SHINSTDIN) && !strin) {
  	attachtty(mypgrp);
  	defev = curhist;
! 	histactive = HA_ACTIVE;
! 	curhist++;
      } else
! 	histactive = HA_NOINC;
  }
  
  /* say we're done using the history mechanism */
***************
*** 614,624 ****
      Histent he;
  
      DPUTS(!chline, "BUG: chline is NULL in hend()");
!     if (histactive & 2) {
  	zfree(chline, hlinesz);
  	zfree(chwords, chwordlen*sizeof(short));
  	chline = NULL;
! 	curhist--;
  	histactive = 0;
  	return 1;
      }
--- 614,625 ----
      Histent he;
  
      DPUTS(!chline, "BUG: chline is NULL in hend()");
!     if (histactive & (HA_NOSTORE|HA_NOINC)) {
  	zfree(chline, hlinesz);
  	zfree(chwords, chwordlen*sizeof(short));
  	chline = NULL;
! 	if (!(histactive & HA_NOINC))
! 	    curhist--;
  	histactive = 0;
  	return 1;
      }
***************
*** 697,713 ****
  void
  remhist(void)
  {
!     if (!(histactive & 1)) {
! 	if (!(histactive & 4)) {
  	    /* make sure this doesn't show up when we do firsthist() */
  	    Histent he = gethistent(curhist);
  	    zsfree(he->text);
  	    he->text = NULL;
! 	    histactive |= 4;
  	    curhist--;
  	}
      } else
! 	histactive |= 2;
  }
  
  /* Gives current expansion word if not last word before chwordpos. */
--- 698,714 ----
  void
  remhist(void)
  {
!     if (!(histactive & HA_ACTIVE)) {
! 	if (!(histactive & HA_JUNKED)) {
  	    /* make sure this doesn't show up when we do firsthist() */
  	    Histent he = gethistent(curhist);
  	    zsfree(he->text);
  	    he->text = NULL;
! 	    histactive |= HA_JUNKED;
  	    curhist--;
  	}
      } else
! 	histactive |= HA_NOSTORE;
  }
  
  /* Gives current expansion word if not last word before chwordpos. */
***************
*** 1074,1080 ****
  
      if (ev < firsthist() || ev > curhist)
  	return NULL;
!     if (ev == curhist && (histactive & 1)) {
  	/* The current history line has not been stored.  Build it up
  	 * from other variables.
  	 */
--- 1075,1081 ----
  
      if (ev < firsthist() || ev > curhist)
  	return NULL;
!     if (ev == curhist && (histactive & HA_ACTIVE)) {
  	/* The current history line has not been stored.  Build it up
  	 * from other variables.
  	 */

-- 
Peter Stephenson <pws@xxxxxx>       Tel: +49 33762 77366
WWW:  http://www.ifh.de/~pws/       Fax: +49 33762 77413
Deutsches Elektronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, 15735 Zeuthen, Germany.



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