1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-09 00:11:25 +02:00

aloow value `pattern' for insert-unambiguous style to preserve patterns in the original string; add list-suffixes style to make file completion list path suffixes if possible; slightly improved completion of pathnames with multiple pattern-components (13128)

This commit is contained in:
Sven Wischnowsky 2000-11-08 09:20:42 +00:00
parent 551fbeeab9
commit e0dc80e0e5
5 changed files with 133 additions and 38 deletions

View file

@ -1,3 +1,12 @@
2000-11-08 Sven Wischnowsky <wischnow@zsh.org>
* 13128: Completion/Builtins/_zstyle, Completion/Core/_match,
Completion/Core/_path_files, Doc/Zsh/compsys.yo: aloow value
`pattern' for insert-unambiguous style to preserve patterns in the
original string; add list-suffixes style to make file completion
list path suffixes if possible; slightly improved completion of
pathnames with multiple pattern-components
2000-11-06 Bart Schaefer <schaefer@zsh.org> 2000-11-06 Bart Schaefer <schaefer@zsh.org>
* 13127: Completion/User/_rcs: Test of $compstate[nmatches] was a * 13127: Completion/User/_rcs: Test of $compstate[nmatches] was a

View file

@ -44,7 +44,7 @@ styles=(
ignored-patterns c: ignored-patterns c:
insert-ids c:insert-ids insert-ids c:insert-ids
insert-tab c:bool insert-tab c:bool
insert-unambiguous c:bool insert-unambiguous c:insunambig
keep-prefix c:keep-prefix keep-prefix c:keep-prefix
last-prompt c:bool last-prompt c:bool
list c:listwhen list c:listwhen
@ -52,6 +52,7 @@ styles=(
list-packed c:bool list-packed c:bool
list-prompt c: list-prompt c:
list-rows-first c:bool list-rows-first c:bool
list-suffixes c:bool
local c: local c:
match-original c:match-orig match-original c:match-orig
matcher c: matcher c:
@ -292,6 +293,10 @@ while [[ -n $state ]]; do
_wanted values expl 'use list of old matches' compadd true false only _wanted values expl 'use list of old matches' compadd true false only
;; ;;
insunambig)
_wanted values expl 'insert unambiguous string compadd true false pattern
;;
urgh) urgh)
_wanted values expl no compadd no false off 0 _wanted values expl no compadd no false off 0
;; ;;

View file

