zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@ifh.de>
To: zsh-workers@math.gatech.edu (Zsh hackers list)
Subject: Re: Tag functions with shell options?
Date: Tue, 02 Jul 1996 17:37:58 +0200	[thread overview]
Message-ID: <199607021537.RAA16181@hydra.ifh.de> (raw)
In-Reply-To: "aheading@jpmorgan.com"'s message of "Tue, 02 Jul 1996 13:05:29 MET." <199607021205.NAA18450@gmp-etpres1.uk.jpmorgan.com>

aheading@jpmorgan.com wrote:
> So I think I need some way of marking these functions to be interpreted with
> SH_WORD_SPLIT turned on locally.  Or have I missed something simple?

This is definitely a weak point in compatibility.  Perhaps in a future
version we do want special ways of doing things like this.  Some time
ago, people were suggesting having hooks you could call when a
function was called etc.; that would do the trick too.

However, for the time being... I take it the problem is within the
function, i.e. you don't actually have problems on the command line
yourself?  In that case it would be outside the scope of the function.

Another problem arises if the functions get defined at arbitrary
points during execution (err, like the sws_locate function below, in
fact).  In that case you're basically stuck without at the least a
smart script to convert all functions defined inside in the
appropriate manner.

If they are playing fair, however, try this function.  You need
to call it with the names of all the functions you want to have run
with sh_word_split turned on.  They can be either already in memory or
autoloadable: in the latter case, it assumes they are ksh-like
autoloadable functions, i.e. the entire function definition is there
including the `function foo { ... } bit.'

It relies on the fact that `functions foo' returns an accurate
representation of foo.  I've been trying to ensure this over the
years, but there almost certainly some things we've all missed.


sws_fn () {
  # Convert a sh or ksh function to run under zsh by the addition of
  # some set of options.  The function may already be defined, or be in
  # some autoload directory.

  # This is the text we\'d like added at the top of the function.
  local optline="setopt shwordsplit localoptions"

  local func body dir fnfile

  sws_locate() {
    # Find an autoload file.
    local dir
    for dir in $fpath; do
      if [[ -f $dir/$1 ]]; then
	fnfile=$dir/$1
	return 0
      fi
    done
    return 1
  }

  for func; do
    if [[ "$(functions $func | head -1)" = *undefined* ]] &&
      sws_locate $func; then
      # We're assuming these are ksh-like autoload functions,
      # i.e. they contain the full function include definition lines.
      . $fnfile
    fi
    body="$(functions $func 2>&1 | sed -e 1d -e '$d')"
    [[ -z $body ]] && print "No such function: $func" >&2 && continue
    eval "function $func {
      $optline
      $body
    }"
  done
}

-- 
Peter Stephenson <pws@ifh.de>       Tel: +49 33762 77366
WWW:  http://www.ifh.de/~pws/       Fax: +49 33762 77330
Deutches Electronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, 15735 Zeuthen, Germany.



  parent reply	other threads:[~1996-07-02 15:47 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-07-02 12:05 Anthony Heading
1996-07-02 13:36 ` Zefram
1996-07-02 14:12   ` Anthony Heading
1996-07-02 15:17     ` Zefram
1996-07-02 15:37 ` Peter Stephenson [this message]
1996-07-02 16:57   ` Anthony Heading
1996-07-02 19:07     ` Bart Schaefer
1996-07-02 19:53       ` Anthony Heading
1996-07-02 21:31         ` Bart Schaefer
1996-07-02 22:27           ` Anthony Heading

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=199607021537.RAA16181@hydra.ifh.de \
    --to=pws@ifh.de \
    --cc=zsh-workers@math.gatech.edu \
    /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).