diff options
Diffstat (limited to 'Src/Zle/compcore.c')
-rw-r--r-- | Src/Zle/compcore.c | 56 |
1 files changed, 44 insertions, 12 deletions
diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c index 0c32be14b..5fc15b0d3 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; @@ -835,6 +836,7 @@ callcompfunc(char *s, char *fn) endparamscope(); lastcmd = 0; incompfunc = icf; + startauto = 0; if (!complist) uselist = 0; @@ -882,8 +884,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 +903,7 @@ callcompfunc(char *s, char *fn) #endif } } - startauto = ((compinsert && + startauto = startauto || ((compinsert && !strcmp(compinsert, "automenu-unambiguous")) || (bashlistfirst && isset(AUTOMENU) && (!compinsert || !*compinsert))); @@ -1043,6 +1050,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 +1064,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, NULL, *p); + s = quotestring(s, *p); p++; } } @@ -1065,6 +1078,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) @@ -1964,6 +1983,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) { @@ -2025,16 +2049,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, pl, 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; @@ -2193,9 +2218,14 @@ 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' || + lpre[prefix_length] == '\0') { + /* $compadd_args[-P] is a prefix of ${PREFIX}, or + * vice-versa. */ + llpl -= prefix_length; + lpre += prefix_length; + } } } /* Now duplicate the strings we have from the command line. */ @@ -2407,6 +2437,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) { @@ -2467,6 +2498,7 @@ addmatches(Cadata dat, char **argv) goto next_array; } if (doadd) { + Cmatch cm; Brinfo bp; for (bp = obpl; bp; bp = bp->next) |