zsh-workers
 help / color / mirror / code / Atom feed
* fc fix
@ 1997-09-25 16:42 Peter Stephenson
  0 siblings, 0 replies; only message in thread
From: Peter Stephenson @ 1997-09-25 16:42 UTC (permalink / raw)
  To: Zsh hackers list

This fixes another long-standing bug, that the fc builtin, often in
the guise of the r command, can't be used in command substitution.
With foo=$(r), you get nothing in $foo; the previous command is simply
listed to stderr.  It is never even re-executed.  The problem is that
fc puts the commands it has dug up straight into the main input loop,
which doesn't get invoked again until the top-level interactive loop
re-executes.

I've taken the path of least resistance, simply invoking the main loop
to execute the command, which involved modifying it so that it will
input just one line (ranges of history lines are still OK, since they
are pushed onto the input stack in one go).  I don't think there's
much point in anything more subtle, since the point of fc is exactly
that it's bound up with the history mechanism just as reading a line
interactively is.

It's still different from ksh in one respect, that the r executed in a
subshell doesn't go into the history list.  This is just the usual
difference:  ksh keeps its entries in a file, while zsh stores it
internally so it doesn't reappear in the parent shell.

*** Src/builtin.c.fc	Thu Jul  3 10:36:11 1997
--- Src/builtin.c	Thu Sep 25 17:20:31 1997
***************
*** 1035,1042 ****
  		if (fcedit(editor, fil))
  		    if (stuff(fil))
  			zwarnnam("fc", "%e: %s", s, errno);
! 		    else
  			retval = lastval;
  	    }
  	}
  	unlink(fil);
--- 1035,1047 ----
  		if (fcedit(editor, fil))
  		    if (stuff(fil))
  			zwarnnam("fc", "%e: %s", s, errno);
! 		    else {
! 			if (delayrem)
! 			    remhist();
! 			delayrem = 0;
! 			loop(0,1);
  			retval = lastval;
+ 		    }
  	    }
  	}
  	unlink(fil);
*** Src/init.c.fc	Thu Sep 25 17:18:23 1997
--- Src/init.c	Thu Sep 25 17:19:58 1997
***************
*** 42,48 ****
  
  /**/
  void
! loop(int toplevel)
  {
      List list;
  #ifdef DEBUG
--- 42,48 ----
  
  /**/
  void
! loop(int toplevel, int justonce)
  {
      List list;
  #ifdef DEBUG
***************
*** 63,69 ****
  	lexinit();              /* initialize lexical state */
  	if (!(list = parse_event())) {	/* if we couldn't parse a list */
  	    hend();
! 	    if (tok == ENDINPUT && !errflag)
  		break;
  	    continue;
  	}
--- 63,69 ----
  	lexinit();              /* initialize lexical state */
  	if (!(list = parse_event())) {	/* if we couldn't parse a list */
  	    hend();
! 	    if ((tok == ENDINPUT && !errflag) || justonce)
  		break;
  	    continue;
  	}
***************
*** 95,100 ****
--- 95,102 ----
  		dotrap(SIGEXIT);
  	    exit(lastval);
  	}
+ 	if (justonce)
+ 	    break;
      }
      popheap();
  }
***************
*** 722,728 ****
      scriptname = s;
  
      sourcelevel++;
!     loop(0);			/* loop through the file to be sourced        */
      sourcelevel--;
      fclose(bshin);
      fdtable[SHIN] = 0;
--- 724,730 ----
      scriptname = s;
  
      sourcelevel++;
!     loop(0, 0);			/* loop through the file to be sourced        */
      sourcelevel--;
      fclose(bshin);
      fdtable[SHIN] = 0;
*** Src/main.c.fc	Thu Sep 25 17:18:28 1997
--- Src/main.c	Thu Sep 25 17:20:09 1997
***************
*** 78,84 ****
  
      for (;;) {
  	do
! 	    loop(1);
  	while (tok != ENDINPUT);
  	if (!(isset(IGNOREEOF) && interact)) {
  #if 0
--- 78,84 ----
  
      for (;;) {
  	do
! 	    loop(1,0);
  	while (tok != ENDINPUT);
  	if (!(isset(IGNOREEOF) && interact)) {
  #if 0

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1997-09-25 16:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-09-25 16:42 fc fix Peter Stephenson

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