mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-30 07:10:58 +02:00
zsh-workers/9772
This commit is contained in:
parent
f82d790d90
commit
0e3f4cecde
10 changed files with 78 additions and 61 deletions
|
@ -5,13 +5,14 @@
|
|||
# shown in a list and one can cycle through them as in a menucompletion
|
||||
# or get the corrected prefix.
|
||||
|
||||
# We don't try correction if the string is too short or we have tried it
|
||||
# already.
|
||||
|
||||
[[ _matcher_num -gt 1 || "${#:-$PREFIX$SUFFIX}" -le 1 ]] && return 1
|
||||
|
||||
local _comp_correct _correct_expl comax cfgacc
|
||||
local curcontext="${curcontext}" oldcontext opm="$compstate[pattern_match]"
|
||||
|
||||
# We don't try correction if the string is too short.
|
||||
|
||||
[[ "${#:-$PREFIX$SUFFIX}" -le 1 ]] && return 1
|
||||
|
||||
[[ "$curcontext" != [^:]#:correct:* ]] &&
|
||||
curcontext="${curcontext/:[^:]#:/:approximate:}"
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ zstyle -s ":completion:${curcontext}:$1" group-name gname &&
|
|||
[[ -z "$gname" ]] && gname="$1"
|
||||
zstyle -s ":completion:${curcontext}:$1" matcher match &&
|
||||
opts=($opts -M "${(q)match}")
|
||||
[[ -n "$_comp_matcher" ]] && opts=($opts -M "${(q)_comp_matcher}")
|
||||
[[ -n "$_matcher" ]] && opts=($opts -M "${(q)_matcher}")
|
||||
|
||||
if zstyle -a ":completion:${curcontext}:$1" ignored-patterns _comp_ignore; then
|
||||
opts=( $opts -F _comp_ignore)
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
# the expansions done produce no result or do not change the original
|
||||
# word from the line.
|
||||
|
||||
[[ _matcher_num -gt 1 ]] && return 1
|
||||
|
||||
local exp word="$PREFIX$SUFFIX" sort expr expl subd suf=" "
|
||||
local curcontext="${curcontext/:[^:]#:/:expand:}"
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
# insert possible completions only after the list has been shown at
|
||||
# least once.
|
||||
|
||||
[[ _matcher_num -gt 1 ]] && return 1
|
||||
|
||||
local pre suf expr curcontext="${curcontext/:[^:]#:/:list:}"
|
||||
|
||||
# Get the strings to compare.
|
||||
|
|
|
@ -20,7 +20,8 @@ setopt localoptions nullglob rcexpandparam extendedglob
|
|||
unsetopt markdirs globsubst shwordsplit nounset ksharrays
|
||||
|
||||
local comp post ret=1 _compskip format _comp_ignore \
|
||||
_completers _completers_left _comp_matcher \
|
||||
_completers _completer _completer_num \
|
||||
_matchers _matcher _matcher_num \
|
||||
context state line opt_args val_args curcontext="$curcontext" \
|
||||
_last_nmatches=-1 _last_menu_style _def_menu_style _menu_style sel \
|
||||
_saved_exact="${compstate[exact]}" \
|
||||
|
@ -62,14 +63,22 @@ _last_menu_style=()
|
|||
# And now just call the completer functions defined.
|
||||
|
||||
_completers=( "$@" )
|
||||
_completers_left=( "$@" )
|
||||
_completer_num=1
|
||||
|
||||
for comp; do
|
||||
if "$comp"; then
|
||||
ret=0
|
||||
break;
|
||||
fi
|
||||
shift 1 _completers_left
|
||||
for _completer; do
|
||||
_matcher="${_completer[2,-1]}-${(M)#_completers[1,_completer_num]:#$_completer}"
|
||||
zstyle -a ":completion:${curcontext/::/:${_matcher}:}:" matcher-list _matchers ||
|
||||
_matchers=( '' )
|
||||
|
||||
_matcher_num=1
|
||||
for _matcher in "$_matchers[@]"; do
|
||||
if "$_completer"; then
|
||||
ret=0
|
||||
break 2
|
||||
fi
|
||||
(( _matcher_num++ ))
|
||||
done
|
||||
(( _completer_num++ ))
|
||||
done
|
||||
|
||||
if [[ $compstate[nmatches] -gt 1 ]]; then
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
# expand-or-complete function because otherwise the pattern will
|
||||
# be expanded using globbing.
|
||||
|
||||
[[ _matcher_num -gt 1 ]] && return 1
|
||||
|
||||
local tmp opm="$compstate[pattern_match]" ret=0 orig ins
|
||||
local curcontext="${curcontext/:[^:]#:/:match:}"
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#autoload
|
||||
|
||||
[[ _matcher_num -gt 1 ]] && return 1
|
||||
|
||||
local curcontext="${curcontext/:[^:]#:/:menu:}"
|
||||
|
||||
# This completer is an example showing how menucompletion can be
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#autoload
|
||||
|
||||
[[ _matcher_num -gt 1 ]] && return 1
|
||||
|
||||
local curcontext="${curcontext/:[^:]#:/:oldlist:}" list
|
||||
|
||||
zstyle -s ":completion:${curcontext}:" list list
|
||||
|
|
|
@ -4,10 +4,10 @@
|
|||
|
||||
[[ -n "$SUFFIX" ]] || return 1
|
||||
|
||||
local curcontext="${curcontext/:[^:]#:/:prefix-${(M)#${(@)_completers[1,-$#_completers_left]}:#_prefix}:}" comp i
|
||||
local curcontext="${curcontext/:[^:]#:/:prefix-${(M)#_completers[1,_completer_num]:#_prefix}:}" comp i
|
||||
|
||||
zstyle -a ":completion:${curcontext}:" completer comp ||
|
||||
comp=( "${(@)_completers[1,-${#_completers_left}-1][(R)_prefix,-1]}" )
|
||||
comp=( "${(@)_completers[1,_completer_num][(R)_prefix,-1]}" )
|
||||
|
||||
if zstyle -t ":completion:${curcontext}:" add-space; then
|
||||
ISUFFIX=" $SUFFIX"
|
||||
|
@ -16,14 +16,8 @@ else
|
|||
fi
|
||||
SUFFIX=''
|
||||
|
||||
local _completers _completer_left
|
||||
|
||||
_completers=( "$comp[@]" )
|
||||
_completers_left=( "$comp[@]" )
|
||||
|
||||
for i in "$comp[@]"; do
|
||||
[[ "$i" != _prefix ]] && "$i" && return 0
|
||||
shift 1 _completers_left
|
||||
done
|
||||
|
||||
return 1
|
||||
|
|
|
@ -1089,11 +1089,50 @@ matches as described in
|
|||
ifzman(the section `Matching Control' in zmanref(zshcompwid))\
|
||||
ifnzman(noderef(Matching Control))\
|
||||
.
|
||||
)
|
||||
item(tt(matcher-list))(
|
||||
This style is used by the main completion function to retrieve match
|
||||
specifications that are to be used everywhere. Its value should be a
|
||||
list of such specifications. The completion system will try them one
|
||||
after another for each completer selected. For example, to first try
|
||||
simple completion and, if that generates no matches, case-insensitive
|
||||
completion one would do:
|
||||
|
||||
This style is also used by the tt(_matcher) completer, see
|
||||
ifzman(the section `Control Functions' below)\
|
||||
ifnzman(noderef(Control Functions))
|
||||
for more information.
|
||||
example(zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}')
|
||||
|
||||
But the style allows even finer control: the style is looked up for
|
||||
every completer tried with the name of the completer (without the
|
||||
leading underscore) in the context name. For example, if one uses the
|
||||
completers tt(_complete) and tt(_prefix) and wants to try
|
||||
case-insensitive completion only when using the tt(_complete)
|
||||
completer, one would do:
|
||||
|
||||
example(zstyle ':completion:*' completer _complete _prefix
|
||||
zstyle ':completion:*:complete*:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}')
|
||||
|
||||
Note that there is no colon directly after the `tt(complete)'. That's
|
||||
because the completion system really uses the name of the completer
|
||||
followed by a minus sign and a number in the var(completer) field of
|
||||
the context name. This is useful if, for example, one wants to try
|
||||
normal completion without a match specification and with
|
||||
case-insensitive matching first, correction if that doesn't generate
|
||||
any matches and partial-word completion if that doesn't yield any
|
||||
matches either. In such a case one can give the tt(_complete)
|
||||
completer more than once in the tt(completer) style and give different
|
||||
match specification to them, as in:
|
||||
|
||||
example(zstyle ':completion:*' completer _complete _correct _complete
|
||||
zstyle ':completion:*:complete-1:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}'
|
||||
zstyle ':completion:*:complete-2:*' matcher-list \
|
||||
'm:{a-zA-Z}={A-Za-z} r:|[-_./]=* r:|=*')
|
||||
|
||||
Note that in any case an unset style makes the completion code use no
|
||||
global match specification. Also, some completers (like tt(_correct)
|
||||
and tt(_approximate)) do not use the match specifications. But even if
|
||||
such completers are used one can use the simple form to set this style
|
||||
(as in the first example above) because such completers will make sure
|
||||
that they are executed only once even if multiple match specifications
|
||||
have been given.
|
||||
)
|
||||
item(tt(max-errors))(
|
||||
This is used by the tt(_approximate) and tt(_correct) completer functions
|
||||
|
@ -1609,42 +1648,6 @@ could be generated that is at least as long as the original string.
|
|||
Note that the matcher specifications defined globally or used by the
|
||||
completion functions will not be used.
|
||||
)
|
||||
findex(_matcher)
|
||||
item(tt(_matcher))(
|
||||
This completer allows to define a match specification (see
|
||||
ifzman(the section `Matching Control' in zmanref(zshcompwid))\
|
||||
ifnzman(noderef(Matching Control))\
|
||||
) that is to be used by all following completers. This is comparable
|
||||
to the global match specifications that can be defined for the
|
||||
tt(compctl) builtin, but gives much better control. The match
|
||||
specification to use is looked up using the tt(matcher) style. For
|
||||
this, the completer field of the context name will contain the string
|
||||
`tt(matcher-)var(n)', where `var(n)' is the number of the call to
|
||||
tt(_matcher). For example:
|
||||
|
||||
example(zstyle ':completion:::::' completer _matcher _complete _matcher _complete
|
||||
zstyle ':completion:*:matcher-1:::' matcher 'm:{a-z-}={A-Z_}'
|
||||
zstyle ':completion:*:matcher-2:::' matcher 'm:{a-z-}={A-Z_}' 'r:|[-_./]=* r:|=*')
|
||||
|
||||
Since tt(_matcher) is called as the first completer, the tt(_complete)
|
||||
completer called after it will first use the match specification
|
||||
`tt(m:{a-z-}={A-Z_})'. If that doesn't generate any matches, the next
|
||||
call to tt(_matcher) will make the second call to tt(_complete) use
|
||||
the specification `tt(r:|[-_./]=* r:|=*)' in addition to the one
|
||||
already used by the first attempt (but note that the specification has
|
||||
to be given again).
|
||||
|
||||
If the tt(matcher) style is not set for one of the invocations of
|
||||
tt(_matcher), this has the same effect as setting it to the empty
|
||||
string: it makes the following completion function not use any match
|
||||
specifications besides those used by the functions themselves.
|
||||
|
||||
Note that currently only the tt(_complete) completer and the
|
||||
tt(_prefix) completer (if it has its own tt(completer) style
|
||||
containing tt(_complete)) use the match specifications, so one doesn't
|
||||
need to repeat all completers one wants to use after each call to
|
||||
tt(_matcher) in the completer list.
|
||||
)
|
||||
findex(_expand)
|
||||
item(tt(_expand))(
|
||||
This completer function does not really do completion, but instead
|
||||
|
|
Loading…
Reference in a new issue