* How to get compadd to not sort words?
@ 2014-12-15 1:35 Rocky Bernstein
2014-12-15 2:50 ` Bart Schaefer
0 siblings, 1 reply; 5+ messages in thread
From: Rocky Bernstein @ 2014-12-15 1:35 UTC (permalink / raw)
To: zsh-users
[-- Attachment #1: Type: text/plain, Size: 432 bytes --]
Hi -
I've been working on beefing up command completion in the zsh debugger
zshdb.
For example, if I enter
compadd -- 1 2 -1 -2 -3 0
The completions come out in the order:
-3 -2 -1 0 1 2
But what I really want is the order I gave. (The most frequent "up or down"
command has value 1; the last useful is "up 0" which doesn't do anything.)
How can I tell compadd not to sort the completions?
Thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How to get compadd to not sort words?
2014-12-15 1:35 How to get compadd to not sort words? Rocky Bernstein
@ 2014-12-15 2:50 ` Bart Schaefer
2014-12-15 6:59 ` Rocky Bernstein
0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2014-12-15 2:50 UTC (permalink / raw)
To: zsh-users
On Dec 14, 8:35pm, Rocky Bernstein wrote:
}
} For example, if I enter
}
} compadd -- 1 2 -1 -2 -3 0
}
} The completions come out in the order:
}
} -3 -2 -1 0 1 2
}
} But what I really want is the order I gave.
"compadd" is actually one of the better-documented bits of the completion
system. Some of the "support builtins" aren't documented at all.
} How can I tell compadd not to sort the completions?
You need to put them in a named unsorted group.
compadd -V numbers 1 2 -1 -2 -3 0
Group names end up being referenced via the "tag" slot in the six-part
completion context string, e.g., with the compadd above you might use
zstyle ':completion:*:*:*:*:numbers' list-colors '=-*=7'
to show negative numbers in reverse video. However, to make that work
you have to initialize the style mechanism by calling _description:
local expl
_description -V numbers expl 'Some Numbers'
compadd "$expl[@]" - 1 2 -1 -2 -3 0
The _description function does all the style processing and fills in
the $expl variable with the corresponding compadd options. The example
in the zsh manual isn't as clear as it could be because it uses
_description files expl file
compadd "$expl[@]" - "$files[@]"
and although expl in the _description call maps to $expl in the compadd
call, the two uses of "files" are unrelated.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How to get compadd to not sort words?
2014-12-15 2:50 ` Bart Schaefer
@ 2014-12-15 6:59 ` Rocky Bernstein
2014-12-15 9:09 ` Bart Schaefer
0 siblings, 1 reply; 5+ messages in thread
From: Rocky Bernstein @ 2014-12-15 6:59 UTC (permalink / raw)
To: Bart Schaefer; +Cc: zsh-users
[-- Attachment #1: Type: text/plain, Size: 1682 bytes --]
Many thanks.
This does the trick. I'm happy with getting this in the order given without
special formatting of negative numbers.
On Sun, Dec 14, 2014 at 9:50 PM, Bart Schaefer <schaefer@brasslantern.com>
wrote:
> On Dec 14, 8:35pm, Rocky Bernstein wrote:
> }
> } For example, if I enter
> }
> } compadd -- 1 2 -1 -2 -3 0
> }
> } The completions come out in the order:
> }
> } -3 -2 -1 0 1 2
> }
> } But what I really want is the order I gave.
>
> "compadd" is actually one of the better-documented bits of the completion
> system. Some of the "support builtins" aren't documented at all.
>
> } How can I tell compadd not to sort the completions?
>
> You need to put them in a named unsorted group.
>
> compadd -V numbers 1 2 -1 -2 -3 0
>
> Group names end up being referenced via the "tag" slot in the six-part
> completion context string, e.g., with the compadd above you might use
>
> zstyle ':completion:*:*:*:*:numbers' list-colors '=-*=7'
>
> to show negative numbers in reverse video. However, to make that work
> you have to initialize the style mechanism by calling _description:
>
> local expl
> _description -V numbers expl 'Some Numbers'
> compadd "$expl[@]" - 1 2 -1 -2 -3 0
>
> The _description function does all the style processing and fills in
> the $expl variable with the corresponding compadd options. The example
> in the zsh manual isn't as clear as it could be because it uses
>
> _description files expl file
> compadd "$expl[@]" - "$files[@]"
>
> and although expl in the _description call maps to $expl in the compadd
> call, the two uses of "files" are unrelated.
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How to get compadd to not sort words?
2014-12-15 6:59 ` Rocky Bernstein
@ 2014-12-15 9:09 ` Bart Schaefer
2014-12-15 16:16 ` Rocky Bernstein
0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2014-12-15 9:09 UTC (permalink / raw)
To: zsh-users
On Dec 15, 1:59am, Rocky Bernstein wrote:
}
} Many thanks.
}
} This does the trick. I'm happy with getting this in the order given without
} special formatting of negative numbers.
You're welcome. The special formatting was just an example I picked to
show how you'd associate styles with the completion results.
In fact, just to flesh out the example a little ...
If you want ^Xh (_complete_help) to be able to generate useful help for
the context, you need to call _tags to initialize that part of the
system, and then you should use the _requested wrapper to make the call
to _description and compadd. So you might do
_unsorted() {
local expl ret=1
_tags numbers letters
while _tags; do
if _requested -V numbers expl 'Some Numbers' compadd 1 2 -1 -2 3 0
then ret=0
fi
if _requested -V letters expl 'Some Letters' compadd A B Z X C M
then ret=0
fi
done
return ret
}
This is obviously a lot more interesting if the completions are more than
a single character/digit. For sorted groups, use -J instead of -V. (No,
there isn't a mnemonic for why -J and -V got used here; it was because
they were single letters not already being used for something else.)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How to get compadd to not sort words?
2014-12-15 9:09 ` Bart Schaefer
@ 2014-12-15 16:16 ` Rocky Bernstein
0 siblings, 0 replies; 5+ messages in thread
From: Rocky Bernstein @ 2014-12-15 16:16 UTC (permalink / raw)
To: Bart Schaefer; +Cc: zsh-users
[-- Attachment #1: Type: text/plain, Size: 2245 bytes --]
Without a doubt the feature of help on a completion group is cool. Those
numbers do fall into the category of a relative frame index. And there's an
absolute frame index,
a breakpoint number, and so on. And some of the categories are already
built in like files.
But as with all things zsh-specific, I find it hard to get to to work on my
own.
I've been working on zshdb recently not for any specific need, but because
I have a little time right now to spend and over the years people have +1'd
it during the times when I didn't have time to devote to it. (So a general
hint to users - if you +1 a project it will tend encourage maintainers of
the project to work on it.)
The debugger completion code I have is at
https://github.com/rocky/zshdb/blob/master/lib/complete.sh in case folks
want to improve it. You can run it standalone.
On Mon, Dec 15, 2014 at 4:09 AM, Bart Schaefer <schaefer@brasslantern.com>
wrote:
> On Dec 15, 1:59am, Rocky Bernstein wrote:
> }
> } Many thanks.
> }
> } This does the trick. I'm happy with getting this in the order given
> without
> } special formatting of negative numbers.
>
> You're welcome. The special formatting was just an example I picked to
> show how you'd associate styles with the completion results.
>
> In fact, just to flesh out the example a little ...
>
> If you want ^Xh (_complete_help) to be able to generate useful help for
> the context, you need to call _tags to initialize that part of the
> system, and then you should use the _requested wrapper to make the call
> to _description and compadd. So you might do
>
> _unsorted() {
> local expl ret=1
> _tags numbers letters
> while _tags; do
> if _requested -V numbers expl 'Some Numbers' compadd 1 2 -1 -2 3 0
> then ret=0
> fi
> if _requested -V letters expl 'Some Letters' compadd A B Z X C M
> then ret=0
> fi
> done
> return ret
> }
>
> This is obviously a lot more interesting if the completions are more than
> a single character/digit. For sorted groups, use -J instead of -V. (No,
> there isn't a mnemonic for why -J and -V got used here; it was because
> they were single letters not already being used for something else.)
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-12-15 16:16 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-15 1:35 How to get compadd to not sort words? Rocky Bernstein
2014-12-15 2:50 ` Bart Schaefer
2014-12-15 6:59 ` Rocky Bernstein
2014-12-15 9:09 ` Bart Schaefer
2014-12-15 16:16 ` Rocky Bernstein
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).