zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: <zsh-workers@zsh.org>
Subject: Re: Added builtins per runtime
Date: Mon, 3 May 2010 19:57:52 +0100	[thread overview]
Message-ID: <20100503195752.7d50fe44@pws-pc> (raw)
In-Reply-To: <12855ad6dba.6318419370147111815.5595086135333789265@dorfelite.net>

On Sat, 01 May 2010 23:02:28 +0200
Christoph Kappel <unexist@dorfelite.net> 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 <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


      parent reply	other threads:[~2010-05-03 19:26 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-01 16:33 Christoph Kappel
2010-05-01 19:58 ` Bart Schaefer
2010-05-01 20:17   ` Christoph Kappel
2010-05-01 20:49     ` Bart Schaefer
2010-05-01 21:02       ` Christoph Kappel
2010-05-02  9:08         ` Bart Schaefer
2010-05-02 17:28           ` Christoph Kappel
2010-05-03 18:57         ` Peter Stephenson [this message]

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=20100503195752.7d50fe44@pws-pc \
    --to=p.w.stephenson@ntlworld.com \
    --cc=zsh-workers@zsh.org \
    /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).