Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Feature Patch: Use completion to view parameter values
- X-seq: zsh-workers 48333
- From: Marlon Richert <marlon.richert@xxxxxxxxx>
- To: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: Feature Patch: Use completion to view parameter values
- Date: Mon, 29 Mar 2021 23:00:12 +0300
- Archived-at: <https://zsh.org/workers/48333>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-workers/2021-03/CAHLkEDtFJbs0gUT-CD-FNBhqP6CiHqiNxbfmbhAJHLYqC%2BkO%3Dw%40mail.gmail.com>
- In-reply-to: <20210329181452.GB6044@tarpaulin.shahaf.local2>
- List-id: <zsh-workers.zsh.org>
- References: <CAHLkEDtf6JqSn86duXjEuQFXGKJn8COcxnEypoOUV=V63SsdPQ@mail.gmail.com> <20210329073913.GP18178@tarpaulin.shahaf.local2> <CAHLkEDuHjvRhXhcX4iqZ0mJuAabcpSnRikunLeK9Y2Ucjhf0oQ@mail.gmail.com> <20210329171120.GA6044@tarpaulin.shahaf.local2> <CAH+w=7bD9bA-AKV4NoQ9YZVM_VpSMgX8GcLjSVhgP06KYokM_A@mail.gmail.com> <20210329181452.GB6044@tarpaulin.shahaf.local2>
On Mon, Mar 29, 2021 at 9:14 PM Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> wrote:
> And in Marlon's patch with the ${(t)…*special*} exclusion bypassed:
> .
> % zstyle \* extra-verbose yes
> % AUTOFOO=42
> % echo $AUTO<TAB><TAB>
> AUTOFOO -- 42 AUTOINCREMENT -- 2
> AUTOFOO -- 42 AUTOINCREMENT -- 4
>
> Yes, it does actually increment the variable twice, probably because the
> _parameters patch uses both ${(t)${(P)}} and then ${(P)}, and the former
> does an increment too:
> .
> % echo $AUTOINCREMENT ${(tP)AUTOINCREMENT} $AUTOINCREMENT
> 0 array-special 2
> %
Hm, that made me realize that using ${(tP)…} is wholly unnecessary,
since _parameter already uses $parameters anyway. So, here's a new
patch that uses $parameters instead of ${(tP)…}:
commit 5ef8fcaabe243c8c4e04de92e1f971543470ce87
Author: Marlon Richert <marlon.richert@xxxxxxxxx>
Date: Mon Mar 29 22:56:34 2021 +0300
Let `zstyle extra-verbose` show parameter values
When completing parameters and
`zstyle -t ":completion:${curcontext}:parameters" extra-verbose`,
display values of non-special parameters as descriptions.
diff --git a/Completion/Zsh/Type/_parameters b/Completion/Zsh/Type/_parameters
index 207e5cf78..b32e049f7 100644
--- a/Completion/Zsh/Type/_parameters
+++ b/Completion/Zsh/Type/_parameters
@@ -6,13 +6,18 @@
# If you specify a -g option with a pattern, the pattern will be used to
# restrict the type of parameters matched.
-local expl pattern fakes faked tmp i pfilt
+local MATCH MBEGIN MEND \
+ disp dopt expl fakes faked i matches pattern pfilt sep tmp
if compset -P '*:'; then
_history_modifiers p
return
fi
+_tags parameters
+( _tags && _requested parameters ) ||
+ return
+
pattern=(-g \*)
zparseopts -D -K -E g:=pattern
@@ -32,8 +37,19 @@ zstyle -t ":completion:${curcontext}:parameters"
prefix-needed && \
[[ $PREFIX != [_.]* ]] && \
pfilt='[^_.]'
-_wanted parameters expl parameter \
- compadd "$@" -Q - \
- "${(@M)${(@k)parameters[(R)${pattern[2]}~*local*]}:#${~pfilt}*}" \
- "$fakes[@]" \
- "${(@)${(@M)faked:#${~pattern[2]}}%%:*}"
+_description parameters expl parameter
+compadd "$expl[@]" -O matches - \
+ "${(@M)${(@k)parameters[(R)${pattern[2]}~*local*]}:#${~pfilt}*}" \
+ "$fakes[@]" \
+ "${(@)${(@M)faked:#${~pattern[2]}}%%:*}"
+
+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}}"}
+ disp=( "${disp[@]:/(#m)*/$MATCH[1,COLUMNS]}" )
+ dopt=( -d disp )
+fi
+
+compadd "$expl[@]" $dopt -Q -a matches
diff --git a/Test/Y01completion.ztst b/Test/Y01completion.ztst
index 571f3cf16..e5901b8e5 100644
--- a/Test/Y01completion.ztst
+++ b/Test/Y01completion.ztst
@@ -222,7 +222,7 @@ F:regression test workers/31611
comptesteval "zstyle ':completion:*:tst:*' ignored-patterns 2"
comptest $'tst 1,\t'
comptesteval "zstyle -d ':completion:*:tst:*' ignored-patterns"
-0:-F doesn't break _sequence
+0:-F doesn’t break _sequence
>line: {tst 1,}{}
>DESCRIPTION:{desc}
>NO:{2}
@@ -237,6 +237,28 @@ F:regression test workers/31611
>FI:{file1}
>FI:{file2}
+ comptesteval "bar=({$'\\0'..$'\\C-?'}); baz=\$bar"
+ comptesteval 'zstyle ":completion:*:parameters" extra-verbose yes'
+ comptest $': $ba\t'
+0:extra-verbose shows parameter values
+>line: {: $ba}{}
+>DESCRIPTION:{parameter}
+>NO:{bar -- '^@' '^A' '^B' '^C' '^D' '^E' '^F' '^G' '^H' '\t' '\n'
'^K' '^L' '^M' '^N}
+>NO:{baz -- '^@ ^A ^B ^C ^D ^E ^F ^G ^H \t \n ^K ^L ^M ^N ^O ^P ^Q ^R
^S ^T ^U ^V ^W }
+
+ comptest $': $path\C-D'
+0:extra-verbose does not show special parameter values
+>DESCRIPTION:{parameter}
+>NO:{path}
+
+ comptesteval 'zstyle -d ":completion:*:parameters" extra-verbose'
+ comptest $': $ba\t'
+0:parameter values not shown without extra-verbose
+>line: {: $ba}{}
+>DESCRIPTION:{parameter}
+>NO:{bar}
+>NO:{baz}
+
comptesteval '_tst() { local disp=( {a..z} ); compadd -ld disp
$disp[@]; comppostfuncs=( _pst ) }'
comptesteval '_pst() { local disp=(
"<INSERT>$compstate[insert]</INSERT>" ); compadd -Qld disp $disp }'
comptesteval "zstyle ':completion:*' menu select=long-list"
Messages sorted by:
Reverse Date,
Date,
Thread,
Author