Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PATCH: completion
- X-seq: zsh-workers 7460
- From: Tanaka Akira <akr@xxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxx
- Subject: Re: PATCH: completion
- Date: 21 Aug 1999 17:39:17 +0900
- In-reply-to: Tanaka Akira's message of "21 Aug 1999 08:22:55 +0900"
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
- References: <199908201259.OAA00799@xxxxxxxxxxxxxxxxxxxxxxxxxxxx> <rsq672a11gw.fsf@xxxxxxxxxxxxxxxxx>
In article <rsq672a11gw.fsf@xxxxxxxxxxxxxxxxx>,
Tanaka Akira <akr@xxxxxxxxxxx> writes:
> But, in general, help messages may not able to modify. Therefore I
> think it is useful that _arguments can handle options started with
> "--".
Oops. I found that already _arguments can handle options started with
"--" without _long_options. But also I fount that it is bit
problematic with -s.
Z(2):akr@is27e1u11% ./Src/zsh -f
is27e1u11% bindkey -e ; autoload -U compinit; compinit -D; compdef _tst tst
compconf group_matches=yes
compconf message_format='%d'
compconf description_format='%d'
is27e1u11% compconf group_matches=yes
is27e1u11% compconf message_format='%d'
is27e1u11% compconf description_format='%d'
is27e1u11% _tst () { _arguments -s '-a' '-b' '--xxx=-:descr:(a b c)' '--yyy=-:descr:(z y x)' }
is27e1u11% tst -a<TAB>
option
-a -a-xxx\= -a-yyy\= -ab
etc.
Index: Completion/Base/_arguments
===================================================================
RCS file: /projects/zsh/zsh/Completion/Base/_arguments,v
retrieving revision 1.1.1.5
diff -u -F^( -r1.1.1.5 _arguments
--- _arguments 1999/08/20 23:24:13 1.1.1.5
+++ _arguments 1999/08/21 08:32:36
@@ -6,7 +6,7 @@
setopt localoptions extendedglob
local long args rest ws cur nth def nm expl descr action opt arg tmp
-local single uns ret=1
+local single uns ret=1 soptseq soptseq1 sopts
# Associative arrays used to collect information about the options.
@@ -90,6 +90,22 @@
shift
done
+if [[ -n "$single" ]]; then
+ soptseq="${(@j::)${(@M)${(@k)opts[(R)]}:#[-+]?}#[-+]}${(@j::)${(@M)${(@k)mopts[(R)]}:#[-+]?}#[-+]}"
+ if [[ -n "$soptseq" ]]; then
+ soptseq="[$soptseq]#"
+ soptseq1="$soptseq#"
+ else
+ soptseq=''
+ soptseq1=''
+ fi
+ sopts="${(@j::)${(@M)${(@k)opts}:#[-+]?}#[-+]}${(@j::)${(@M)${(@k)mopts}:#[-+]?}#[-+]}${(@j::)${(@M)${(@k)dopts}:#[-+]?}#[-+]}${(@j::)${(@M)${(@k)dmopts}:#[-+]?}#[-+]}${(@j::)${(@M)${(@k)odopts}:#[-+]?}#[-+]}${(@j::)${(@M)${(@k)odmopts}:#[-+]?}#[-+]}"
+else
+ soptseq=''
+ soptseq1=''
+ sopts=''
+fi
+
if [[ $#long -ne 0 && "$PREFIX" = --* ]]; then
# If the current words starts with `--' and we should use long
@@ -157,19 +173,17 @@
def="$mopts[$ws[1]]"
else
uns=''
- if [[ -n "$single" && "$ws[1]" = [-+]* ]]; then
- if [[ ${#${(kj::)opts[(R)?*]#?}} -ne 0 &&
- "$ws[1]" = ${ws[1][1]}*[${(kj::)opts[(R)?*]#?}] ]]; then
+ if [[ -n "$sopts" && "$ws[1]" = [-+]${~soptseq}[$sopts] ]]; then
+ if (( $+opts[${ws[1][1]}${ws[1][-1]}] )); then
def="$opts[${ws[1][1]}${ws[1][-1]}]"
uns="${ws[1][2,-1]}"
opt=''
- elif [[ ${#${(kj::)mopts[(R)?*]#?}} -ne 0 &&
- "$ws[1]" = ${ws[1][1]}*[${(kj::)mopts[(R)?*]#?}] ]]; then
+ elif (( $+mopts[${ws[1][1]}${ws[1][-1]}] )); then
def="$mopts[${ws[1][1]}${ws[1][-1]}]"
uns="${ws[1][2,-1]}"
opt=''
fi
- fi
+ fi
# If the word is none of the simple options, test for those
# whose first argument has to or may come directly after the
@@ -185,8 +199,8 @@
# with one of the option names.
while (( $#tmp )); do
- if [[ -n "$single" ]]; then
- if [[ "$ws[1]" = ${tmp[1][1]}*${tmp[1][2]}* ]]; then
+ if [[ -n "$sopts" && $tmp[1] = [-+]? ]]; then
+ if [[ "$ws[1]" = ${tmp[1][1]}${~soptseq}${tmp[1][2]}* ]]; then
uns="${ws[1][2,-1]%%${tmp[1][2]}*}${tmp[1][2]}"
break;
fi
@@ -204,7 +218,7 @@
opt=''
def="$dopts[$tmp[1]]"
- [[ -z "$single" ]] && unset "dopts[$tmp[1]]"
+ unset "dopts[$tmp[1]]"
if [[ "$def" = ?*:*:* ]]; then
def="${def#?*:*:}"
else
@@ -215,8 +229,8 @@
if [[ -n "$opt" && $#dmopts -ne 0 ]]; then
tmp=( "${(@k)dmopts}" )
while (( $#tmp )); do
- if [[ -n "$single" ]]; then
- if [[ "$ws[1]" = ${tmp[1][1]}*${tmp[1][2]}* ]]; then
+ if [[ -n "$sopts" && $tmp[1] = [-+]? ]]; then
+ if [[ "$ws[1]" = ${tmp[1][1]}${~soptseq}${tmp[1][2]}* ]]; then
uns="${ws[1][2,-1]%%${tmp[1][2]}*}${tmp[1][2]}"
break;
fi
@@ -239,8 +253,8 @@
if [[ -n "$opt" && $#odopts -ne 0 ]]; then
tmp=( "${(@k)odopts}" )
while (( $#tmp )); do
- if [[ -n "$single" ]]; then
- if [[ "$ws[1]" = ${tmp[1][1]}*${tmp[1][2]}* ]]; then
+ if [[ -n "$sopts" && $tmp[1] = [-+]? ]]; then
+ if [[ "$ws[1]" = ${tmp[1][1]}${~soptseq}${tmp[1][2]}* ]]; then
uns="${ws[1][2,-1]%%${tmp[1][2]}*}${tmp[1][2]}"
break;
fi
@@ -253,14 +267,14 @@
if (( $#tmp )); then
opt=''
def="$odopts[$tmp[1]]"
- [[ -z "$single" ]] && unset "odopts[$tmp[1]]"
+ unset "odopts[$tmp[1]]"
# For options whose first argument *may* come after the
# option, we skip over the first description only if there
# is something after the option name on the line.
- if [[ ( -z "$single" && "$ws[1]" != "$tmp[1]" ) ||
- ( -n "$single" && "$ws[1]" != *${tmp[1][2]} ) ]]; then
+ if [[ ( -z "$sopts" && "$ws[1]" != "$tmp[1]" ) ||
+ ( -n "$sopts" && $tmp[1] = [-+]? && "$ws[1]" != ${tmp[1][1]}${~soptseq}${tmp[1][2]} ) ]]; then
if [[ "$def" = ?*:*:* ]]; then
def="${def#?*:*:}"
else
@@ -272,8 +286,8 @@
if [[ -n "$opt" && $#odmopts -ne 0 ]]; then
tmp=( "${(@k)odmopts}" )
while (( $#tmp )); do
- if [[ -n "$single" ]]; then
- if [[ "$ws[1]" = ${tmp[1][1]}*${tmp[1][2]}* ]]; then
+ if [[ -n "$sopts" && $tmp[1] = [-+]? ]]; then
+ if [[ "$ws[1]" = ${tmp[1][1]}${~soptseq}${tmp[1][2]}* ]]; then
uns="${ws[1][2,-1]%%${tmp[1][2]}*}${tmp[1][2]}"
break;
fi
@@ -286,8 +300,8 @@
if (( $#tmp )); then
opt=''
def="$odmopts[$tmp[1]]"
- if [[ ( -z "$single" && "$ws[1]" != "$tmp[1]" ) ||
- ( -n "$single" && "$ws[1]" != *${tmp[1][2]} ) ]]; then
+ if [[ ( -z "$sopts" && "$ws[1]" != "$tmp[1]" ) ||
+ ( -n "$sopts" && $tmp[1] = [-+]? && "$ws[1]" != ${tmp[1][1]}${~soptseq}${tmp[1][2]} ) ]]; then
if [[ "$def" = ?*:*:* ]]; then
def="${def#?*:*:}"
else
@@ -297,7 +311,7 @@
fi
fi
- [[ -n "$single" && -n "$opt" && "$ws[1]" = [-+]* ]] && \
+ [[ -n "$sopts" && -n "$opt" && "$ws[1]" = [-+]${~soptseq} ]] && \
uns="${ws[1][2,-1]}"
[[ -n "$uns" ]] &&
@@ -351,7 +365,7 @@
tmp=( "${(@k)dopts}" )
while (( $#tmp )); do
- if [[ -n "$single" ]] && compset -P "${tmp[1][1]}*${tmp[1][2]}"; then
+ if [[ -n "$sopts" && $tmp[1] = [-+]? ]] && compset -P "${tmp[1][1]}${~soptseq}${tmp[1][2]}"; then
def="$dopts[$tmp[1]]"
opt=''
uns="${PREFIX[2,-1]%%${tmp[1][2]}*}${tmp[1][2]}"
@@ -371,7 +385,7 @@
if [[ -n "$opt" && $#dmopts -ne 0 ]]; then
tmp=( "${(@k)dmopts}" )
while (( $#tmp )); do
- if [[ -n "$single" ]] && compset -P "${tmp[1][1]}*${tmp[1][2]}"; then
+ if [[ -n "$sopts" && $tmp[1] = [-+]? ]] && compset -P "${tmp[1][1]}${~soptseq}${tmp[1][2]}"; then
def="$dmopts[$tmp[1]]"
opt=''
uns="${PREFIX[2,-1]%%${tmp[1][2]}*}${tmp[1][2]}"
@@ -387,7 +401,7 @@
if [[ -n "$opt" && $#odopts -ne 0 ]]; then
tmp=( "${(@k)odopts}" )
while (( $#tmp )); do
- if [[ -n "$single" ]] && compset -P "${tmp[1][1]}*${tmp[1][2]}"; then
+ if [[ -n "$sopts" && $tmp[1] = [-+]? ]] && compset -P "${tmp[1][1]}${~soptseq}${tmp[1][2]}"; then
def="$odopts[$tmp[1]]"
opt=''
uns="${PREFIX[2,-1]%%${tmp[1][2]}*}${tmp[1][2]}"
@@ -403,7 +417,7 @@
if [[ -n "$opt" && $#odmopts -ne 0 ]]; then
tmp=( "${(@k)odmopts}" )
while (( $#tmp )); do
- if [[ -n "$single" ]] && compset -P "${tmp[1][1]}*${tmp[1][2]}"; then
+ if [[ -n "$sopts" && $tmp[1] = [-+]? ]] && compset -P "${tmp[1][1]}${~soptseq}${tmp[1][2]}"; then
def="$odmopts[$tmp[1]]"
opt=''
uns="${PREFIX[2,-1]%%${tmp[1][2]}*}${tmp[1][2]}"
@@ -417,7 +431,7 @@
done
fi
- [[ -n "$single" && -n "$opt" && "$PREFIX" = [-+]* ]] && \
+ [[ -n "$sopts" && -n "$opt" && "$PREFIX" = [-+]* ]] && \
uns="${PREFIX[2,-1]}"
[[ -n "$uns" ]] &&
@@ -433,25 +447,12 @@
if [[ "$compconfig[option_prefix]" != *(short|all)* ||
"$PREFIX" = [-+]* ]]; then
_description expl option
- if [[ -n "$single" ]]; then
- if [[ -z "$PREFIX" || "$PREFIX" = ? ]]; then
- compadd "$expl[@]" - "${(@k)opts}" "${(@k)mopts}" \
- "${(@k)dopts}" "${(@k)dmopts}" \
- "${(@k)odopts}" "${(@k)odmopts}" &&
- ret=0
- else
- compadd "$expl[@]" - "${PREFIX}${(@k)^opts[(I)${PREFIX[1]}*]#?}" \
- "${PREFIX}${(@k)^mopts[(I)${PREFIX[1]}*]#?}" \
- "${PREFIX}${(@k)^dopts[(I)${PREFIX[1]}*]#?}" \
- "${PREFIX}${(@k)^dmopts[(I)${PREFIX[1]}*]#?}" \
- "${PREFIX}${(@k)^odopts[(I)${PREFIX[1]}*]#?}" \
- "${PREFIX}${(@k)^odmopts[(I)${PREFIX[1]}*]#?}" &&
- ret=0
- fi
+ if [[ -n "$sopts" && -n "$PREFIX" && -n "$soptseq" && "$PREFIX" = [-+]${~soptseq1} ]]; then
+ compadd "$expl[@]" -Q - "$PREFIX" && ret=0
else
- compadd "$expl[@]" - "${(@k)opts}" "${(@k)mopts}" \
- "${(@k)dopts}" "${(@k)dmopts}" \
- "${(@k)odopts}" "${(@k)odmopts}" && ret=0
+ compadd "$expl[@]" -Q - "${(@k)opts}" "${(@k)mopts}" \
+ "${(@k)odopts}" "${(@k)odmopts}" && ret=0
+ compadd "$expl[@]" -QS '' - "${(@k)dopts}" "${(@k)dmopts}" && ret=0
fi
fi
[[ $#long -ne 0 &&
Index: Completion/User/_patch
===================================================================
RCS file: /projects/zsh/zsh/Completion/User/_patch,v
retrieving revision 1.1.1.1
diff -u -F^( -r1.1.1.1 _patch
--- _patch 1999/08/20 23:55:52 1.1.1.1
+++ _patch 1999/08/21 08:35:32
@@ -12,7 +12,7 @@
'-b' \
'-V+:version control style:(simple numbered existing)' \
'-B+:backup path prefix:' \
- '-Y+:basename basename prefix:_files' \
+ '-Y+:backup basename prefix:_files' \
'-z+:backup file suffix:(.bak)' \
'-g+:NUM:' \
'-t' '-f' '-s' \
--
Tanaka Akira
Messages sorted by:
Reverse Date,
Date,
Thread,
Author