@ -11,41 +11,60 @@
### Shouldn't be needed any more: [[ _matcher_num -gt 1 ]] && return 1 ### Shouldn't be needed any more: [[ _matcher_num -gt 1 ]] && return 1
local tmp opm="$compstate[pattern_match]" ret=0 orig ins local tmp opm="$compstate[pattern_match]" ret=1 orig ins
local oms="$_old_match_string"
local ocsi="$compstate[insert]" ocspi="$compstate[pattern_insert]"
# Do nothing if we don't have a pattern. # Do nothing if we don't have a pattern.
tmp="${${:-$PREFIX$SUFFIX}#[~=]}" tmp="${${:-$PREFIX$SUFFIX}#[~=]}"
[[ "$tmp:q" = "$tmp" ]] && return 1 [[ "$tmp:q" = "$tmp" ]] && return 1
_old_match_string="$PREFIX$SUFFIX$HISTNO"
zstyle -s ":completion:${curcontext}:" match-original orig zstyle -s ":completion:${curcontext}:" match-original orig
zstyle -b ":completion:${curcontext}:" insert-unambiguous ins zstyle -s ":completion:${curcontext}:" insert-unambiguous ins
# Try completion without inserting a `*'? # Try completion without inserting a `*'?
if [[ -n "$orig" ]]; then if [[ -n "$orig" ]]; then
compstate[pattern_match]='-' compstate[pattern_match]='-'
_complete && ret=1 _complete && ret=0
compstate[pattern_match]="$opm" compstate[pattern_match]="$opm"
if (( ret )); then # No completion with inserting `*'?
[[ "$ins" = yes &&
$#compstate[unambiguous] -ge ${#:-${PREFIX}${SUFFIX}} ]] && [[ ret -eq 1 && "$orig" = only ]] && return 1
compstate[pattern_insert]=unambiguous
return 0
fi
fi fi
# No completion with inserting `*'? if (( ret )); then
compstate[pattern_match]='*'
_complete && ret=0
compstate[pattern_match]="$opm"
fi
[[ "$orig" = only ]] && return 1 if (( ! ret )); then
compstate[pattern_match]='*' if [[ "$ins" = pattern && $compstate[nmatches] -gt 1 ]]; then
_complete && ret=1
compstate[pattern_match]="$opm"
[[ ret -eq 1 && "$ins" = yes && [[ "$oms" = "$PREFIX$SUFFIX$HISTNO" &&
$#compstate[unambiguous] -ge ${#:-${PREFIX}${SUFFIX}} ]] && "$compstate[insert]" = automenu-unambiguous ]] &&
compstate[pattern_insert]=unambiguous compstate[insert]=automenu
[[ "$compstate[insert]" != *menu ]] &&
compstate[pattern_insert]= compstate[insert]=
return 1-ret # We tried to be clever here, making completion insert unambiguous
# expansions as early as possible, but this is really hard to test
# and the code below probably does more harm than good.
#
# [[ $compstate[unambiguous_cursor] -gt $#compstate[unambiguous] ]] &&
# ins=yes compstate[insert]="$ocsi" compstate[pattern_insert]="$ocspi"
fi
[[ "$ins" = (true|yes|on|1) &&
$#compstate[unambiguous] -ge ${#:-${PREFIX}${SUFFIX}} ]] &&
compstate[pattern_insert]=unambiguous
fi
return ret

View file

@ -5,7 +5,7 @@
local linepath realpath donepath prepath testpath exppath skips skipped local linepath realpath donepath prepath testpath exppath skips skipped
local tmp1 tmp2 tmp3 tmp4 i orig eorig pre suf tpre tsuf opre osuf cpre local tmp1 tmp2 tmp3 tmp4 i orig eorig pre suf tpre tsuf opre osuf cpre
local pats haspats ignore pfxsfx sopt gopt opt sdirs ignpar cfopt local pats haspats ignore pfxsfx sopt gopt opt sdirs ignpar cfopt listsfx
local nm=$compstate[nmatches] menu matcher mopts sort match mid accex fake local nm=$compstate[nmatches] menu matcher mopts sort match mid accex fake
typeset -U prepaths exppaths typeset -U prepaths exppaths
@ -137,6 +137,8 @@ else
fi fi
zstyle -s ":completion:${curcontext}:paths" special-dirs sdirs zstyle -s ":completion:${curcontext}:paths" special-dirs sdirs
zstyle -t ":completion:${curcontext}:paths" list-suffixes &&
listsfx=yes
[[ "$pats" = ((|*[[:blank:]])\*(|[[:blank:]]*)|*\([^[:blank:]]#/[^[:blank:]]#\)*) ]] && [[ "$pats" = ((|*[[:blank:]])\*(|[[:blank:]]*)|*\([^[:blank:]]#/[^[:blank:]]#\)*) ]] &&
sopt=$sopt/ sopt=$sopt/
@ -460,9 +462,11 @@ for prepath in "$prepaths[@]"; do
SUFFIX="${tsuf}" SUFFIX="${tsuf}"
fi fi
if (( tmp4 )) || # This once tested `|| [[ -n "$compstate[pattern_match]" &&
[[ -n "$compstate[pattern_match]" && # "$tmp2" = (|*[^\\])[][*?#~^\|\<\>]* ]]' but it should now be smart
"$tmp2" = (|*[^\\])[][*?#~^\|\<\>]* ]]; then # enough to handle multiple components with patterns.
if (( tmp4 )); then
# It is. For menucompletion we now add the possible completions # It is. For menucompletion we now add the possible completions
# for this component with the unambigous prefix we have built # for this component with the unambigous prefix we have built
# and the rest of the string from the line as the suffix. # and the rest of the string from the line as the suffix.
@ -480,15 +484,33 @@ for prepath in "$prepaths[@]"; do
compquote tmp1 tmp2 compquote tmp1 tmp2
fi fi
if [[ -z "$_comp_correct" &&
"$compstate[pattern_match]" = \* && -n "$listsfx" &&
"$tmp2" = (|*[^\\])[][*?#~^\|\<\>]* ]]; then
PREFIX="$opre"
SUFFIX="$osuf"
fi
if [[ -n $menu || -z "$compstate[insert]" ]] || if [[ -n $menu || -z "$compstate[insert]" ]] ||
! zstyle -t ":completion:${curcontext}:paths" expand suffix; then ! zstyle -t ":completion:${curcontext}:paths" expand suffix ||
[[ -z "$listsfx" &&
( -n "$_comp_correct" ||
-z "$compstate[pattern_match]" || "$SUFFIX" != */* ||
"${SUFFIX#*/}" = (|*[^\\])[][*?#~^\|\<\>]* ) ]]; then
(( tmp4 )) && zstyle -t ":completion:${curcontext}:paths" ambiguous && (( tmp4 )) && zstyle -t ":completion:${curcontext}:paths" ambiguous &&
compstate[to_end]= compstate[to_end]=
if [[ "$tmp3" = */* ]]; then if [[ "$tmp3" = */* ]]; then
compadd -Qf "$mopts[@]" -p "$linepath$tmp2" -s "/${tmp3#*/}" \ if [[ -z "$listsfx" || "$tmp3" != */?* ]]; then
-W "$prepath$realpath$testpath" \ compadd -Qf "$mopts[@]" -p "$linepath$tmp2" -s "/${tmp3#*/}" \
"$pfxsfx[@]" -M "r:|/=* r:|=*" \ -W "$prepath$realpath$testpath" \
- "${(@)tmp1%%/*}" "$pfxsfx[@]" -M "r:|/=* r:|=*" \
- "${(@)tmp1%%/*}"
else
compadd -Qf "$mopts[@]" -p "$linepath$tmp2" \
-W "$prepath$realpath$testpath" \
"$pfxsfx[@]" -M "r:|/=* r:|=*" \
- "${(@)^tmp1%%/*}/${tmp3#*/}"
fi
else else
compadd -Qf "$mopts[@]" -p "$linepath$tmp2" \ compadd -Qf "$mopts[@]" -p "$linepath$tmp2" \
-W "$prepath$realpath$testpath" \ -W "$prepath$realpath$testpath" \
@ -497,12 +519,20 @@ for prepath in "$prepaths[@]"; do
fi fi
else else
if [[ "$tmp3" = */* ]]; then if [[ "$tmp3" = */* ]]; then
tmp3=( -Qf "$mopts[@]" -p "$linepath$tmp2" tmp4=( -Qf "$mopts[@]" -p "$linepath$tmp2"
-W "$prepath$realpath$testpath" -W "$prepath$realpath$testpath"
"$pfxsfx[@]" -M "r:|/=* r:|=*" ) "$pfxsfx[@]" -M "r:|/=* r:|=*" )
for i in "$tmp1[@]"; do if [[ -z "$listsfx" ]]; then
compadd "$tmp3[@]" -s "/${i#*/}" - "${i%%/*}" for i in "$tmp1[@]"; do
done compadd "$tmp4[@]" -s "/${i#*/}" - "${i%%/*}"
done
else
[[ -n "$compstate[pattern_match]" ]] && SUFFIX="${SUFFIX:s./.*/}*"
for i in "$tmp1[@]"; do
compadd "$tmp4[@]" - "$i"
done
fi
else else
compadd -Qf "$mopts[@]" -p "$linepath$tmp2" \ compadd -Qf "$mopts[@]" -p "$linepath$tmp2" \
-W "$prepath$realpath$testpath" \ -W "$prepath$realpath$testpath" \
@ -526,22 +556,33 @@ for prepath in "$prepaths[@]"; do
# take it from the filenames. # take it from the filenames.
testpath="${testpath}${tmp1[1]%%/*}/" testpath="${testpath}${tmp1[1]%%/*}/"
tmp1=( "${(@)tmp1#*/}" )
tmp3="${tmp3#*/}" tmp3="${tmp3#*/}"
if [[ "$tpre" = */* ]]; then if [[ "$tpre" = */* ]]; then
cpre="${cpre}${tpre%%/*}/" if [[ -z "$_comp_correct" && -n "$compstate[pattern_match]" &&
"$tmp2" = (|*[^\\])[][*?#~^\|\<\>]* ]]; then
cpre="${cpre}${tmp1[1]%%/*}/"
else
cpre="${cpre}${tpre%%/*}/"
fi
tpre="${tpre#*/}" tpre="${tpre#*/}"
elif [[ "$tsuf" = */* ]]; then elif [[ "$tsuf" = */* ]]; then
[[ "$tsuf" != /* ]] && mid="$testpath" [[ "$tsuf" != /* ]] && mid="$testpath"
cpre="${cpre}${tpre}/" if [[ -z "$_comp_correct" && -n "$compstate[pattern_match]" &&
"$tmp2" = (|*[^\\])[][*?#~^\|\<\>]* ]]; then
cpre="${cpre}${tmp1[1]%%/*}/"
else
cpre="${cpre}${tpre}/"
fi
tpre="${tsuf#*/}" tpre="${tsuf#*/}"
tsuf= tsuf=
else else
tpre= tpre=
tsuf= tsuf=
fi fi
tmp1=( "${(@)tmp1#*/}" )
done done
if [[ -z "$tmp4" ]]; then if [[ -z "$tmp4" ]]; then
@ -580,8 +621,14 @@ for prepath in "$prepaths[@]"; do
else else
compquote tmp4 tmp1 compquote tmp4 tmp1
fi fi
compadd -Qf "$mopts[@]" -p "$linepath$tmp4" -W "$prepath$realpath$testpath" \ if [[ -z "$_comp_correct" && -n "$compstate[pattern_match]" &&
"$pfxsfx[@]" -M "r:|/=* r:|=*" -a tmp1 "$PREFIX$SUFFIX" = (|*[^\\])[][*?#~^\|\<\>]* ]]; then
compadd -Qf -W "$prepath$realpath" "$pfxsfx[@]" "$mopts[@]" \
-M "r:|/=* r:|=*" - "$linepath$tmp4${(@)^tmp1}"
else
compadd -Qf -p "$linepath$tmp4" -W "$prepath$realpath$testpath" \
"$pfxsfx[@]" "$mopts[@]" -M "r:|/=* r:|=*" -a tmp1
fi
fi fi
fi fi
done done

View file

@ -1368,6 +1368,10 @@ tt(_approximate) completer uses it after setting the completer field
in the context name to one of tt(correct-)var(num) or in the context name to one of tt(correct-)var(num) or
tt(approximate-)var(num), where var(num) is the number of errors that tt(approximate-)var(num), where var(num) is the number of errors that
were accepted. were accepted.
When used for the tt(_match) completer, the style may also be set to
the string `tt(pattern)'. This makes the pattern on the line be left
unchanged if it didn't match unambiguously.
) )
kindex(keep-prefix, completion style) kindex(keep-prefix, completion style)
item(tt(keep-prefix))( item(tt(keep-prefix))(
@ -1467,6 +1471,14 @@ This style is tested in the same way as the tt(list-packed) style and
determines if matches are to be listed in a rows-first fashion, as for the determines if matches are to be listed in a rows-first fashion, as for the
tt(LIST_ROWS_FIRST) option. tt(LIST_ROWS_FIRST) option.
) )
kindex(list-suffixes, completion style)
item(tt(list-suffixes))(
This style is used by the function used to complete filenames. If
completion is attempted on a string containing multiple partially
typed pathname components and this style is set to `true', all
components starting with the first one for which more than one match
could be generated will be shown.
)
kindex(local, completion style) kindex(local, completion style)
item(tt(local))( item(tt(local))(
This style is used by completion functions which generate URLs as This style is used by completion functions which generate URLs as
@ -2417,6 +2429,9 @@ The generated matches will be offered in a menu completion unless the
tt(insert-unambiguous) style is set to `true'. In tt(insert-unambiguous) style is set to `true'. In
this case menu completion will only be started if no unambiguous string this case menu completion will only be started if no unambiguous string
could be generated that is at least as long as the original string. could be generated that is at least as long as the original string.
The style may also be set to the string `tt(pattern)'. This will keep
the pattern on the line intact as long as there isn't an unambiguous
completion with which it could be replaced.
Note that the matcher specifications defined globally or used by the Note that the matcher specifications defined globally or used by the
completion functions will not be used. completion functions will not be used.
@ -3475,7 +3490,7 @@ These functions also accept the `tt(-J)', `tt(-V)', `tt(-1)',
`tt(-r)', and `tt(-R)' options from the tt(compadd) builtin. `tt(-r)', and `tt(-R)' options from the tt(compadd) builtin.
Finally, the tt(_path_files) function uses the styles tt(expand), Finally, the tt(_path_files) function uses the styles tt(expand),
tt(ambiguous) and tt(special-dirs) and tt(file-sort). tt(ambiguous), tt(special-dirs), tt(list-suffixes) and tt(file-sort).
) )
findex(_regex_arguments) findex(_regex_arguments)
item(tt(_regex_arguments) var(name) var(specs) ...)( item(tt(_regex_arguments) var(name) var(specs) ...)(