From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1731 invoked from network); 14 Mar 2004 18:01:25 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 14 Mar 2004 18:01:25 -0000 Received: (qmail 28203 invoked by alias); 14 Mar 2004 18:01:09 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 19621 Received: (qmail 28190 invoked from network); 14 Mar 2004 18:01:08 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 14 Mar 2004 18:01:08 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [167.160.213.139] by sunsite.dk (MessageWall 1.0.8) with SMTP; 14 Mar 2004 18:1:8 -0000 Received: from moonbase.zanshin.com (IDENT:schaefer@localhost [127.0.0.1]) by moonbase.zanshin.com (8.12.11/8.12.11) with ESMTP id i2EI165H019188 for ; Sun, 14 Mar 2004 10:01:06 -0800 Received: (from schaefer@localhost) by moonbase.zanshin.com (8.12.11/8.12.11/Submit) id i2EI16wC019187 for zsh-workers@sunsite.dk; Sun, 14 Mar 2004 10:01:06 -0800 Received: (from schaefer@localhost) by candle.brasslantern.com (8.11.6/8.11.6) id i2EI12006713; Sun, 14 Mar 2004 10:01:02 -0800 X-Authentication-Warning: candle.brasslantern.com: schaefer set sender to schaefer@closedmail.com using -f From: Bart Schaefer Message-Id: <1040314180102.ZM6712@candle.brasslantern.com> Date: Sun, 14 Mar 2004 18:01:01 +0000 In-Reply-To: <20040314162702.503178543@pwstephenson.fsnet.co.uk> Comments: In reply to Peter Stephenson "Re: alias vl="vi !$"" (Mar 14, 4:27pm) References: <20040314162702.503178543@pwstephenson.fsnet.co.uk> X-Mailer: Z-Mail (5.0.0 30July97) To: zsh-workers@sunsite.dk Subject: Re: alias vl="vi !$" MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Envelope-Sender: [Redirected to -workers] On Mar 14, 4:27pm, Peter Stephenson wrote: } } Bart Schaefer wrote: } > Inside a function, however, $_ has already been changed to be the last } > word of the _currently executing_ command, the same as as $argv[-1]. } } It's not likely anyone's using the present form in a function; [...] Unfortunately this is not as easily/cleanly changed as I'd hoped. setunderscore() is called fairly early in execcmd() and uses the value from getdata(lastnode(args)) before the "args" list is manipulated by, e.g., the RM_STAR_SILENT and AUTO_CD code, and globlist(). Thereafter, execcmd() does a number of early "return"s, mostly in error states. Those can be changed to "goto"s down to the end of the function (like "goto done" used in at least one spot) but I'm not sure if it's safe to simply save a pointer to getdata(lastnode(args)) or if it'd have to be dupstring()'d. So it comes out something like this: Index: Src/exec.c =================================================================== RCS file: /extra/cvsroot/zsh/zsh-4.0/Src/exec.c,v retrieving revision 1.16 diff -c -r1.16 exec.c --- exec.c 14 Feb 2004 19:39:27 -0000 1.16 +++ exec.c 14 Mar 2004 17:53:44 -0000 @@ -1747,6 +1747,7 @@ wordcode code; Wordcode beg = state->pc, varspc; FILE *oxtrerr = xtrerr; + char *underscore = ""; doneps4 = 0; redir = (wc_code(*state->pc) == WC_REDIR ? ecgetredirs(state) : NULL); @@ -1989,8 +1990,8 @@ text = NULL; /* Set up special parameter $_ */ - - setunderscore((args && nonempty(args)) ? ((char *) getdata(lastnode(args))) : ""); + if (args && nonempty(args)) + underscore = dupstring((char *) getdata(lastnode(args))); /* Warn about "rm *" */ if (type == WC_SIMPLE && interact && unset(RMSTARSILENT) && @@ -2021,8 +2022,7 @@ if (errflag) { lastval = 1; - opts[AUTOCONTINUE] = oautocont; - return; + goto _return; } if (type == WC_SIMPLE && !nullexec) { @@ -2104,8 +2104,7 @@ if ((pid = zfork()) == -1) { close(synch[0]); close(synch[1]); - opts[AUTOCONTINUE] = oautocont; - return; + goto _return; } if (pid) { close(synch[1]); read(synch[0], &dummy, 1); @@ -2130,8 +2129,7 @@ } } addproc(pid, text, 0); - opts[AUTOCONTINUE] = oautocont; - return; + goto _return; } /* pid == 0 */ close(synch[0]); @@ -2500,6 +2498,8 @@ zsfree(STTYval); STTYval = 0; + _return: + setunderscore(underscore); opts[AUTOCONTINUE] = oautocont; } -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net