about summary refs log tree commit diff
path: root/Src/Zle
diff options
context:
space:
mode:
authorOliver Kiddle <opk@zsh.org>2017-01-04 14:50:56 +0100
committerOliver Kiddle <opk@zsh.org>2017-01-04 14:50:56 +0100
commit8be732cbcc248abfa82ee1b4d0031f684e79aa8b (patch)
tree3b48189e1d637fbce77bc2471e6d31b804620228 /Src/Zle
parenta69b19d215798c7cfd89a307abd959fb970dd679 (diff)
downloadzsh-8be732cbcc248abfa82ee1b4d0031f684e79aa8b.tar.gz
zsh-8be732cbcc248abfa82ee1b4d0031f684e79aa8b.tar.xz
zsh-8be732cbcc248abfa82ee1b4d0031f684e79aa8b.zip
40227: handle _arguments sets and rest arguments starting with a dash
This is a new approach to the problem first covered by 39611: checking
to see if an option-like argument belongs to one of the other sets.
Diffstat (limited to 'Src/Zle')
-rw-r--r--Src/Zle/computil.c37
1 files changed, 26 insertions, 11 deletions
diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c
index cc879c445..82144656d 100644
--- a/Src/Zle/computil.c
+++ b/Src/Zle/computil.c
@@ -1741,6 +1741,27 @@ ca_get_sopt(Cadef d, char *line, char **end, LinkList *lp)
     return pp;
 }
 
+/* Search for an option in all sets except the current one.
+ * Return true if found */
+
+static int
+ca_foreign_opt(Cadef curset, Cadef all, char *option)
+{
+    Cadef d;
+    Caopt p;
+
+    for (d = all; d; d = d->snext) {
+	if (d == curset)
+	    continue;
+
+	for (p = d->opts; p; p = p->next) {
+	    if (!strcmp(p->name, option))
+		return 1;
+	}
+    }
+    return 0;
+}
+
 /* Return the n'th argument definition. */
 
 static Caarg
@@ -1917,7 +1938,7 @@ ca_opt_arg(Caopt opt, char *line)
  * existing options on the line. */
 
 static int
-ca_parse_line(Cadef d, int multi, int first)
+ca_parse_line(Cadef d, Cadef all, int multi, int first)
 {
     Caarg adef, ddef;
     Caopt ptr, wasopt = NULL, dopt;
@@ -2163,13 +2184,7 @@ ca_parse_line(Cadef d, int multi, int first)
 	    else
 		state.curopt = NULL;
 	} else if (multi && (*line == '-' || *line == '+') && cur != compcurrent
-#if 0
-		   /**** Ouch. Using this will disable the mutual exclusion
-			 of different sets. Not using it will make the -A
-			 pattern be effectively ignored with multiple sets. */
-		   && (!napat || !pattry(napat, line))
-#endif
-		   )
+		&& (ca_foreign_opt(d, all, line)))
 	    return 1;
 	else if (state.arg &&
 		 (!napat || cur <= compcurrent || !pattry(napat, line))) {
@@ -2515,20 +2530,20 @@ bin_comparguments(char *nam, char **args, UNUSED(Options ops), UNUSED(int func))
          * auto-description string, the optional -s, -S, -A and -M options
          * given to _arguments and the specs. */
 	if (compcurrent > 1 && compwords[0]) {
-	    Cadef def;
+	    Cadef def, all;
 	    int cap = ca_parsed, multi, first = 1, use, ret = 0;
 	    Castate states = NULL, sp;
 
 	    ca_parsed = 0;
 
-	    if (!(def = get_cadef(nam, args + 1)))
+	    if (!(def = all = get_cadef(nam, args + 1)))
 		return 1;
 
 	    multi = !!def->snext; /* if we have sets */
 	    ca_parsed = cap;
 
 	    while (def) { /* for each set */
-		use = !ca_parse_line(def, multi, first);
+		use = !ca_parse_line(def, all, multi, first);
 		def = def->snext;
 		if (use && def) {
 		    /* entry needed so save it into list */