zsh-workers
 help / color / mirror / code / Atom feed
* Re: alias vl="vi !$"
       [not found] <20040314162702.503178543@pwstephenson.fsnet.co.uk>
@ 2004-03-14 18:01 ` Bart Schaefer
  0 siblings, 0 replies; only message in thread
From: Bart Schaefer @ 2004-03-14 18:01 UTC (permalink / raw)
  To: zsh-workers

[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   


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

only message in thread, other threads:[~2004-03-14 18:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20040314162702.503178543@pwstephenson.fsnet.co.uk>
2004-03-14 18:01 ` alias vl="vi !$" Bart Schaefer

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