zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: Zsh User <zsh-users@sunsite.dk>
Subject: Re: dynamic reset of completion widget
Date: Thu, 04 Nov 2004 13:09:41 +0000	[thread overview]
Message-ID: <11332.1099573781@csr.com> (raw)
In-Reply-To: <20041104124224.GA9979@let.rug.nl>

Francisco Borges wrote:
> 2. Have a default widget for my python script, say _optparse, that makes
> a new custom widget and rebinds the completion of foo.py to _foo.py

This sounds quite a reasonable way of doing it.

You might want to make it a bit more flexible about possible
enchancements by providing a few extra support functions in parallel to
_optparse (just put #autoload at the top of each function) and then make
_foo.py use those.  It gives you a little bit more decoupling between
the versions of zsh and the versions of the python script.  It depends
how complicated _foo.py is going to be; if you're simply going to call
_arguments, for example, maybe there's no point.  However, having your
own _optparse_arguments as a front-end whose initial implementation is
simply

_optparse_arguments() { _arguments "$@"; }

allows you a bit of future-proofing.

> # I start with
> compdef _optparse foo.py 
> compdef _optparse bozo.py
> [etc]
> 
> # I'm not a zsh programmer, so please have patience here...
> _optparse(){
> 
> # discover the name of the command we are completing
> set bar=`give the command name I'm completing`

$service ought to give you this immediately.  In general it's
a completion context, but if you know you're complete for
command arguments, as you will here, it's the name of the command
you're completing for.

> eval "`$bar --make-zsh-widget`"
> # which would return something like:
> # "_foo.py() { compadd Scooby Dooby Doo; }"
> 
> compdef _$bar $bar
> }
> 
> Is this possible? Can I just rebind like this?

Yes, you can, however the newly defined function won't get called the
first time.  So you should add

_$bar "$@"

to the end of _optparse.

Before that you might want to check that the specific completion
function has actually been defined for safety, e.g.

if [[ -z $functions[_$bar] ]]; the
  _message "$bar --make-zsh-widget didn't define _$bar"
  return 1
fi

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************


  reply	other threads:[~2004-11-04 13:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-04 12:42 Francisco Borges
2004-11-04 13:09 ` Peter Stephenson [this message]
2004-11-04 20:54   ` Francisco Borges
2004-11-05 12:11     ` Peter Stephenson
2004-11-04 18:39 ` Bart Schaefer

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=11332.1099573781@csr.com \
    --to=pws@csr.com \
    --cc=zsh-users@sunsite.dk \
    /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).