From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6208 invoked by alias); 3 May 2010 19:26:24 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 27946 Received: (qmail 1038 invoked from network); 3 May 2010 19:26:21 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham version=3.3.1 Received-SPF: pass (ns1.primenet.com.au: SPF record at ntlworld.com designates 81.103.221.31 as permitted sender) Date: Mon, 3 May 2010 19:57:52 +0100 From: Peter Stephenson To: Subject: Re: Added builtins per runtime Message-ID: <20100503195752.7d50fe44@pws-pc> In-Reply-To: <12855ad6dba.6318419370147111815.5595086135333789265@dorfelite.net> References: <12854b73c24.-5662614641985446414.-6364714751911043221@dorfelite.net> <1285584468e.-5976807992945925025.-2686280647114173652@dorfelite.net> <12855ad6dba.6318419370147111815.5595086135333789265@dorfelite.net> X-Mailer: Claws Mail 3.7.5 (GTK+ 2.18.9; 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.1 cv=W3tOLUehizD4qj6VhtReFuw5MKb8d+XqjIxlDsIazEA= c=1 sm=0 a=DogomfpGjd0A:10 a=kj9zAlcOel0A:10 a=1k5uuwECAAAA:8 a=NLZqzBF-AAAA:8 a=3EUVpcj1fVrNt60YM3sA:9 a=c5qtezS5J1_U5UtoWl9C5o30ItwA:4 a=CjuIK1q_8ugA:10 a=W1NnjgLZnwMA:10 a=_dQi-Dcv4p4A:10 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117 On Sat, 01 May 2010 23:02:28 +0200 Christoph Kappel wrote: > That was exactly my question. Can a module change it's features per runtime? I think the interface you want in the C code is probably handlefeatures() or thereabouts. You can get similar effects from shell code with zmodload, for example: # Load the zsh/stat module, enabling (only) the zstat builtin % zmodload -F zsh/stat b:zstat % which zstat zstat: shell built-in command # Disable the zstat builtin % zmodload -F zsh/stat -b:zstat % which zstat zstat not found # Reenable it % zmodload -F zsh/stat +b:zstat % which zstat zstat: shell built-in command This is under user control, i.e. the zstat builtin is always there to be enabled from the command line. If you want to change what builtins or other feature are actually offered, you need to be a bit more careful. I *think* you can get away with doing the C equivalent of disabling a feature, and after that not showing it --- the interface between the main shell and a module doesn't remember the feature list, it queries the module every time, so if you present it a different list of features each time it doesn't care. However, if a builtin is linked into the shell, it will be called whatever zmodload sees, which is why I think you need to ensure you disable the feature before presenting a list with it missing. In other words, to disable a builtin (or parameter, math function, or condition) in a way that doesn't allow the user to reenable it (i) call handlefeatures() with an appropriate array indicating what you want to be enabled. That should probably be an "and" of what is actually enabled together with zeros for the features you no longer want to present (ii) next time there's a call from zmodload into your function, only present the set of features / array of enabled features shortened so that it doesn't include the feature you want to disappear. The only tricky bit is to make quite sure the two arrays are the same length with the appropriate element missing. (The point of the interface the way it is is that the Features array is expected to be invariant while the array of integers will change each time; your case is atypical.) I think that should work, but I have not tried. If it doesn't work, it's probably a bug that should be fixed (though I reserve the right to say, "oh yeah, I never expected it to do *that*" at infuriating points). I don't think you should be doing this at the level below that of generic features, the interface isn't as powerful, so even if you're just interested in builtins, create a list of features with the lists of feature types other than builtins set to NULL and pass that to handlefeatures(). If you'd like more documentation, please be explicit (though not necessarily detailed) about where in the documentation it should go and what it should talk about. The developer's guide is certainly not for the faint of heart (and isn't supposed to be), but is capable of expansion. Good luck. -- Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/