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

History list fix



This fixes the off-by-one error when trying to list just the last
history entry (you can't, neither with nor without HISTNOSTORE set).

At least, it seems to fix it: it's a bit confusing when you don't have
HISTNOSTORE set but you do have HISTIGNOREDUPS set, since if the
previous command is the same as the current history command you don't
see it.  However, I suppose that's logical: with my recent
HISTIGNOREDUPS command it's really always the last command which is in
the history list, which is still the current comand, and `history'
never shows the current command.  (People repeating identical history
commands only tend to be testing the history code anyway.)

This error by tradition reappears whenever anybody makes any change to
the fc code.  I've tried to reduce the likelihood of a recrudescence
by removing the two confusing possibilities, i.e. either the current
history entry is already deleted or is about to be.  With this patch
curhist is always still the fc/history command itself.  Otherwise,
there are unpleasant dependencies on HISTNOSTORE.

By the way, there's another fix of mine for a traditional bug, namely
the bogus `permission denied' error when trying to execute a
non-existent programme with an unreadable directory somewhere in the
path, which seems to have gone missing.

*** Src/builtin.c.fc	Mon Aug  5 14:38:39 1996
--- Src/builtin.c	Tue Aug 13 17:53:59 1996
***************
*** 2433,2444 ****
      }
      delayrem = 0;
      if (!(ops['l'] && unset(HISTNOSTORE)) &&
! 	!(ops['R'] || ops['W'] || ops['A'])) {
! 	if (ops['l'])
! 	    remhist();
! 	else
! 	    delayrem = 1;
!     }
      if (ops['R']) {
  	/* read history from a file */
  	readhistfile(*argv ? *argv : getsparam("HISTFILE"), 1);
--- 2433,2440 ----
      }
      delayrem = 0;
      if (!(ops['l'] && unset(HISTNOSTORE)) &&
! 	!(ops['R'] || ops['W'] || ops['A']))
! 	delayrem = 1;
      if (ops['R']) {
  	/* read history from a file */
  	readhistfile(*argv ? *argv : getsparam("HISTFILE"), 1);
***************
*** 2474,2488 ****
      if (*argv) {
  	minflag = **argv == '-';
  	first = fcgetcomm(*argv);
! 	if (first == -1)
  	    return 1;
  	argv++;
      }
      /* interpret and check second history line specifier */
      if (*argv) {
  	last = fcgetcomm(*argv);
! 	if (last == -1)
  	    return 1;
  	argv++;
      }
      /* There is a maximum of two history specifiers.  At least, there *
--- 2470,2490 ----
      if (*argv) {
  	minflag = **argv == '-';
  	first = fcgetcomm(*argv);
! 	if (first == -1) {
! 	    if (delayrem)
! 		remhist();
  	    return 1;
+ 	}
  	argv++;
      }
      /* interpret and check second history line specifier */
      if (*argv) {
  	last = fcgetcomm(*argv);
! 	if (last == -1) {
! 	    if (delayrem)
! 		remhist();
  	    return 1;
+ 	}
  	argv++;
      }
      /* There is a maximum of two history specifiers.  At least, there *
***************
*** 2489,2494 ****
--- 2491,2498 ----
       * will be as long as the history list is one-dimensional.        */
      if (*argv) {
  	zwarnnam("fc", "too many arguments", NULL, 0);
+ 	if (delayrem)
+ 	    remhist();
  	return 1;
      }
      /* default values of first and last, and range checking */
***************
*** 2495,2501 ****
      if (first == -1)
  	first = (ops['l']) ? curhist - 16 : curhist - 1;
      if (last == -1)
! 	last = (ops['l']) ? curhist : first;
      if (first < firsthist())
  	first = firsthist();
      if (last == -1)
--- 2499,2505 ----
      if (first == -1)
  	first = (ops['l']) ? curhist - 16 : curhist - 1;
      if (last == -1)
! 	last = (ops['l']) ? curhist - 1 : first;
      if (first < firsthist())
  	first = firsthist();
      if (last == -1)

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