1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-03 10:21:46 +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>
* 13127: Completion/User/_rcs: Test of $compstate[nmatches] was a

View file

@ -44,7 +44,7 @@ styles=(
ignored-patterns c:
insert-ids c:insert-ids
insert-tab c:bool
insert-unambiguous c:bool
insert-unambiguous c:insunambig
keep-prefix c:keep-prefix
last-prompt c:bool
list c:listwhen
@ -52,6 +52,7 @@ styles=(
list-packed c:bool
list-prompt c:
list-rows-first c:bool
list-suffixes c:bool
local c:
match-original c:match-orig
matcher c:
@ -292,6 +293,10 @@ while [[ -n $state ]]; do
_wanted values expl 'use list of old matches' compadd true false only
;;
insunambig)
_wanted values expl 'insert unambiguous string compadd true false pattern
;;
urgh)
_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
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.
tmp="${${:-$PREFIX$SUFFIX}#[~=]}"
[[ "$tmp:q" = "$tmp" ]] && return 1
_old_match_string="$PREFIX$SUFFIX$HISTNO"
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 `*'?
if [[ -n "$orig" ]]; then
compstate[pattern_match]='-'
_complete && ret=1
_complete && ret=0
compstate[pattern_match]="$opm"
if (( ret )); then
[[ "$ins" = yes &&
$#compstate[unambiguous] -ge ${#:-${PREFIX}${SUFFIX}} ]] &&
compstate[pattern_insert]=unambiguous
return 0
fi
# No completion with inserting `*'?
[[ ret -eq 1 && "$orig" = only ]] && return 1
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]='*'
_complete && ret=1
compstate[pattern_match]="$opm"
if [[ "$ins" = pattern && $compstate[nmatches] -gt 1 ]]; then
[[ ret -eq 1 && "$ins" = yes &&
$#compstate[unambiguous] -ge ${#:-${PREFIX}${SUFFIX}} ]] &&
compstate[pattern_insert]=unambiguous
[[ "$oms" = "$PREFIX$SUFFIX$HISTNO" &&
"$compstate[insert]" = automenu-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 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
typeset -U prepaths exppaths
@ -137,6 +137,8 @@ else
fi
zstyle -s ":completion:${curcontext}:paths" special-dirs sdirs
zstyle -t ":completion:${curcontext}:paths" list-suffixes &&
listsfx=yes
[[ "$pats" = ((|*[[:blank:]])\*(|[[:blank:]]*)|*\([^[:blank:]]#/[^[:blank:]]#\)*) ]] &&
sopt=$sopt/
@ -460,9 +462,11 @@ for prepath in "$prepaths[@]"; do
SUFFIX="${tsuf}"
fi
if (( tmp4 )) ||
[[ -n "$compstate[pattern_match]" &&
"$tmp2" = (|*[^\\])[][*?#~^\|\<\>]* ]]; then
# This once tested `|| [[ -n "$compstate[pattern_match]" &&
# "$tmp2" = (|*[^\\])[][*?#~^\|\<\>]* ]]' but it should now be smart
# enough to handle multiple components with patterns.
if (( tmp4 )); then
# It is. For menucompletion we now add the possible completions
# for this component with the unambigous prefix we have built
# and the rest of the string from the line as the suffix.
@ -480,15 +484,33 @@ for prepath in "$prepaths[@]"; do
compquote tmp1 tmp2
fi
if [[ -z "$_comp_correct" &&
"$compstate[pattern_match]" = \* && -n "$listsfx" &&
"$tmp2" = (|*[^\\])[][*?#~^\|\<\>]* ]]; then
PREFIX="$opre"
SUFFIX="$osuf"
fi
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 &&
compstate[to_end]=
if [[ "$tmp3" = */* ]]; then
compadd -Qf "$mopts[@]" -p "$linepath$tmp2" -s "/${tmp3#*/}" \
-W "$prepath$realpath$testpath" \
"$pfxsfx[@]" -M "r:|/=* r:|=*" \
- "${(@)tmp1%%/*}"
if [[ -z "$listsfx" || "$tmp3" != */?* ]]; then
compadd -Qf "$mopts[@]" -p "$linepath$tmp2" -s "/${tmp3#*/}" \
-W "$prepath$realpath$testpath" \
"$pfxsfx[@]" -M "r:|/=* r:|=*" \
- "${(@)tmp1%%/*}"
else
compadd -Qf "$mopts[@]" -p "$linepath$tmp2" \
-W "$prepath$realpath$testpath" \
"$pfxsfx[@]" -M "r:|/=* r:|=*" \
- "${(@)^tmp1%%/*}/${tmp3#*/}"
fi
else
compadd -Qf "$mopts[@]" -p "$linepath$tmp2" \
-W "$prepath$realpath$testpath" \
@ -497,12 +519,20 @@ for prepath in "$prepaths[@]"; do
fi
else
if [[ "$tmp3" = */* ]]; then
tmp3=( -Qf "$mopts[@]" -p "$linepath$tmp2"
tmp4=( -Qf "$mopts[@]" -p "$linepath$tmp2"
-W "$prepath$realpath$testpath"
"$pfxsfx[@]" -M "r:|/=* r:|=*" )
for i in "$tmp1[@]"; do
compadd "$tmp3[@]" -s "/${i#*/}" - "${i%%/*}"
done
if [[ -z "$listsfx" ]]; then
for i in "$tmp1[@]"; do
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
compadd -Qf "$mopts[@]" -p "$linepath$tmp2" \
-W "$prepath$realpath$testpath" \
@ -526,22 +556,33 @@ for prepath in "$prepaths[@]"; do
# take it from the filenames.
testpath="${testpath}${tmp1[1]%%/*}/"
tmp1=( "${(@)tmp1#*/}" )
tmp3="${tmp3#*/}"
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#*/}"
elif [[ "$tsuf" = */* ]]; then
[[ "$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#*/}"
tsuf=
else
tpre=
tsuf=
fi
tmp1=( "${(@)tmp1#*/}" )
done
if [[ -z "$tmp4" ]]; then
@ -580,8 +621,14 @@ for prepath in "$prepaths[@]"; do
else
compquote tmp4 tmp1
fi
compadd -Qf "$mopts[@]" -p "$linepath$tmp4" -W "$prepath$realpath$testpath" \
"$pfxsfx[@]" -M "r:|/=* r:|=*" -a tmp1
if [[ -z "$_comp_correct" && -n "$compstate[pattern_match]" &&
"$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
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
tt(approximate-)var(num), where var(num) is the number of errors that
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)
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
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)
item(tt(local))(
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
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.
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
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.
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)
item(tt(_regex_arguments) var(name) var(specs) ...)(