From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28164 invoked from network); 11 Feb 2009 20:29:13 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.5 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 11 Feb 2009 20:29:13 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 92085 invoked from network); 11 Feb 2009 20:29:08 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 11 Feb 2009 20:29:08 -0000 Received: (qmail 1963 invoked by alias); 11 Feb 2009 20:29:03 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 26556 Received: (qmail 1946 invoked from network); 11 Feb 2009 20:29:02 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 11 Feb 2009 20:29:02 -0000 Received: from mtaout01-winn.ispmail.ntl.com (mtaout01-winn.ispmail.ntl.com [81.103.221.47]) by bifrost.dotsrc.org (Postfix) with ESMTP id 12FC380271F0 for ; Wed, 11 Feb 2009 21:28:58 +0100 (CET) Received: from aamtaout01-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout01-winn.ispmail.ntl.com (InterMail vM.7.08.04.00 201-2186-134-20080326) with ESMTP id <20090211202854.DNVT2989.mtaout01-winn.ispmail.ntl.com@aamtaout01-winn.ispmail.ntl.com> for ; Wed, 11 Feb 2009 20:28:54 +0000 Received: from pws-pc ([81.107.42.185]) by aamtaout01-winn.ispmail.ntl.com (InterMail vG.2.02.00.01 201-2161-120-102-20060912) with ESMTP id <20090211202854.JGZM19264.aamtaout01-winn.ispmail.ntl.com@pws-pc> for ; Wed, 11 Feb 2009 20:28:54 +0000 Date: Wed, 11 Feb 2009 20:28:40 +0000 From: Peter Stephenson To: zsh-workers@sunsite.dk (Zsh hackers list) Subject: Re: PATCH: sticky emulation Message-ID: <20090211202840.000b37aa@pws-pc> In-Reply-To: <090210191804.ZM7110@torch.brasslantern.com> References: <18952.1234307021@pws-pc> <090210191804.ZM7110@torch.brasslantern.com> X-Mailer: Claws Mail 3.7.0 (GTK+ 2.14.7; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Cloudmark-Analysis: v=1.0 c=1 a=q2GGsy2AAAAA:8 a=NLZqzBF-AAAA:8 a=2Ou9Dq8DKg8Yc8J4LfcA:9 a=ruznXYoTnWgT9WePTlMA:7 a=MzkGe_kn6SCnCM38514BerRGXQgA:4 a=LY0hPdMaydYA:10 a=I6wTmPyJxzYA:10 a=_dQi-Dcv4p4A:10 X-Virus-Scanned: ClamAV 0.92.1/8980/Wed Feb 11 17:40:45 2009 on bifrost X-Virus-Status: Clean On Tue, 10 Feb 2009 19:18:04 -0800 Bart Schaefer wrote: > On Feb 10, 11:03pm, Peter Stephenson wrote: > } Subject: PATCH: sticky emulation > } > } This is how I envision (and have already described, at least briefly) > } sticky emulation for functions working. > > This all seems quite reasonable to me, particularly because the > implementation appears to be a straightforward change to the code -- > tends to imply that it fits naturally into the existing semantics. > > Nit-pick: The patch to Src/hashtable.c is a no-op. Yes, that's been lying around for ages waiting for an excuse to commit it. > } Note that sticky emulation is not propagated to autoloaded functions, > } neither when the autoload is set up nor when they are loaded > > What about zcompiled functions? Obviously there's no special case for > them, but their treatment may be worth explanation at doc time. I've done that. Here's the documentation. I'll submit the lot and it can be modified later if necessary. Index: Doc/Zsh/builtins.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/builtins.yo,v retrieving revision 1.118 diff -u -r1.118 builtins.yo --- Doc/Zsh/builtins.yo 8 Feb 2009 08:09:19 -0000 1.118 +++ Doc/Zsh/builtins.yo 11 Feb 2009 20:28:11 -0000 @@ -356,10 +356,6 @@ )\ . -If tt(-c) tt(arg) is given, evaluate tt(arg) after temporary setting -requested emulation. Emulation and all options will be restored to their -original values before tt(emulate) returns. - If the tt(-R) option is given, all options are reset to their default value corresponding to the specified emulation mode, except for certain options describing the interactive @@ -370,6 +366,62 @@ tt(trap) commands to be local to the immediately surrounding shell function, if any; normally these options are turned off in all emulation modes except tt(ksh). The tt(-L) and tt(-c) are mutually exclusive. + +If tt(-c) tt(arg) is given, evaluate tt(arg) while the requested +emulation is temporarily in effect. The emulation and all options will +be restored to their original values before tt(emulate) returns. The +tt(-R) flag may be used. + +Use of tt(-c) enables `sticky' emulation mode for functions defined +within the evaluated expression: the emulation mode is associated +thereafter with the function so that whenever the function is executed +the emulation (respecting the tt(-R) flag, if present) and all +options are set before entry to the function, and restored after exit. +If the function is called when the sticky emulation is already in +effect, either within an `tt(emulate) var(shell) tt(-c)' expression or +within another function with the same sticky emulation, entry and exit +from the function do not cause options to be altered (except due to +standard processing such as the tt(LOCAL_OPTIONS) option). + +For example: + +example(emulate sh -c 'fni+LPAR()RPAR() { setopt cshnullglob; } +fno+LPAR()RPAR() { fni; }' +fno +) + +The two functions tt(fni) and tt(fno) are defined with sticky tt(sh) +emulation. tt(fno) is then executed, causing options associated +with emulations to be set to their values in tt(sh). tt(fni) then +calls tt(fno); because tt(fno) is also marked for sticky tt(sh) +emulation, no option changes take place on entry to or exit from it. +Hence the option tt(cshnullglob), turned off by tt(sh) emulation, will +be turned on within tt(fni) and remain on on return to tt(fno). On exit +from tt(fno), the emulation mode and all options will be restored to the +state they were in before entry to the temporary emulation. + +The documentation above is typically sufficient for the intended +purpose of executing code designed for other shells in a suitable +environment. More detailed rules follow. +startsitem() +sitem(1.)(The sticky emulation environment provided by `tt(emulate) +var(shell) tt(-c)' is identical to that provided by entry to +a function marked for sticky emulation as a consequence of being +defined in such an environment. Hence, for example, the sticky +emulation is inherited by subfunctions defined within functions +with sticky emulation.) +sitem(2.)(No change of options takes place on entry to or exit from +functions that are not marked for sticky emulation, other than those +that would normally take place, even if those functions are called +within sticky emulation.) +sitem(3.)(No special handling is provided for functions marked for +tt(autoload) nor for functions present in wordcode created by +the tt(zcompile) command.) +sitem(4.)(The presence or absence of the tt(-R) flag to tt(emulate) +corresponds to different sticky emulation modes, so for example +`tt(emulate sh -c)', `tt(emulate -R sh -c)' and `tt(emulate csh -c)' +are treated as three distinct sticky emulations.) +endsitem() ) findex(enable) cindex(enabling commands) -- Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/