From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26053 invoked from network); 25 Sep 1997 16:56:28 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 25 Sep 1997 16:56:28 -0000 Received: (from list@localhost) by math.gatech.edu (8.8.5/8.8.5) id MAA21558; Thu, 25 Sep 1997 12:41:53 -0400 (EDT) Resent-Date: Thu, 25 Sep 1997 12:41:53 -0400 (EDT) Message-Id: <199709251642.SAA23768@hydra.ifh.de> To: zsh-workers@math.gatech.edu (Zsh hackers list) Subject: fc fix Date: Thu, 25 Sep 1997 18:42:20 +0200 From: Peter Stephenson Resent-Message-ID: <"Hnztf3.0.nG5.HHfAq"@math> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/3526 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu 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 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.