Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Feature Patch: Use completion to view parameter values



On 29 Mar, Marlon Richert wrote:
> When completing parameters and
> `zstyle -t ":completion:${curcontext}:parameters" extra-verbose`,
> display values of non-special parameters as descriptions.

Incidentally, we actually already do this for array elements (with the
verbose style) but not for associative array elements. Numeric
indices are rather less meaningful so that only needing the verbose
style while this uses extra-verbose is probably sensible.

Following is a review of the patch:

> -local expl pattern fakes faked tmp i pfilt
> +local MATCH MBEGIN MEND \
> +  disp dopt expl fakes faked i matches pattern pfilt sep tmp

It isn't important but I tend to split these up by type and use `local
-a' or `local -i'. Setting the right type can avoid certain issues such
as += using the declared type.

> +_tags parameters
> +( _tags && _requested parameters ) ||
> +  return

I'm not entirely sure this is needed. Tag loop nesting isn't especially
ideal and helpers like _parameters are only called from places that
already have one. But it perhaps needs a little testing. I'm aware that
the old function had this in the form of _wanted.

> -_wanted parameters expl parameter \
> -    compadd "$@" -Q - \

Note the old function was passing "$@" which you've lost. This does
matter. Passed descriptions get thrown away, similarly pressing [ to
auto-remove space suffixes on arrays. "$@" is typically passed before
"$expl[@]".

The use of double indentation for continuation lines in the removed
lines is intentional by the way, see Etc/completion-style-guide

> +_description parameters expl parameter
> +compadd "$expl[@]" -O matches - \
> +  "${(@M)${(@k)parameters[(R)${pattern[2]}~*local*]}:#${~pfilt}*}" \
> +  "$fakes[@]" \
> +  "${(@)${(@M)faked:#${~pattern[2]}}%%:*}"

The faked parameters are not going to have a value. You can just add a
separate compadd for them right at the end (take care over return
status then). It will also then need to check if any faked parameters are
duplicates of real ones otherwise they'll appear twice.

> +
> +if zstyle -t ":completion:${curcontext}:parameters" extra-verbose; then
> +  zstyle -s ":completion:${curcontext}:parameters" list-separator sep ||
> +    sep=--
> +  zformat -a disp " $sep " \
> +    ${matches[@]:/(#m)*/"${MATCH}:${${parameters[$MATCH]:#*special*}:+${(Pkv@q+)MATCH}}"}

We should probably also honour the typeset -H flag so the pattern would
need to be *(hideval|special)*

By not using _describe, this has the advantage that if the values are
all short, it can use columns. Unfortunately, many variables force it to
be a single column and then many lines have only a single short
parameter on their own. Compounding this, the parameters ! - ? @ * # $
and 0 get sorted near the top each getting a whole line.

_describe does the matches with a description first with the -l option
to compadd and then adds in undescribed matches. Perhaps this can be
presented better even if the parameters need to be spliced up.

For my own setup, I'd likely limit this style to when at least a few
characters have been typed which would avoid this; something like:
  zstyle -e ':completion:*:parameters' extra-verbose 'reply=( $(( ($#PREFIX+$#SUFFIX) > 2 )) )'

The formatting for arrays, associative arrays and empty strings could
perhaps also be nicer. Perhaps that's something for a future update.

> -0:-F doesn't break _sequence
> +0:-F doesn’t break _sequence

This is a somewhat separate change. Do we want to be using unicode here?

And, thanks. This looks useful.

Oliver




Messages sorted by: Reverse Date, Date, Thread, Author