51758: Make dynamic dir completion easier to implement

This commit is contained in:
Marlon Richert 2023-05-18 23:44:54 +03:00 committed by Oliver Kiddle
parent a95198e268
commit bb441f77a7
4 changed files with 56 additions and 35 deletions

View File

@ -1,3 +1,9 @@
2023-05-21 Oliver Kiddle <opk@zsh.org>
* Marlon Richert: 51758: Test/Y01completion.ztst, Doc/Zsh/expn.yo,
Completion/Zsh/Context/_dynamic_directory_name: Make dynamic dir
completion easier to implement
2023-05-13 Peter Stephenson <p.w.stephenson@ntlworld.com> 2023-05-13 Peter Stephenson <p.w.stephenson@ntlworld.com>
* 51722: Src/Modules/parameter.c: Add safety to extracting * 51722: Src/Modules/parameter.c: Add safety to extracting

View File

@ -1,15 +1,29 @@
#autoload #autoload
local -a dirfuncs=(
${(k)functions[zsh_directory_name]}
$zsh_directory_name_functions
)
local descr='dynamically named directory'
local func if (( $#dirfuncs )); then
integer ret=1 local -a expl
local -i ret
local func suf tag=dynamically-named-directories
if [[ -n $functions[zsh_directory_name] || \ [[ $ISUFFIX != \]* ]] &&
${+zsh_directory_name_functions} -ne 0 ]] ; then suf=-S]
[[ -n $functions[zsh_directory_name] ]] && zsh_directory_name c && ret=0
for func in $zsh_directory_name_functions; do _tags "$tag"
$func c && ret=0 while _tags; do
while _next_label "$tag" expl "$descr" $suf; do
for func in $dirfuncs; do
$func c && ret=0
done
done
(( ret )) || break
done done
return ret return ret
else else
_message 'dynamic directory name: implemented as zsh_directory_name c' _message "${descr}: implement as zsh_directory_name c"
fi fi

View File

@ -2066,34 +2066,24 @@ tt(/home/pws/perforce). In this simple case a static name for the
directory would be just as effective. directory would be just as effective.
example(zsh_directory_name+LPAR()RPAR() { example(zsh_directory_name+LPAR()RPAR() {
emulate -L zsh emulate -L zsh -o extendedglob
setopt extendedglob
local -a match mbegin mend local -a match mbegin mend
if [[ $1 = d ]]; then local base=/home/pws/perforce
# turn the directory into a name case $1 in
if [[ $2 = (#b)(/home/pws/perforce/)([^/]##)* ]]; then ( d ) # Turn the directory into a name.
typeset -ga reply [[ $2 == (#b)($base/)([^/]##)* ]] &&
reply=(p:$match[2] $(( ${#match[1]} + ${#match[2]} )) ) reply=( p:$match[2] $(( $#match[1] + $#match[2] )) )
else ;;
return 1 ( n ) # Turn the name into a directory.
fi [[ $2 == (#b)p:(?*) ]] &&
elif [[ $1 = n ]]; then reply=( $base/$match[1] )
# turn the name into a directory ;;
[[ $2 != (#b)p:(?*) ]] && return 1 ( c ) # Complete names.
typeset -ga reply local -a dirs=( $base/*(/:t) )
reply=(/home/pws/perforce/$match[1]) # Completion system populates $expl with flags for compadd.
elif [[ $1 = c ]]; then compadd "$expl[@]" p:$^dirs
# complete names ;;
local expl esac
local -a dirs
dirs=(/home/pws/perforce/*(/:t))
dirs=(p:${^dirs})
_wanted dynamic-dirs expl 'dynamic directory' compadd -S\] -a dirs
return
else
return 1
fi
return 0
}) })
texinode(Static named directories)(`=' expansion)(Dynamic named directories)(Filename Expansion) texinode(Static named directories)(`=' expansion)(Dynamic named directories)(Filename Expansion)

View File

@ -75,6 +75,17 @@
>line: {: ~user2}{} >line: {: ~user2}{}
>line: {: ~user1}{} >line: {: ~user1}{}
comptesteval 'zsh_directory_name() { compadd "$expl[@]" -- name1 name2 }'
comptest $': ~[\t\t\t\t'
0:dynamic directory names after ~[
>line: {: ~[name}{}
>line: {: ~[name}{}
>DESCRIPTION:{dynamically named directory}
>NO:{name1}
>NO:{name2}
>line: {: ~[name1]}{}
>line: {: ~[name2]}{}
comptest $'echo ;:\C-b\C-b\t' comptest $'echo ;:\C-b\C-b\t'
0:directories and files before separator 0:directories and files before separator
>line: {echo }{;:} >line: {echo }{;:}