Subject: Re: typeset completion with arguments after cursor
From: Oliver Kiddle <[email-masked]>
To: zsh workers <[email-masked]>
Date: Thu, 11 Aug 2016 21:34:58 +0200
List-Id: Zsh Workers List <zsh-workers.zsh.org>

Mikael Magnusson wrote:
> When you do this
> typeset -<tab> a
> it just completes an equal sign, instead of the correct options.
> Without the `a` present it works fine, but I'm not sure what is
> missing from the completion to make this work correctly, and it seems
> to use some extra magic than usual as well. "This function uses whacky
> features of _arguments"

This is a bug in the way the -A option is handled. It is trying the
pattern against all arguments. So the "a" argument doesn't match "-A" and
it disables all option completion. This patch prevents the pattern check for
arguments preceding (and including) the one we are currently completing.

I'm resending this message as it didn't come through from the list first
time. Sorry if it now arrives twice.

Oliver

diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c
index 0028ac1..ecfa2bc 100644
--- a/Src/Zle/computil.c
+++ b/Src/Zle/computil.c
@@ -2167,9 +2167,11 @@ ca_parse_line(Cadef d, int multi, int first)
 #endif
 		   )
 	    return 1;
-	else if (state.arg && (!napat || !pattry(napat, line))) {
+	else if (state.arg &&
+		 (!napat || cur <= compcurrent || !pattry(napat, line))) {
 	    /* Otherwise it's a normal argument. */
-	    if (napat && ca_inactive(d, NULL, cur + 1, 1, NULL))
+	    if (napat && cur <= compcurrent &&
+		    ca_inactive(d, NULL, cur + 1, 1, NULL))
 		return 1;
 
 	    arglast = 1;