zsh-users
 help / color / mirror / code / Atom feed
From: Francisco Borges <borges@let.rug.nl>
To: Zsh User <zsh-users@sunsite.dk>
Subject: dynamic reset of completion widget
Date: Thu, 4 Nov 2004 13:42:24 +0100	[thread overview]
Message-ID: <20041104124224.GA9979@let.rug.nl> (raw)

I hope the subject wasn't that confusing...

I want to automatically create zsh widgets for python programs using
python's standard option parser framework (optparse) and I want also to
be able to make and set this widget on-the-fly.

----------------------------------------------------------------
Here is the full story...

Yesterday I made a small script that, called from inside my foo.py
script, outputs a zsh completion widget to a file _foo.py.

This gives me a fast completion widget but it involves some shell
configuration every time I change options.

[...]

This guy has done a python module (http://furius.ca/optcomplete/) that
will provide bash directly with option completion through bash's
'completion protocol', e.g. setting COMP_(CWORD|LINE|POINT|WORDS) and
COMPREPLY.

So appart from a stable _foo.py file, I think it would also be good to
have a on-the-fly completion widget for zsh, like the one done for
bash. 

Wondering how to do it, I saw two possibilities:

1. Do the same as optcomplete does for bash, e.g. talk to the shell by
setting the correspondent variables;

OR

(don't know if this is possible, but it seems easier) 
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

# 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`

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?

I imagine I'm not taking care of all details yet...

Any ideas, comments or suggestions? All welcome.

Any example of something similar? (I must confess that I find zsh
documentation a bit overwhelming...)

Peace,
Francisco.


             reply	other threads:[~2004-11-04 12:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-04 12:42 Francisco Borges [this message]
2004-11-04 13:09 ` Peter Stephenson
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=20041104124224.GA9979@let.rug.nl \
    --to=borges@let.rug.nl \
    --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).