* Ordering of alternatives for menu completion
@ 2012-03-07 13:24 Jesper Nygårds
2012-03-07 13:40 ` Peter Stephenson
0 siblings, 1 reply; 3+ messages in thread
From: Jesper Nygårds @ 2012-03-07 13:24 UTC (permalink / raw)
To: zsh-users
I use menu completion and I am trying to make a simple completion
function NOT sort the completion alternatives alphabetically.
I have a function called up(), and I am trying to add a completion
function for it, as follows:
_up() {
local myarray myindex revarray
myarray=( ${(s:/:)PWD} )
revarray=()
for myindex in {2..$(( $#myarray - 1 ))}; do
revarray=( $myarray[$myindex] $revarray[@] )
done
compadd - $revarray
}
compdef _up up
What it does is that it splits the current path into its parts, and
then reverses the array, ignoring the current directory (the last part
of the original array). So if $PWD is
"/Workbench/workspace/actual/src/main/resources", $revarray will be
"main src actual workspace Workbench".
This works fine, but when I use the completion like this: "up <tab>",
the alternatives are cycled in alphabetical order. I want them to be
suggested in the order of $revarray, i.e. with the closest parent
first and the progressively higher up in the hierarchy, but some
mechanism sorts the alternatives alphabetically.
I have experimented with different ways to indicate that I don't want
this array to be sorted, but haven't succeeded. How can I achieve
this?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Ordering of alternatives for menu completion
2012-03-07 13:24 Ordering of alternatives for menu completion Jesper Nygårds
@ 2012-03-07 13:40 ` Peter Stephenson
2012-03-07 14:21 ` Jesper Nygårds
0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2012-03-07 13:40 UTC (permalink / raw)
To: zsh-users
On Wed, 7 Mar 2012 14:24:43 +0100
Jesper Nygårds <jesper.nygards@gmail.com> wrote:
> _up() {
> local myarray myindex revarray
> myarray=( ${(s:/:)PWD} )
> revarray=()
> for myindex in {2..$(( $#myarray - 1 ))}; do
> revarray=( $myarray[$myindex] $revarray[@] )
> done
> compadd - $revarray
> }
> This works fine, but when I use the completion like this: "up <tab>",
> the alternatives are cycled in alphabetical order. I want them to be
> suggested in the order of $revarray, i.e. with the closest parent
> first and the progressively higher up in the hierarchy, but some
> mechanism sorts the alternatives alphabetically.
You need to tell compadd by passing -V plus the name of a group of
matches. I think
compadd -V unsorted - $revarray
ought to be good enough. While I'm at it,
compadd -V unsorted -a revarray
is a little more efficient if the array is big.
(It's not too hard to make this use the usual tags mechanism to mix with
other completions but it doesn't sound like you actually need that.)
--
Peter Stephenson <pws@csr.com> 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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Ordering of alternatives for menu completion
2012-03-07 13:40 ` Peter Stephenson
@ 2012-03-07 14:21 ` Jesper Nygårds
0 siblings, 0 replies; 3+ messages in thread
From: Jesper Nygårds @ 2012-03-07 14:21 UTC (permalink / raw)
To: zsh-users
On Wed, Mar 7, 2012 at 2:40 PM, Peter Stephenson
<Peter.Stephenson@csr.com> wrote:
> compadd -V unsorted - $revarray
>
> ought to be good enough. While I'm at it,
>
> compadd -V unsorted -a revarray
>
> is a little more efficient if the array is big.
>
Thank you, Peter, this solves my problem.
Jesper
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-03-07 14:21 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-07 13:24 Ordering of alternatives for menu completion Jesper Nygårds
2012-03-07 13:40 ` Peter Stephenson
2012-03-07 14:21 ` Jesper Nygårds
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).