From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15083 invoked by alias); 28 Aug 2012 13:00:02 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 17213 Received: (qmail 13553 invoked from network); 28 Aug 2012 13:00:00 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at csr.com does not designate permitted sender hosts) Date: Tue, 28 Aug 2012 13:57:49 +0100 From: Peter Stephenson To: Subject: Re: How to change description for _user_expand completions? Message-ID: <20120828135749.3751941d@pwslap01u.europe.root.pri> In-Reply-To: References: Organization: Cambridge Silicon Radio X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.101.10.18] X-Scanned-By: MailControl 8316.0 (www.mailcontrol.com) on 10.71.0.138 On Sun, 26 Aug 2012 11:28:31 -0700 Pax Unix wrote: > My current problem: I've got a function called by _user_expand so I can > generate context-independent completions based on a particular prefix. > > It works perfectly well, but the only description that ever appears is > either "all expansions" or "expansions" (or "original"). I want to > specify the description string from within my expander function, > tailored to the results I'm returning, rather than have to accept the > default. I don't think that's currently handled. All _user_expand does with your function is run it to assemble a list of possible completions from an array. This is then passed into the completion system by _user_expand, so anything else your function does is ignored (unless it's directly adding completions itself, which would make _user_expand a bit pointless). We could come up with a convention for this. It looks to me like _user_expand only ever picks the first non-zero set of expansions (when it's found some expansions it assigns, rather than appends, to the array exp that contains the expansions) --- this doesn't appear to be documented --- so passing back an additional reply from the function ought to be good enough. So we could use REPLY and do something like the following. Index: Completion/Base/Completer/_user_expand =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/Base/Completer/_user_expand,v retrieving revision 1.1 diff -p -u -r1.1 _user_expand --- Completion/Base/Completer/_user_expand 25 Mar 2009 13:29:30 -0000 1.1 +++ Completion/Base/Completer/_user_expand 28 Aug 2012 12:56:03 -0000 @@ -12,7 +12,7 @@ setopt localoptions nonomatch [[ _matcher_num -gt 1 ]] && return 1 -local exp word sort expr expl subd suf=" " asp tmp spec +local exp word sort expr expl subd suf=" " asp tmp spec REPLY local -a specs reply if [[ "$funcstack[2]" = _prefix ]]; then @@ -30,6 +30,7 @@ exp=("$word") zstyle -a ":completion:${curcontext}" user-expand specs || return 1 for spec in $specs; do + REPLY= case $spec in ('$'[[:IDENT:]]##) # Spec is an associative array with explicit keys. @@ -85,9 +86,9 @@ fi if [[ -z "$compstate[insert]" ]] ;then if [[ "$sort" = menu ]]; then - _description expansions expl expansions "o:$word" + _description expansions expl "expansions${REPLY:+: $REPLY}" "o:$word" else - _description -V expansions expl expansions "o:$word" + _description -V expansions expl "expansions${REPLY:+: $REPLY}" "o:$word" fi compadd "$expl[@]" -UQ -qS "$suf" -a exp @@ -98,9 +99,9 @@ else local i j normal space dir if [[ "$sort" = menu ]]; then - _description expansions expl expansions "o:$word" + _description expansions expl "expansions${REPLY:+: $REPLY}" "o:$word" else - _description -V expansions expl expansions "o:$word" + _description -V expansions expl "expansions${REPLY:+: $REPLY}" "o:$word" fi normal=() space=() @@ -120,7 +121,7 @@ else (( $#space )) && compadd "$expl[@]" -UQ -qS " " -a space (( $#normal )) && compadd "$expl[@]" -UQ -qS "" -a normal fi - if _requested all-expansions expl 'all expansions'; then + if _requested all-expansions expl "all expansions${REPLY:+: $REPLY}"; then local disp dstr if [[ "${#${exp}}" -ge COLUMNS ]]; then Index: Doc/Zsh/compsys.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v retrieving revision 1.248 diff -p -u -r1.248 compsys.yo --- Doc/Zsh/compsys.yo 21 Aug 2012 18:45:31 -0000 1.248 +++ Doc/Zsh/compsys.yo 28 Aug 2012 12:56:04 -0000 @@ -3180,7 +3180,9 @@ var(_func) is the name of a shell functi tt(_) but is not otherwise special to the completion system. The function is called with the trial word as an argument. If the word is to be expanded, the function should set the array tt(reply) to a list of -expansions. The return status of the function is irrelevant. +expansions. Optionally, it can set tt(REPLY) to a word that will +be used as a description for the set of expansions. +The return status of the function is irrelevant. ) endsitem() ) -- Peter Stephenson Software Engineer Tel: +44 (0)1223 692070 Cambridge Silicon Radio Limited Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom More information can be found at www.csr.com. Follow CSR on Twitter at http://twitter.com/CSR_PLC and read our blog at www.csr.com/blog