From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6007 invoked from network); 4 Nov 2004 13:10:51 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 4 Nov 2004 13:10:51 -0000 Received: (qmail 22579 invoked from network); 4 Nov 2004 13:10:43 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 4 Nov 2004 13:10:43 -0000 Received: (qmail 21780 invoked by alias); 4 Nov 2004 13:09:49 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 8169 Received: (qmail 21765 invoked from network); 4 Nov 2004 13:09:48 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 4 Nov 2004 13:09:48 -0000 Received: (qmail 21445 invoked from network); 4 Nov 2004 13:09:48 -0000 Received: from host81-105-217-43.not-set-yet.ntli.net (HELO MAILSWEEPER01.csr.com) (81.105.217.43) by a.mx.sunsite.dk with SMTP; 4 Nov 2004 13:09:47 -0000 Received: from exchange03.csr.com (unverified [10.100.137.60]) by MAILSWEEPER01.csr.com (Content Technologies SMTPRS 4.3.12) with ESMTP id for ; Thu, 4 Nov 2004 13:08:35 +0000 Received: from csr.com ([10.102.144.127]) by exchange03.csr.com with Microsoft SMTPSVC(5.0.2195.6713); Thu, 4 Nov 2004 13:13:08 +0000 To: Zsh User Subject: Re: dynamic reset of completion widget In-reply-to: <20041104124224.GA9979@let.rug.nl> References: <20041104124224.GA9979@let.rug.nl> Date: Thu, 04 Nov 2004 13:09:41 +0000 Message-ID: <11332.1099573781@csr.com> From: Peter Stephenson X-OriginalArrivalTime: 04 Nov 2004 13:13:08.0016 (UTC) FILETIME=[06D7FB00:01C4C270] X-Spam-Checker-Version: SpamAssassin 2.63 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, hits=0.0 required=6.0 tests=none autolearn=no version=2.63 X-Spam-Hits: 0.0 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 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 **********************************************************************