From: Sven Wischnowsky <wischnow@informatik.hu-berlin.de>
To: zsh-workers@sunsite.auc.dk
Subject: Re: PATCH: completion
Date: Fri, 20 Aug 1999 14:59:20 +0200 (MET DST) [thread overview]
Message-ID: <199908201259.OAA00799@beta.informatik.hu-berlin.de> (raw)
In-Reply-To: Tanaka Akira's message of 19 Aug 1999 23:38:50 +0900
Tanaka Akira wrote:
> I feel `_arguments' is very good as basis of that. Is it easy to
> extend `_arguments' to handle short options?
Not that easy and some people probably don't like the way option names
are completed with this patch, but still...
I haven't changed `_cvs' (btw., maybe this should be split into
smaller functions and put in its own directory?).
Bye
Sven
diff -u od/Zsh/compsys.yo Doc/Zsh/compsys.yo
--- od/Zsh/compsys.yo Fri Aug 20 14:33:55 1999
+++ Doc/Zsh/compsys.yo Fri Aug 20 14:31:11 1999
@@ -939,12 +939,18 @@
builtins and which make sure that the var(message) given in the
description will be shown above the matches.
-Finally, this function can be made to automatically call the
+Normally the option names are taken as multi-character names and a
+word from the line is considered to contain only one option (or
+none). By giving the tt(-s) option to this function (as the first
+argument), options are considered to be one-character options and the
+string from the line may contain more than one such option letter.
+
+This function can also be made to automatically call the
tt(_long_options) function where appropriate by giving it the string
`tt(--)' as an argument. All arguments after this will be given
unchanged to the tt(_long_options) function.
-This function also uses one configuration key: tt(option_prefix). If
+Finally, this function uses one configuration key: tt(option_prefix). If
this is set to a string containing `tt(short)' or `tt(all)' as a
substring, option names beginning with a single minus sign are added
as possible matches only if the word on the line begins with a minus
diff -u -r oc/Base/_arguments Completion/Base/_arguments
--- oc/Base/_arguments Fri Aug 20 14:33:55 1999
+++ Completion/Base/_arguments Fri Aug 20 13:32:59 1999
@@ -5,12 +5,20 @@
setopt localoptions extendedglob
-local long args rest ws cur nth def nm expl descr action opt arg tmp ret=1
+local long args rest ws cur nth def nm expl descr action opt arg tmp
+local single uns ret=1
# Associative arrays used to collect information about the options.
typeset -A opts mopts dopts dmopts odopts odmopts
+# See if we are using single-letter options.
+
+if [[ "$1" = -s ]]; then
+ shift
+ single=yes
+fi
+
# See if we support long options, too.
nth=$argv[(I)--]
@@ -141,19 +149,33 @@
if (( $+opts[$ws[1]] )); then
# Options that may only be given once are removed from the
- # associative array so that we are not offered them again.
+ # associative array so that we don't offer them again.
def="$opts[$ws[1]]"
unset "opts[$ws[1]]"
elif (( $+mopts[$ws[1]] )); then
def="$mopts[$ws[1]]"
else
+ uns=''
+ if [[ -n "$single" && "$ws[1]" = [-+]* ]]; then
+ if [[ $#opts -ne 0 &&
+ "$ws[1]" = ${ws[1][1]}*[${(kj::)opts[(R)?*]#?}] ]]; then
+ def="$opts[${ws[1][1]}${ws[1][-1]}]"
+ uns="${ws[1][2,-1]}"
+ opt=''
+ elif [[ $#mopts -ne 0 &&
+ "$ws[1]" = ${ws[1][1]}*[${(kj::)mopts[(R)?*]#?}] ]]; then
+ def="$mopts[${ws[1][1]}${ws[1][-1]}]"
+ uns="${ws[1][2,-1]}"
+ opt=''
+ 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
# option. This is done in four loops looking very much alike.
- if (( $#dopts )); then
+ if [[ -n "$opt" && $#dopts -ne 0 ]]; then
# First we get the option names.
@@ -163,7 +185,14 @@
# with one of the option names.
while (( $#tmp )); do
- [[ "$ws[1]" = ${tmp[1]}* ]] && break
+ if [[ -n "$single" ]]; then
+ if [[ "$ws[1]" = ${tmp[1][1]}*${tmp[1][2]}* ]]; then
+ uns="${ws[1][2,-1]%%${tmp[1][2]}*}${tmp[1][2]}"
+ break;
+ fi
+ elif [[ "$ws[1]" = ${tmp[1]}* ]]; then
+ break
+ fi
shift 1 tmp
done
@@ -175,7 +204,7 @@
opt=''
def="$dopts[$tmp[1]]"
- unset "dopts[$tmp[1]]"
+ [[ -z "$single" ]] && unset "dopts[$tmp[1]]"
if [[ "$def" = ?*:*:* ]]; then
def="${def#?*:*:}"
else
@@ -186,7 +215,14 @@
if [[ -n "$opt" && $#dmopts -ne 0 ]]; then
tmp=( "${(@k)dmopts}" )
while (( $#tmp )); do
- [[ "$ws[1]" = ${tmp[1]}* ]] && break
+ if [[ -n "$single" ]]; then
+ if [[ "$ws[1]" = ${tmp[1][1]}*${tmp[1][2]}* ]]; then
+ uns="${ws[1][2,-1]%%${tmp[1][2]}*}${tmp[1][2]}"
+ break;
+ fi
+ elif [[ "$ws[1]" = ${tmp[1]}* ]]; then
+ break
+ fi
shift 1 tmp
done
@@ -203,20 +239,28 @@
if [[ -n "$opt" && $#odopts -ne 0 ]]; then
tmp=( "${(@k)odopts}" )
while (( $#tmp )); do
- [[ "$ws[1]" = ${tmp[1]}* ]] && break
+ if [[ -n "$single" ]]; then
+ if [[ "$ws[1]" = ${tmp[1][1]}*${tmp[1][2]}* ]]; then
+ uns="${ws[1][2,-1]%%${tmp[1][2]}*}${tmp[1][2]}"
+ break;
+ fi
+ elif [[ "$ws[1]" = ${tmp[1]}* ]]; then
+ break
+ fi
shift 1 tmp
done
if (( $#tmp )); then
opt=''
def="$odopts[$tmp[1]]"
- unset "odopts[$tmp[1]]"
+ [[ -z "$single" ]] && 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 [[ "$ws[1]" != "$tmp[1]" ]]; then
+ if [[ ( -z "$single" && "$ws[1]" != "$tmp[1]" ) ||
+ ( -n "$single" && "$ws[1]" != *${tmp[1][2]} ) ]]; then
if [[ "$def" = ?*:*:* ]]; then
def="${def#?*:*:}"
else
@@ -228,14 +272,22 @@
if [[ -n "$opt" && $#odmopts -ne 0 ]]; then
tmp=( "${(@k)odmopts}" )
while (( $#tmp )); do
- [[ "$ws[1]" = ${tmp[1]}* ]] && break
+ if [[ -n "$single" ]]; then
+ if [[ "$ws[1]" = ${tmp[1][1]}*${tmp[1][2]}* ]]; then
+ uns="${ws[1][2,-1]%%${tmp[1][2]}*}${tmp[1][2]}"
+ break;
+ fi
+ elif [[ "$ws[1]" = ${tmp[1]}* ]]; then
+ break
+ fi
shift 1 tmp
done
if (( $#tmp )); then
opt=''
def="$odmopts[$tmp[1]]"
- if [[ "$ws[1]" != "$tmp[1]" ]]; then
+ if [[ ( -z "$single" && "$ws[1]" != "$tmp[1]" ) ||
+ ( -n "$single" && "$ws[1]" != *${tmp[1][2]} ) ]]; then
if [[ "$def" = ?*:*:* ]]; then
def="${def#?*:*:}"
else
@@ -245,6 +297,14 @@
fi
fi
+ [[ -n "$single" && -n "$opt" && "$ws[1]" = [-+]* ]] && \
+ uns="${ws[1][2,-1]}"
+
+ [[ -n "$uns" ]] &&
+ unset "opts[${(@)^opts[(I)${ws[1][1]}[$uns]]}]" \
+ "dopts[${(@)^dopts[(I)${ws[1][1]}[$uns]]}]" \
+ "odopts[${(@)^odopts[(I)${ws[1][1]}[$uns]]}]"
+
# If we didn't find a matching option description and we were
# told to use normal argument descriptions, just increase
# our counter `nth'.
@@ -265,6 +325,9 @@
nm="$compstate[nmatches]"
if [[ -z "$def" || "$def" = :* ]]; then
+ local pre="$PREFIX"
+
+ uns=''
# We either don't have a description for an argument of an option
# or we have a description for a optional argument.
@@ -288,7 +351,12 @@
tmp=( "${(@k)dopts}" )
while (( $#tmp )); do
- if compset -P "$tmp[1]"; then
+ if [[ -n "$single" ]] && compset -P "${tmp[1][1]}*${tmp[1][2]}"; then
+ def="$dopts[$tmp[1]]"
+ opt=''
+ uns="${PREFIX[2,-1]%%${tmp[1][2]}*}${tmp[1][2]}"
+ break
+ elif compset -P "$tmp[1]"; then
# The current string starts with the option name, so ignore
# that and complete the rest of the string.
@@ -303,7 +371,12 @@
if [[ -n "$opt" && $#dmopts -ne 0 ]]; then
tmp=( "${(@k)dmopts}" )
while (( $#tmp )); do
- if compset -P "$tmp[1]"; then
+ if [[ -n "$single" ]] && compset -P "${tmp[1][1]}*${tmp[1][2]}"; then
+ def="$dmopts[$tmp[1]]"
+ opt=''
+ uns="${PREFIX[2,-1]%%${tmp[1][2]}*}${tmp[1][2]}"
+ break
+ elif compset -P "$tmp[1]"; then
def="$dmopts[$tmp[1]]"
opt=''
break
@@ -314,7 +387,12 @@
if [[ -n "$opt" && $#odopts -ne 0 ]]; then
tmp=( "${(@k)odopts}" )
while (( $#tmp )); do
- if compset -P "$tmp[1]"; then
+ if [[ -n "$single" ]] && compset -P "${tmp[1][1]}*${tmp[1][2]}"; then
+ def="$odopts[$tmp[1]]"
+ opt=''
+ uns="${PREFIX[2,-1]%%${tmp[1][2]}*}${tmp[1][2]}"
+ break
+ elif compset -P "$tmp[1]"; then
def="$odopts[$tmp[1]]"
opt=''
break
@@ -325,7 +403,12 @@
if [[ -n "$opt" && $#odmopts -ne 0 ]]; then
tmp=( "${(@k)odmopts}" )
while (( $#tmp )); do
- if compset -P "$tmp[1]"; then
+ if [[ -n "$single" ]] && compset -P "${tmp[1][1]}*${tmp[1][2]}"; then
+ def="$odmopts[$tmp[1]]"
+ opt=''
+ uns="${PREFIX[2,-1]%%${tmp[1][2]}*}${tmp[1][2]}"
+ break
+ elif compset -P "$tmp[1]"; then
def="$odmopts[$tmp[1]]"
opt=''
break
@@ -333,17 +416,43 @@
shift 1 tmp
done
fi
+
+ [[ -n "$single" && -n "$opt" && "$PREFIX" = [-+]* ]] && \
+ uns="${PREFIX[2,-1]}"
+
+ [[ -n "$uns" ]] &&
+ unset "opts[${(@)^opts[(I)${pre[1]}[$uns]]}]" \
+ "dopts[${(@)^dopts[(I)${pre[1]}[$uns]]}]" \
+ "odopts[${(@)^odopts[(I)${pre[1]}[$uns]]}]"
+
if [[ -n "$opt" ]]; then
# We aren't in an argument directly after a option name, so
# all option names are possible matches.
if [[ "$compconfig[option_prefix]" != *(short|all)* ||
- "$PREFIX" = -* ]]; then
+ "$PREFIX" = [-+]* ]]; then
_description expl option
- compadd "$expl[@]" - "${(@k)opts}" "${(@k)mopts}" \
- "${(@k)dopts}" "${(@k)dmopts}" \
- "${(@k)odopts}" "${(@k)odmopts}" && ret=0
+ 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
+ else
+ compadd "$expl[@]" - "${(@k)opts}" "${(@k)mopts}" \
+ "${(@k)dopts}" "${(@k)dmopts}" \
+ "${(@k)odopts}" "${(@k)odmopts}" && ret=0
+ fi
fi
[[ $#long -ne 0 &&
( "$compconfig[option_prefix]" != *(long|all)* ||
--
Sven Wischnowsky wischnow@informatik.hu-berlin.de
next reply other threads:[~1999-08-20 12:59 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-08-20 12:59 Sven Wischnowsky [this message]
1999-08-20 23:22 ` Tanaka Akira
1999-08-21 8:39 ` Tanaka Akira
1999-08-21 17:47 ` Tanaka Akira
-- strict thread matches above, loose matches on Subject: below --
2000-02-21 9:50 Sven Wischnowsky
1999-10-28 8:12 Sven Wischnowsky
1999-10-28 6:58 Sven Wischnowsky
1999-10-27 8:42 Sven Wischnowsky
1999-10-27 16:39 ` Bart Schaefer
1999-10-27 7:14 Sven Wischnowsky
1999-10-27 21:26 ` Tanaka Akira
1999-10-26 13:17 Sven Wischnowsky
1999-10-26 13:01 Oliver Kiddle
1999-10-26 13:35 ` Zefram
1999-10-26 11:03 Sven Wischnowsky
1999-10-26 17:17 ` Bart Schaefer
1999-10-26 17:22 ` Tanaka Akira
1999-10-26 17:32 ` Tanaka Akira
1999-08-30 9:30 Sven Wischnowsky
1999-08-27 7:03 Sven Wischnowsky
1999-08-27 8:29 ` Tanaka Akira
1999-08-28 6:01 ` Tanaka Akira
1999-08-26 13:52 Sven Wischnowsky
1999-08-26 12:20 Sven Wischnowsky
1999-08-26 13:17 ` Tanaka Akira
1999-08-26 17:56 ` Tanaka Akira
1999-08-25 12:57 Sven Wischnowsky
1999-08-25 12:54 Sven Wischnowsky
1999-08-25 8:24 Sven Wischnowsky
1999-08-26 10:54 ` Tanaka Akira
1999-08-24 10:43 Sven Wischnowsky
1999-08-25 1:56 ` Tanaka Akira
1999-08-24 9:12 Sven Wischnowsky
1999-08-24 10:04 ` Tanaka Akira
1999-08-23 13:46 Sven Wischnowsky
1999-08-23 16:16 ` Tanaka Akira
1999-08-24 15:56 ` Tanaka Akira
1999-08-23 12:00 Sven Wischnowsky
1999-08-23 9:32 Sven Wischnowsky
1999-08-23 10:54 ` Tanaka Akira
1999-08-20 7:42 Sven Wischnowsky
1999-08-19 13:59 Sven Wischnowsky
1999-08-19 10:44 Sven Wischnowsky
1999-08-19 14:38 ` Tanaka Akira
1999-08-24 13:46 ` Peter Stephenson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=199908201259.OAA00799@beta.informatik.hu-berlin.de \
--to=wischnow@informatik.hu-berlin.de \
--cc=zsh-workers@sunsite.auc.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).