zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@sunsite.dk
Subject: Re: alias vl="vi !$"
Date: Sun, 14 Mar 2004 18:01:01 +0000	[thread overview]
Message-ID: <1040314180102.ZM6712@candle.brasslantern.com> (raw)
In-Reply-To: <20040314162702.503178543@pwstephenson.fsnet.co.uk>

[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   


           reply	other threads:[~2004-03-14 18:01 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <20040314162702.503178543@pwstephenson.fsnet.co.uk>]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1040314180102.ZM6712@candle.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).