From 8c29b34032ebb714d2c593286aa29e5c64be55ab Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Mon, 7 Mar 2016 13:15:40 +0100 Subject: 38043: allow any completion widget to cycle matches for menu completion to fix reverse menu completion --- Src/Zle/compcore.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'Src/Zle/compcore.c') diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c index ae3a64074..ae7068fc9 100644 --- a/Src/Zle/compcore.c +++ b/Src/Zle/compcore.c @@ -30,10 +30,6 @@ #include "complete.mdh" #include "compcore.pro" -/* The last completion widget called. */ - -static Widget lastcompwidget; - /* Flags saying what we have to do with the result. */ /**/ @@ -471,8 +467,7 @@ before_complete(UNUSED(Hookdef dummy), int *lst) /* If we are doing a menu-completion... */ - if (minfo.cur && menucmp && *lst != COMP_LIST_EXPAND && - (menucmp != 1 || !compwidget || compwidget == lastcompwidget)) { + if (minfo.cur && menucmp && *lst != COMP_LIST_EXPAND) { do_menucmp(*lst); return 1; } @@ -481,7 +476,6 @@ before_complete(UNUSED(Hookdef dummy), int *lst) onlyexpl = listdat.valid = 0; return 1; } - lastcompwidget = compwidget; /* We may have to reset the cursor to its position after the * * string inserted by the last completion. */ -- cgit v1.2.3 From f368720b8b9b481f82cef2e84a7e035864dff5f1 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 9 Sep 2016 09:38:06 +0000 Subject: 39252: internal: quotestring: Drop the 'e' parameter, which no caller uses. --- ChangeLog | 7 +++++++ Src/Zle/compcore.c | 2 +- Src/Zle/compctl.c | 20 ++++++++++---------- Src/Zle/computil.c | 6 +++--- Src/Zle/zle_misc.c | 2 +- Src/Zle/zle_tricky.c | 24 ++++++++++++------------ Src/builtin.c | 2 +- Src/subst.c | 12 ++++++------ Src/text.c | 4 ++-- Src/utils.c | 27 ++++----------------------- 10 files changed, 47 insertions(+), 59 deletions(-) (limited to 'Src/Zle/compcore.c') diff --git a/ChangeLog b/ChangeLog index a0e643615..7fba3550c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2016-09-11 Daniel Shahaf + + * 39252: Src/Zle/compcore.c, Src/Zle/compctl.c, + Src/Zle/computil.c, Src/Zle/zle_misc.c, Src/Zle/zle_tricky.c, + Src/builtin.c, Src/subst.c, Src/text.c, Src/utils.c: internal: + quotestring: Drop the 'e' parameter, which no caller uses. + 2016-09-09 Daniel Shahaf * unposted: Test/D04parameter.ztst: Add tests for ${(q)} being diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c index ae7068fc9..2f9fb3308 100644 --- a/Src/Zle/compcore.c +++ b/Src/Zle/compcore.c @@ -1055,7 +1055,7 @@ multiquote(char *s, int ign) p += ign; while (*p) { if (ign >= 0 || p[1]) - s = quotestring(s, NULL, *p); + s = quotestring(s, *p); p++; } } diff --git a/Src/Zle/compctl.c b/Src/Zle/compctl.c index ce4576297..c2da2977f 100644 --- a/Src/Zle/compctl.c +++ b/Src/Zle/compctl.c @@ -1400,7 +1400,7 @@ printcompctl(char *s, Compctl cc, int printflags, int ispat) untokenize(p); quotedzputs(p, stdout); } else - quotedzputs(quotestring(s, NULL, QT_BACKSLASH), stdout); + quotedzputs(quotestring(s, QT_BACKSLASH), stdout); } /* loop through flags w/o args that are set, printing them if so */ @@ -1536,7 +1536,7 @@ printcompctl(char *s, Compctl cc, int printflags, int ispat) char *p = dupstring(s); untokenize(p); - quotedzputs(quotestring(p, NULL, QT_BACKSLASH), stdout); + quotedzputs(quotestring(p, QT_BACKSLASH), stdout); } } putchar('\n'); @@ -1740,8 +1740,8 @@ static int addwhat; * This uses the instring variable exported from zle_tricky.c. */ -#define quotename(s, e) \ -quotestring(s, e, instring == QT_NONE ? QT_BACKSLASH : instring) +#define quotename(s) \ +quotestring(s, instring == QT_NONE ? QT_BACKSLASH : instring) /* Hook functions */ @@ -3153,10 +3153,10 @@ makecomplistflags(Compctl cc, char *s, int incmd, int compadd) lpre = zhalloc(lpl + 1); memcpy(lpre, s, lpl); lpre[lpl] = '\0'; - qlpre = quotename(lpre, NULL); + qlpre = quotename(lpre); lsuf = dupstring(s + offs); lsl = strlen(lsuf); - qlsuf = quotename(lsuf, NULL); + qlsuf = quotename(lsuf); /* First check for ~.../... */ if (ic == Tilde) { @@ -3175,11 +3175,11 @@ makecomplistflags(Compctl cc, char *s, int incmd, int compadd) rpre = (*p || *lpre == Tilde || *lpre == Equals) ? (noreal = 0, getreal(tt)) : dupstring(tt); - qrpre = quotename(rpre, NULL); + qrpre = quotename(rpre); for (p = lsuf; *p && *p != String && *p != Tick; p++); rsuf = *p ? (noreal = 0, getreal(lsuf)) : dupstring(lsuf); - qrsuf = quotename(rsuf, NULL); + qrsuf = quotename(rsuf); /* Check if word is a pattern. */ @@ -3315,10 +3315,10 @@ makecomplistflags(Compctl cc, char *s, int incmd, int compadd) /* And get the file prefix. */ fpre = dupstring(((s1 == s || s1 == rpre || ic) && (*s != '/' || zlemetacs == wb)) ? s1 : s1 + 1); - qfpre = quotename(fpre, NULL); + qfpre = quotename(fpre); /* And the suffix. */ fsuf = dupstrpfx(rsuf, s2 - rsuf); - qfsuf = quotename(fsuf, NULL); + qfsuf = quotename(fsuf); if (comppatmatch && *comppatmatch && (ispattern & 2)) { int t2; diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c index 1c90a543a..16b681cda 100644 --- a/Src/Zle/computil.c +++ b/Src/Zle/computil.c @@ -3554,7 +3554,7 @@ comp_quote(char *str, int prefix) if ((x = (prefix && *str == '='))) *str = 'x'; - ret = quotestring(str, NULL, *compqstack); + ret = quotestring(str, *compqstack); if (x) *str = *ret = '='; @@ -4744,7 +4744,7 @@ cf_ignore(char **names, LinkList ign, char *style, char *path) for (; (n = *names); names++) { if (!ztat(n, &nst, 1) && S_ISDIR(nst.st_mode)) { if (tpwd && nst.st_dev == est.st_dev && nst.st_ino == est.st_ino) { - addlinknode(ign, quotestring(n, NULL, QT_BACKSLASH)); + addlinknode(ign, quotestring(n, QT_BACKSLASH)); continue; } if (tpar && !strncmp((c = dupstring(n)), path, pl)) { @@ -4760,7 +4760,7 @@ cf_ignore(char **names, LinkList ign, char *style, char *path) if (found || ((e = strrchr(c, '/')) && e > c + pl && !ztat(c, &st, 1) && st.st_dev == nst.st_dev && st.st_ino == nst.st_ino)) - addlinknode(ign, quotestring(n, NULL, QT_BACKSLASH)); + addlinknode(ign, quotestring(n, QT_BACKSLASH)); } } } diff --git a/Src/Zle/zle_misc.c b/Src/Zle/zle_misc.c index a040ca0df..fbd40cd03 100644 --- a/Src/Zle/zle_misc.c +++ b/Src/Zle/zle_misc.c @@ -780,7 +780,7 @@ bracketedpaste(char **args) int n; ZLE_STRING_T wpaste; wpaste = stringaszleline((zmult == 1) ? pbuf : - quotestring(pbuf, NULL, QT_SINGLE_OPTIONAL), 0, &n, NULL, NULL); + quotestring(pbuf, QT_SINGLE_OPTIONAL), 0, &n, NULL, NULL); cuttext(wpaste, n, CUT_REPLACE); if (!(zmod.flags & MOD_VIBUF)) { kct = -1; diff --git a/Src/Zle/zle_tricky.c b/Src/Zle/zle_tricky.c index 1d4e1d284..958e79ffb 100644 --- a/Src/Zle/zle_tricky.c +++ b/Src/Zle/zle_tricky.c @@ -424,8 +424,8 @@ mod_export int instring, inbackt; * This uses the instring variable above. */ -#define quotename(s, e) \ -quotestring(s, e, instring == QT_NONE ? QT_BACKSLASH : instring) +#define quotename(s) \ +quotestring(s, instring == QT_NONE ? QT_BACKSLASH : instring) /* Check if the given string is the name of a parameter and if this * * parameter is one worth expanding. */ @@ -2004,11 +2004,11 @@ get_comp_string(void) new->next = NULL; new->str = dupstrpfx(bbeg, len); - new->str = ztrdup(quotename(new->str, NULL)); + new->str = ztrdup(quotename(new->str)); untokenize(new->str); new->pos = begi; *dbeg = '\0'; - new->qpos = strlen(quotename(predup, NULL)); + new->qpos = strlen(quotename(predup)); *dbeg = '{'; i -= len; boffs -= len; @@ -2067,11 +2067,11 @@ get_comp_string(void) lastbrbeg = new; new->str = dupstrpfx(bbeg, len); - new->str = ztrdup(quotename(new->str, NULL)); + new->str = ztrdup(quotename(new->str)); untokenize(new->str); new->pos = begi; *dbeg = '\0'; - new->qpos = strlen(quotename(predup, NULL)); + new->qpos = strlen(quotename(predup)); *dbeg = '{'; i -= len; boffs -= len; @@ -2117,7 +2117,7 @@ get_comp_string(void) brend = new; new->str = dupstrpfx(bbeg, len); - new->str = ztrdup(quotename(new->str, NULL)); + new->str = ztrdup(quotename(new->str)); untokenize(new->str); new->pos = dp - predup - len + 1; new->qpos = len; @@ -2146,11 +2146,11 @@ get_comp_string(void) lastbrbeg = new; new->str = dupstrpfx(bbeg, len); - new->str = ztrdup(quotename(new->str, NULL)); + new->str = ztrdup(quotename(new->str)); untokenize(new->str); new->pos = begi; *dbeg = '\0'; - new->qpos = strlen(quotename(predup, NULL)); + new->qpos = strlen(quotename(predup)); *dbeg = '{'; boffs -= len; memmove(dbeg, dbeg + len, 1+strlen(dbeg+len)); @@ -2165,7 +2165,7 @@ get_comp_string(void) p = bp->pos; l = bp->qpos; bp->pos = strlen(predup + p + l); - bp->qpos = strlen(quotename(predup + p + l, NULL)); + bp->qpos = strlen(quotename(predup + p + l)); memmove(predup + p, predup + p + l, 1+bp->pos); } } @@ -2288,7 +2288,7 @@ doexpansion(char *s, int lst, int olst, int explincmd) foredel(we - wb, CUT_RAW); while ((ss = (char *)ugetnode(vl))) { ret = 0; - ss = quotename(ss, NULL); + ss = quotename(ss); untokenize(ss); inststr(ss); if (nonempty(vl) || !first) { @@ -2997,7 +2997,7 @@ processcmd(UNUSED(char **args)) inststr(" "); untokenize(s); - inststr(quotename(s, NULL)); + inststr(quotename(s)); zsfree(s); done = 1; diff --git a/Src/builtin.c b/Src/builtin.c index 3b82c9e7f..248f929d7 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -4844,7 +4844,7 @@ bin_print(char *name, char **args, Options ops, int func) break; case 'q': stringval = curarg ? - quotestring(curarg, NULL, QT_BACKSLASH_SHOWNULL) : &nullstr; + quotestring(curarg, QT_BACKSLASH_SHOWNULL) : &nullstr; *d = 's'; print_val(stringval); break; diff --git a/Src/subst.c b/Src/subst.c index 4641b4ba5..1c2027f32 100644 --- a/Src/subst.c +++ b/Src/subst.c @@ -3615,7 +3615,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags, char *tmp; for (; *ap; ap++) { - tmp = quotestring(*ap, NULL, quotetype); + tmp = quotestring(*ap, quotetype); sl = strlen(tmp); *ap = (char *) zhalloc(pre + sl + post + 1); strcpy((*ap) + pre, tmp); @@ -3628,7 +3628,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags, } } else for (; *ap; ap++) - *ap = quotestring(*ap, NULL, QT_BACKSLASH_SHOWNULL); + *ap = quotestring(*ap, QT_BACKSLASH_SHOWNULL); } else { int one = noerrs, oef = errflag, haserr = 0; @@ -3658,7 +3658,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags, } else if (quotetype > QT_BACKSLASH) { int sl; char *tmp; - tmp = quotestring(val, NULL, quotetype); + tmp = quotestring(val, quotetype); sl = strlen(tmp); val = (char *) zhalloc(pre + sl + 2); strcpy(val + pre, tmp); @@ -3669,7 +3669,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags, if (quotetype == QT_DOLLARS) val[0] = '$'; } else - val = quotestring(val, NULL, QT_BACKSLASH_SHOWNULL); + val = quotestring(val, QT_BACKSLASH_SHOWNULL); } else { int one = noerrs, oef = errflag, haserr; @@ -4274,7 +4274,7 @@ modify(char **str, char **ptr) subst(©, hsubl, hsubr, gbal); break; case 'q': - copy = quotestring(copy, NULL, QT_BACKSLASH_SHOWNULL); + copy = quotestring(copy, QT_BACKSLASH_SHOWNULL); break; case 'Q': { @@ -4356,7 +4356,7 @@ modify(char **str, char **ptr) subst(str, hsubl, hsubr, gbal); break; case 'q': - *str = quotestring(*str, NULL, QT_BACKSLASH); + *str = quotestring(*str, QT_BACKSLASH); break; case 'Q': { diff --git a/Src/text.c b/Src/text.c index cf6d3eb42..d387d361a 100644 --- a/Src/text.c +++ b/Src/text.c @@ -1068,11 +1068,11 @@ getredirs(LinkList redirs) */ if (!has_token(f->name)) { taddchr('\''); - taddstr(quotestring(f->name, NULL, QT_SINGLE)); + taddstr(quotestring(f->name, QT_SINGLE)); taddchr('\''); } else { taddchr('"'); - taddstr(quotestring(f->name, NULL, QT_DOUBLE)); + taddstr(quotestring(f->name, QT_DOUBLE)); taddchr('"'); } if (sav) diff --git a/Src/utils.c b/Src/utils.c index d209078f4..b434821e5 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -1047,9 +1047,9 @@ substnamedir(char *s) Nameddir d = finddir(s); if (!d) - return quotestring(s, NULL, QT_BACKSLASH); + return quotestring(s, QT_BACKSLASH); return zhtricat("~", d->node.nam, quotestring(s + strlen(d->dir), - NULL, QT_BACKSLASH)); + QT_BACKSLASH)); } @@ -5649,10 +5649,6 @@ addunprintable(char *v, const char *u, const char *uend) /* * Quote the string s and return the result as a string from the heap. * - * If e is non-zero, the - * pointer it points to may point to a position in s and in e the position - * of the corresponding character in the quoted string is returned. - * * The last argument is a QT_ value defined in zsh.h other than QT_NONE. * * Most quote styles other than backslash assume the quotes are to @@ -5665,13 +5661,13 @@ addunprintable(char *v, const char *u, const char *uend) /**/ mod_export char * -quotestring(const char *s, char **e, int instring) +quotestring(const char *s, int instring) { const char *u; char *v; int alloclen; char *buf; - int sf = 0, shownull = 0; + int shownull = 0; /* * quotesub is used with QT_SINGLE_OPTIONAL. * quotesub = 0: mechanism not active @@ -5742,10 +5738,6 @@ quotestring(const char *s, char **e, int instring) while (*u) { uend = u + MB_METACHARLENCONV(u, &cc); - if (e && !sf && *e <= u) { - *e = v; - sf = 1; - } if ( #ifdef MULTIBYTE_SUPPORT cc != WEOF && @@ -5772,11 +5764,6 @@ quotestring(const char *s, char **e, int instring) } } else if (instring == QT_BACKSLASH_PATTERN) { while (*u) { - if (e && !sf && *e == u) { - *e = v; - sf = 1; - } - if (ipattern(*u)) *v++ = '\\'; *v++ = *u++; @@ -5795,8 +5782,6 @@ quotestring(const char *s, char **e, int instring) */ while (*u) { int dobackslash = 0; - if (e && *e == u) - *e = v, sf = 1; if (*u == Tick || *u == Qtick) { char c = *u++; @@ -5984,10 +5969,6 @@ quotestring(const char *s, char **e, int instring) *v++ = '\''; *v = '\0'; - if (e && *e == u) - *e = v, sf = 1; - DPUTS(e && !sf, "BUG: Wild pointer *e in quotestring()"); - v = dupstring(buf); zfree(buf, alloclen); return v; -- cgit v1.2.3 From bd94e13f34db02b0fed2414b54cc6787407436ad Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 17 Sep 2016 06:32:58 +0000 Subject: 39372: compadd: Match -P prefix all-or-nothing rather than greedily. --- ChangeLog | 5 +++++ Src/Zle/compcore.c | 11 +++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) (limited to 'Src/Zle/compcore.c') diff --git a/ChangeLog b/ChangeLog index f9592dd8b..2a8ba741b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-09-20 Daniel Shahaf + + * 39372: Src/Zle/compcore.c: compadd: Match -P prefix + all-or-nothing rather than greedily. + 2016-09-19 Barton E. Schaefer * 39381: Src/exec.c: handle save/restore of variable values when diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c index 2f9fb3308..05d27068a 100644 --- a/Src/Zle/compcore.c +++ b/Src/Zle/compcore.c @@ -2029,7 +2029,7 @@ addmatches(Cadata dat, char **argv) char **aign = NULL, **dparr = NULL, *oaq = autoq, *oppre = dat->ppre; char *oqp = qipre, *oqs = qisuf, qc, **disp = NULL, *ibuf = NULL; char **arrays = NULL; - int lpl, lsl, pl, sl, bcp = 0, bcs = 0, bpadd = 0, bsadd = 0; + int lpl, lsl, sl, bcp = 0, bcs = 0, bpadd = 0, bsadd = 0; int ppl = 0, psl = 0, ilen = 0; int llpl = 0, llsl = 0, nm = mnum, gflags = 0, ohp = haspattern; int isexact, doadd, ois = instring, oib = inbackt; @@ -2193,9 +2193,12 @@ addmatches(Cadata dat, char **argv) /* Test if there is an existing -P prefix. */ if (dat->pre && *dat->pre) { - pl = pfxlen(dat->pre, lpre); - llpl -= pl; - lpre += pl; + int prefix_length = pfxlen(dat->pre, lpre); + if (dat->pre[prefix_length] == '\0') { + /* $compadd_args[-P] is a prefix of ${PREFIX}. */ + llpl -= prefix_length; + lpre += prefix_length; + } } } /* Now duplicate the strings we have from the command line. */ -- cgit v1.2.3 From 2c612c5ba10d7278b76e1d05374cc617ed5ad5fc Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 19 Sep 2016 07:00:22 +0000 Subject: 39383: compadd: Restrict previous patch to the case where $PREFIX includes characters both from the -P prefix and from the (unprefixed) candidate completion word. --- ChangeLog | 4 ++++ Src/Zle/compcore.c | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'Src/Zle/compcore.c') diff --git a/ChangeLog b/ChangeLog index 2a8ba741b..ff313003b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2016-09-20 Daniel Shahaf + * 39383: Src/Zle/compcore.c: compadd: Restrict previous patch + to the case where $PREFIX includes characters both from the -P + prefix and from the (unprefixed) candidate completion word. + * 39372: Src/Zle/compcore.c: compadd: Match -P prefix all-or-nothing rather than greedily. diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c index 05d27068a..5443018d8 100644 --- a/Src/Zle/compcore.c +++ b/Src/Zle/compcore.c @@ -2194,8 +2194,10 @@ addmatches(Cadata dat, char **argv) /* Test if there is an existing -P prefix. */ if (dat->pre && *dat->pre) { int prefix_length = pfxlen(dat->pre, lpre); - if (dat->pre[prefix_length] == '\0') { - /* $compadd_args[-P] is a prefix of ${PREFIX}. */ + if (dat->pre[prefix_length] == '\0' || + lpre[prefix_length] == '\0') { + /* $compadd_args[-P] is a prefix of ${PREFIX}, or + * vice-versa. */ llpl -= prefix_length; lpre += prefix_length; } -- cgit v1.2.3 From 36b290814f5c2176f67f10746d5e899ccc260a67 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 1 Nov 2016 17:26:08 +0000 Subject: 39802: internal: Document and simplify multiquote(). The code simplifications take advantage of the fact that all callers pass either 0 or 1 for 'ign'. The tildequote() text is from workers/39271. --- ChangeLog | 3 +++ Src/Zle/compcore.c | 22 +++++++++++++++++----- Src/Zle/complete.c | 2 +- 3 files changed, 21 insertions(+), 6 deletions(-) (limited to 'Src/Zle/compcore.c') diff --git a/ChangeLog b/ChangeLog index 4a08d2664..63b9342c1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2016-11-03 Daniel Shahaf + * 39802: Src/Zle/compcore.c, Src/Zle/complete.c: internal: + Document and simplify multiquote(). + * users/22063: Doc/Zsh/zle.yo: bracketed-paste: Document ability to specify a vi register. (after users/22036) diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c index 5443018d8..f69f68091 100644 --- a/Src/Zle/compcore.c +++ b/Src/Zle/compcore.c @@ -1043,6 +1043,13 @@ makecomplist(char *s, int incmd, int lst) } } +/* + * Quote 's' according to compqstack, aka $compstate[all_quotes]. + * + * If 'ign' is 1, skip the innermost quoting level. Otherwise 'ign' + * must be 0. + */ + /**/ mod_export char * multiquote(char *s, int ign) @@ -1050,12 +1057,11 @@ multiquote(char *s, int ign) if (s) { char *os = s, *p = compqstack; - if (p && *p && (ign < 1 || p[ign])) { - if (ign > 0) - p += ign; + if (p && *p && (ign == 0 || p[1])) { + if (ign) + p++; while (*p) { - if (ign >= 0 || p[1]) - s = quotestring(s, *p); + s = quotestring(s, *p); p++; } } @@ -1065,6 +1071,12 @@ multiquote(char *s, int ign) return NULL; } +/* + * tildequote(s, ign): Equivalent to multiquote(s, ign), except that if + * compqstack[0] == QT_BACKSLASH and s[0] == '~', then that tilde is not + * quoted. + */ + /**/ mod_export char * tildequote(char *s, int ign) diff --git a/Src/Zle/complete.c b/Src/Zle/complete.c index 4bf238fab..73619347c 100644 --- a/Src/Zle/complete.c +++ b/Src/Zle/complete.c @@ -52,7 +52,7 @@ char **compwords, *compqiprefix, *compqisuffix, *compquote, - *compqstack, + *compqstack, /* compstate[all_quotes] */ *comppatmatch, *complastprompt; /**/ -- cgit v1.2.3 From 4ad1ad9777d2bb27791043b306b65de62deb5f11 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 1 Nov 2016 17:26:11 +0000 Subject: 39805: internal: Document some compadd internals. --- ChangeLog | 3 +++ Src/Zle/comp.h | 19 +++++++++---------- Src/Zle/compcore.c | 12 ++++++++++-- 3 files changed, 22 insertions(+), 12 deletions(-) (limited to 'Src/Zle/compcore.c') diff --git a/ChangeLog b/ChangeLog index f2ec7cc25..12cf892ed 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2016-11-03 Daniel Shahaf + * 39805: Src/Zle/comp.h, Src/Zle/compcore.c: internal: Document + some compadd internals. + * 39804: Src/Zle/comp.h, Src/Zle/complete.c: internal: Document matchspec flags. diff --git a/Src/Zle/comp.h b/Src/Zle/comp.h index 14af6173c..3711fde29 100644 --- a/Src/Zle/comp.h +++ b/Src/Zle/comp.h @@ -125,7 +125,7 @@ struct cmatch { #define CMF_REMOVE (1<< 1) /* remove the suffix */ #define CMF_ISPAR (1<< 2) /* is paramter expansion */ #define CMF_PARBR (1<< 3) /* paramter expansion with a brace */ -#define CMF_PARNEST (1<< 4) /* nested paramter expansion */ +#define CMF_PARNEST (1<< 4) /* nested parameter expansion */ #define CMF_NOLIST (1<< 5) /* should not be listed */ #define CMF_DISPLINE (1<< 6) /* display strings one per line */ #define CMF_HIDE (1<< 7) /* temporarily hide this one */ @@ -235,7 +235,6 @@ struct cpattern { * the anchor. */ typedef struct cline *Cline; -typedef struct clsub Clsub; struct cline { Cline next; @@ -291,14 +290,14 @@ struct menuinfo { /* Flags for compadd and addmatches(). */ -#define CAF_QUOTE 1 -#define CAF_NOSORT 2 -#define CAF_MATCH 4 -#define CAF_UNIQCON 8 -#define CAF_UNIQALL 16 -#define CAF_ARRAYS 32 -#define CAF_KEYS 64 -#define CAF_ALL 128 +#define CAF_QUOTE 1 /* compadd -Q: positional arguments already quoted */ +#define CAF_NOSORT 2 /* compadd -V: don't sort */ +#define CAF_MATCH 4 /* compadd without -U: do matching */ +#define CAF_UNIQCON 8 /* compadd -2: don't deduplicate */ +#define CAF_UNIQALL 16 /* compadd -1: deduplicate */ +#define CAF_ARRAYS 32 /* compadd -a or -k: array/assoc parameter names */ +#define CAF_KEYS 64 /* compadd -k: assoc parameter names */ +#define CAF_ALL 128 /* compadd -C: _all_matches */ /* Data for compadd and addmatches() */ diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c index f69f68091..fe16c1300 100644 --- a/Src/Zle/compcore.c +++ b/Src/Zle/compcore.c @@ -1976,6 +1976,11 @@ get_user_var(char *nam) } } +/* + * If KEYS, then NAME is an associative array; return its keys. + * Else, NAME is a plain array; return its elements. + */ + static char ** get_data_arr(char *name, int keys) { @@ -2037,16 +2042,17 @@ addmatch(char *str, int flags, char ***dispp, int line) int addmatches(Cadata dat, char **argv) { + /* ms: "match string" - string to use as completion. + * Overloaded at one place as a temporary. */ char *s, *ms, *lipre = NULL, *lisuf = NULL, *lpre = NULL, *lsuf = NULL; char **aign = NULL, **dparr = NULL, *oaq = autoq, *oppre = dat->ppre; char *oqp = qipre, *oqs = qisuf, qc, **disp = NULL, *ibuf = NULL; char **arrays = NULL; - int lpl, lsl, sl, bcp = 0, bcs = 0, bpadd = 0, bsadd = 0; + int lpl, lsl, bcp = 0, bcs = 0, bpadd = 0, bsadd = 0; int ppl = 0, psl = 0, ilen = 0; int llpl = 0, llsl = 0, nm = mnum, gflags = 0, ohp = haspattern; int isexact, doadd, ois = instring, oib = inbackt; Cline lc = NULL, pline = NULL, sline = NULL; - Cmatch cm; struct cmlist mst; Cmlist oms = mstack; Patprog cp = NULL, *pign = NULL; @@ -2424,6 +2430,7 @@ addmatches(Cadata dat, char **argv) if (dat->psuf) psl = strlen(dat->psuf); for (; (s = *argv); argv++) { + int sl; bpl = obpl; bsl = obsl; if (disp) { @@ -2484,6 +2491,7 @@ addmatches(Cadata dat, char **argv) goto next_array; } if (doadd) { + Cmatch cm; Brinfo bp; for (bp = obpl; bp; bp = bp->next) -- cgit v1.2.3 From 58ce2f119a42f115e9ed5c1b6a35e5837d4f6776 Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Sat, 5 Nov 2016 00:34:43 +0100 Subject: 39829: when compstate[insert] is emptied by the completion function and AUTO_MENU is set, start menu completion on the second tab press rather than the third --- ChangeLog | 6 +++++- Src/Zle/compcore.c | 10 ++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'Src/Zle/compcore.c') diff --git a/ChangeLog b/ChangeLog index 9f8e5a0c3..a8f2c0b1d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2016-11-04 Oliver Kiddle + * 39829: Src/Zle/compcore.c: when compstate[insert] is emptied + by the completion function and AUTO_MENU is set, start menu + completion on the second tab press rather than the third + * 39834: Src/builtin.c, Completion/Zsh/Command/_print, Completion/Zsh/Command/_fc, Completion/Zsh/Type/_ps1234: when print used with -v and -l, include a final @@ -3363,7 +3367,7 @@ 2015-09-11 Daniel Shahaf - * 36443: Doc/Zsh/zle.yo Src/Zle/zle_refresh.c: + * 36443: Doc/Zsh/zle.yo Src/Zle/zle_refresh.c: Highlight pasted/yanked text as standout by default (i.e., when $zle_highlight doesn't specify otherwise). diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c index fe16c1300..536bca7b3 100644 --- a/Src/Zle/compcore.c +++ b/Src/Zle/compcore.c @@ -835,6 +835,7 @@ callcompfunc(char *s, char *fn) endparamscope(); lastcmd = 0; incompfunc = icf; + startauto = 0; if (!complist) uselist = 0; @@ -882,8 +883,13 @@ callcompfunc(char *s, char *fn) useline = 1, usemenu = 1; else if (strpfx("auto", compinsert)) useline = 1, usemenu = 2; - else + else { useline = usemenu = 0; + /* if compstate[insert] was emptied, no unambiguous prefix + * ever gets inserted so allow the next tab to already start + * menu completion */ + startauto = lastambig = isset(AUTOMENU); + } if (useline && (p = strchr(compinsert, ':'))) { insmnum = atoi(++p); @@ -896,7 +902,7 @@ callcompfunc(char *s, char *fn) #endif } } - startauto = ((compinsert && + startauto = startauto || ((compinsert && !strcmp(compinsert, "automenu-unambiguous")) || (bashlistfirst && isset(AUTOMENU) && (!compinsert || !*compinsert))); -- cgit v1.2.3 From 7d2f8050088f61444fc6117cf1e7bfe8d440d73c Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Wed, 16 Nov 2016 09:42:49 +0100 Subject: 39945: allow further tab presses to move on to menu completion even when compstate[insert] is emptied --- ChangeLog | 6 +++++ Completion/Base/Core/_message | 3 ++- Src/Zle/compcore.c | 1 + Test/Y03arguments.ztst | 61 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 1 deletion(-) (limited to 'Src/Zle/compcore.c') diff --git a/ChangeLog b/ChangeLog index 488f1ed45..cdc89a86d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2016-11-16 Oliver Kiddle + + * 39945: Src/Zle/compcore.c, Completion/Base/Core/_message, + Test/Y03arguments.ztst: allow further tab presses to move on + to menu completion even when compstate[insert] is emptied + 2016-11-15 Peter Stephenson * 39949: Src/subst.c, Src/utils.c, Test/B09hash.ztst: "-" is diff --git a/Completion/Base/Core/_message b/Completion/Base/Core/_message index 13c83989f..4d5645eaf 100644 --- a/Completion/Base/Core/_message +++ b/Completion/Base/Core/_message @@ -18,7 +18,8 @@ if [[ "$1" = -e ]]; then ret=0 done - (( $compstate[nmatches] )) || compstate[insert]= + (( ! $compstate[nmatches] )) && [[ $compstate[insert] = *unambiguous* ]] && + compstate[insert]= return ret fi diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c index 536bca7b3..d1cf7a08a 100644 --- a/Src/Zle/compcore.c +++ b/Src/Zle/compcore.c @@ -425,6 +425,7 @@ do_completion(UNUSED(Hookdef dummy), Compldat dat) } } else { invalidatelist(); + lastambig = isset(BASHAUTOLIST); if (forcelist) clearlist = 1; zlemetacs = 0; diff --git a/Test/Y03arguments.ztst b/Test/Y03arguments.ztst index 3ada16844..0763c419d 100644 --- a/Test/Y03arguments.ztst +++ b/Test/Y03arguments.ztst @@ -243,6 +243,67 @@ >NO:{-a} >NO:{-b} + tst_arguments --abc --aah :arg: + comptesteval 'setopt bashautolist automenu' + comptest $'tst --a\t\t\t' +0:with message and bashautolist, a third tab will get menu completion +>line: {tst --a}{} +>line: {tst --a}{} +>DESCRIPTION:{arg} +>DESCRIPTION:{option} +>NO:{--aah} +>NO:{--abc} +>line: {tst --aah}{} + + tst_arguments --abc --aah :arg: + comptesteval 'setopt bashautolist noautomenu' + comptest $'tst --a\t\t\t' +0:with message and bashautolist, a third tab is needed to display the list +>line: {tst --a}{} +>line: {tst --a}{} +>DESCRIPTION:{arg} +>DESCRIPTION:{option} +>NO:{--aah} +>NO:{--abc} +>line: {tst --a}{} + + tst_arguments --abc --aah :arg: + comptesteval 'setopt nobashautolist noautomenu' + comptest $'tst --\t\t' +0:with message and noautomenu second tab redisplays the list +>line: {tst --}{} +>DESCRIPTION:{arg} +>DESCRIPTION:{option} +>NO:{--aah} +>NO:{--abc} +>line: {tst --}{} +>DESCRIPTION:{arg} +>DESCRIPTION:{option} +>NO:{--aah} +>NO:{--abc} + + tst_arguments --abc --aah :arg: + comptesteval 'setopt nobashautolist automenu' + comptest $'tst --\t\t' +0:with message two tabs will start menu completion +>line: {tst --}{} +>DESCRIPTION:{arg} +>DESCRIPTION:{option} +>NO:{--aah} +>NO:{--abc} +>line: {tst --aah}{} + + tst_arguments --abc --aah :arg: + comptesteval 'zstyle ":completion:*::::" completer _oldlist _complete' + comptest $'tst --\t\t' +0:with message and _oldlist, two tabs will start menu completion +>line: {tst --}{} +>DESCRIPTION:{arg} +>DESCRIPTION:{option} +>NO:{--aah} +>NO:{--abc} +>line: {tst --aah}{} + %clean zmodload -ui zsh/zpty -- cgit v1.2.3