Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: problem with _arguments exclusion lists
- X-seq: zsh-workers 14117
- From: Sven Wischnowsky <wischnow@xxxxxxxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: Re: problem with _arguments exclusion lists
- Date: Thu, 26 Apr 2001 16:35:23 +0200 (MET DST)
- In-reply-to: <3AE828D4.A2EC6AEE@xxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
Oliver Kiddle wrote:
> ...
>
> But if the word is empty, and the pattern matches, it does offer both
> message and options. I think this check should come before the
> _message and an empty $PREFIX$SUFFIX should prevent the failed return.
> Like this:
> [[ -n $PREFIX$SUFFIX && "$PREFIX$SUFFIX" != $~1 ]] && return 1
If we do that, no options will be completed after, e.g. `pine -c' (with
your patch), because then the action returned zero.
> The completion for vncserver (patch below) could use this so that it
> offers display numbers before the initial `:' is typed.
I admit that I never thought about using this in a normal-argument spec
(non-option-argument). Isn't that already covered enough by the normal
behaviour of _arguments? I.e., using some other action for that
argument that displays the message and handles the colon (I don't know
how this argument has to look like...).
> When, in the first message you say `the new behaviour of completing
> options if the action returns non-zero', I would have said that the
> behaviour was to be not claiming to complete the message when actions
> return non-zero so that completing other things, like options isn't
> blocked.
That part of the `behaviour' depends on whatever the action does,
obviously. And I think that the current behaviour of _guard is at least
a good default. As I said, we can give it an option to say what should
be done (returned) if the word is the empty string.
> > No, -w (now -W since I swapped them), makes it complete options
> > regardless of the return value of the action. What you're seeing
> > here
> > is the new default behaviour of trying to complete options if the
> > action returns non-zero.
>
> Oh. I thought it was going to not complete single letter options
> unless it had -W and -s and always complete long options. So how do I
> get _pine to work properly (use of _guard for _pine also in the
> patch):
>
> valid
> pine -cr4 produces an error message
>
> so pine -r<tab> offers other single letter options including -c pine
> -c<tab> should offer -conf, -character-set etc but not other single
> letter options like -r. It should also offer numbers.
[See? That last one... that's what you get with the current behaviour
of _guard and _arguments.]
> I thought the
> _arguments -W option was going to allow it to offer single letter
> options like -r for any command which allows options between an option
> and its argument where they are all in the same word. So -W wouldn't be
> used for pine and the -r option wouldn't be offered between -c and its
> number argument.
Ah, right. That makes sense. Patch below.
Bye
Sven
Index: Completion/Base/Utility/_arguments
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/Utility/_arguments,v
retrieving revision 1.4
diff -u -r1.4 _arguments
--- Completion/Base/Utility/_arguments 2001/04/26 12:13:37 1.4
+++ Completion/Base/Utility/_arguments 2001/04/26 14:34:38
@@ -182,7 +182,7 @@
-R) rawret=yes; shift;;
-w) optarg=yes; shift;;
-s) singopt=(-s); shift;;
- -W) alwopt=yes; shift;;
+ -W) alwopt=arg; shift;;
esac
done
@@ -282,7 +282,7 @@
eval ws\=\( "${action[3,-3]}" \)
_describe -t "$subc" "$descr" ws -M "$matcher" "$subopts[@]" ||
- alwopt=yes
+ alwopt=${alwopt:-yes}
tried=yes
elif [[ "$action" = \(*\) ]]; then
@@ -292,7 +292,7 @@
eval ws\=\( "${action[2,-2]}" \)
_all_labels "$subc" expl "$descr" compadd "$subopts[@]" -a - ws ||
- alwopt=yes
+ alwopt=${alwopt:-yes}
tried=yes
elif [[ "$action" = \{*\} ]]; then
@@ -301,7 +301,7 @@
while _next_label "$subc" expl "$descr"; do
eval "$action[2,-2]" && ret=0
done
- (( ret )) && alwopt=yes
+ (( ret )) && alwopt=${alwopt:-yes}
tried=yes
elif [[ "$action" = \ * ]]; then
@@ -311,7 +311,7 @@
while _next_label "$subc" expl "$descr"; do
"$action[@]" && ret=0
done
- (( ret )) && alwopt=yes
+ (( ret )) && alwopt=${alwopt:-yes}
tried=yes
else
@@ -321,7 +321,7 @@
while _next_label "$subc" expl "$descr"; do
"$action[1]" "$subopts[@]" "$expl[@]" "${(@)action[2,-1]}" && ret=0
done
- (( ret )) && alwopt=yes
+ (( ret )) && alwopt=${alwopt:-yes}
tried=yes
fi
fi
@@ -340,7 +340,8 @@
PREFIX="$origpre"
IPREFIX="$origipre"
- if comparguments -s single; then
+ if [[ -z "$alwopt" || -z "$tried" || "$alwopt" = arg ]] &&
+ comparguments -s single; then
if [[ "$single" = direct ]]; then
_all_labels options expl option \
Index: Doc/Zsh/compsys.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v
retrieving revision 1.119
diff -u -r1.119 compsys.yo
--- Doc/Zsh/compsys.yo 2001/04/26 13:03:24 1.119
+++ Doc/Zsh/compsys.yo 2001/04/26 14:34:41
@@ -2938,17 +2938,18 @@
normally not complete the other option directly after `tt(-a)', but it would
allow that if given the tt(-w) option.
-Similarly, the option tt(-W) may be given to force completion of options
-even after options that get an argument in the same word. For example,
-if a command takes the options `tt(a)' and `tt(b)', where `tt(a)' needs
-an argument in the same word, directly after the option character,
-tt(_arguments) would normally only execute the action for that argument
-and not offer other options as possible completions. If given the
-tt(-W) option, it will offer other options as possible completions after
-executing the action for the argument. Note that, depending on the
-action, this may mean that the other options can't really be completed,
-but at least they will be listed. For more control, use an utility
-function like tt(_guard) in the argument's action.
+Similarly, the option tt(-W) may be given together with tt(-s) to force
+completion of single-letter options even after options that get an
+argument in the same word. For example, if a command takes the options
+`tt(a)' and `tt(b)', where `tt(a)' needs an argument in the same word,
+directly after the option character, tt(_arguments) would normally only
+execute the action for that argument and not offer other single-letter
+options as possible completions. If given the tt(-W) option, it will
+offer other options as possible completions after executing the action
+for the argument. Note that, depending on the action, this may mean
+that the other options can't really be completed, but at least they will
+be listed. For more control, use an utility function like tt(_guard) in
+the argument's action.
The forms of var(optspec) are:
--
Sven Wischnowsky wischnow@xxxxxxxxxxxxxxxxxxxxxxx
Messages sorted by:
Reverse Date,
Date,
Thread,
Author