diff options
Diffstat (limited to 'Src/Zle')
-rw-r--r-- | Src/Zle/compcore.c | 29 | ||||
-rw-r--r-- | Src/Zle/complete.c | 2 | ||||
-rw-r--r-- | Src/Zle/complist.c | 18 | ||||
-rw-r--r-- | Src/Zle/zle_main.c | 7 | ||||
-rw-r--r-- | Src/Zle/zle_refresh.c | 16 | ||||
-rw-r--r-- | Src/Zle/zle_thingy.c | 12 | ||||
-rw-r--r-- | Src/Zle/zle_tricky.c | 64 |
7 files changed, 103 insertions, 45 deletions
diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c index 5514e2e1d..b1de6c6cc 100644 --- a/Src/Zle/compcore.c +++ b/Src/Zle/compcore.c @@ -607,7 +607,7 @@ callcompfunc(char *s, char *fn) if (rdstr) compredirect = rdstr; kset |= CP_REDIRECT; - } else + } else { switch (linwhat) { case IN_ENV: compcontext = (linarr ? "array_value" : "value"); @@ -637,6 +637,7 @@ callcompfunc(char *s, char *fn) aadd = 1; } } + } compcontext = ztrdup(compcontext); if (compwords) freearray(compwords); @@ -1099,7 +1100,7 @@ mod_export char * check_param(char *s, int set, int test) { char *p; - int found = 0; + int found = 0, qstring = 0; zsfree(parpre); parpre = NULL; @@ -1126,6 +1127,7 @@ check_param(char *s, int set, int test) !(*p == String && p[1] == Snull) && !(*p == Qstring && p[1] == '\'')) { found = 1; + qstring = (*p == Qstring); break; } } @@ -1150,7 +1152,7 @@ check_param(char *s, int set, int test) p[1] != Inpar && p[1] != Inbrack && p[1] != Snull) { /* This is a parameter expression, not $(...), $[...], $'...'. */ char *b = p + 1, *e = b, *ie; - int n = 0, br = 1, nest = 0; + int br = 1, nest = 0; if (*b == Inbrace) { char *tb = b; @@ -1161,7 +1163,18 @@ check_param(char *s, int set, int test) /* Ignore the possible (...) flags. */ b++, br++; - n = skipparens(Inpar, Outpar, &b); + if ((qstring ? skipparens('(', ')', &b) : + skipparens(Inpar, Outpar, &b)) > 0) { + /* + * We are still within the parameter flags. There's no + * point trying to do anything clever here with + * parameter names. Instead, just report that we are in + * a brace parameter but let the completion function + * decide what to do about it. + */ + ispar = 2; + return NULL; + } for (tb = p - 1; tb > s && *tb != Outbrace && *tb != Inbrace; tb--); if (tb > s && *tb == Inbrace && (tb[-1] == String || *tb == Qstring)) @@ -1204,7 +1217,7 @@ check_param(char *s, int set, int test) } /* Now make sure that the cursor is inside the name. */ - if (offs <= e - s && offs >= b - s && n <= 0) { + if (offs <= e - s && offs >= b - s) { char sav; if (br) { @@ -1465,7 +1478,7 @@ set_comp_sep(void) * when stripping single quotes: 1 for RCQUOTES, 3 otherwise * (because we leave a "'" in the final string). */ - int dq = 0, odq, sq = 0, osq, qttype, sqq = 0, lsq = 0, qa = 0; + int dq = 0, odq, sq = 0, qttype, sqq = 0, lsq = 0, qa = 0; /* dolq: like sq and dq but for dollars quoting. */ int dolq = 0; /* remember some global variable values (except lp is local) */ @@ -1570,7 +1583,6 @@ set_comp_sep(void) } odq = dq; - osq = sq; inpush(dupstrspace(tmp), 0, NULL); zlemetaline = tmp; /* @@ -3294,7 +3306,7 @@ dupmatch(Cmatch m, int nbeg, int nend) mod_export int permmatches(int last) { - Cmgroup g = amatches, n, opm; + Cmgroup g = amatches, n; Cmatch *p, *q; Cexpl *ep, *eq, e, o; LinkList mlist; @@ -3308,7 +3320,6 @@ permmatches(int last) } newmatches = fi = 0; - opm = pmatches; pmatches = lmatches = NULL; nmatches = smatches = diffmatches = 0; diff --git a/Src/Zle/complete.c b/Src/Zle/complete.c index 6398fd3e7..ea5e41f5f 100644 --- a/Src/Zle/complete.c +++ b/Src/Zle/complete.c @@ -1544,7 +1544,7 @@ cond_range(char **a, int id) } static struct builtin bintab[] = { - BUILTIN("compadd", 0, bin_compadd, 0, -1, 0, NULL, NULL), + BUILTIN("compadd", BINF_HANDLES_OPTS, bin_compadd, 0, -1, 0, NULL, NULL), BUILTIN("compset", 0, bin_compset, 1, 3, 0, NULL, NULL), }; diff --git a/Src/Zle/complist.c b/Src/Zle/complist.c index fdca7a99f..bcf356179 100644 --- a/Src/Zle/complist.c +++ b/Src/Zle/complist.c @@ -849,9 +849,9 @@ putmatchcol(char *group, char *n) { Patcol pc; - nrefs = MAX_POS - 1; + for (pc = mcolors.pats; pc; pc = pc->next) { + nrefs = MAX_POS - 1; - for (pc = mcolors.pats; pc; pc = pc->next) if ((!pc->prog || !group || pattry(pc->prog, group)) && pattryrefs(pc->pat, n, -1, -1, 0, &nrefs, begpos, endpos)) { if (pc->cols[1]) { @@ -863,6 +863,7 @@ putmatchcol(char *group, char *n) return 0; } + } zcputs(group, COL_NO); @@ -880,9 +881,9 @@ putfilecol(char *group, char *filename, mode_t m, int special) Patcol pc; int len; - nrefs = MAX_POS - 1; + for (pc = mcolors.pats; pc; pc = pc->next) { + nrefs = MAX_POS - 1; - for (pc = mcolors.pats; pc; pc = pc->next) if ((!pc->prog || !group || pattry(pc->prog, group)) && pattryrefs(pc->pat, filename, -1, -1, 0, &nrefs, begpos, endpos)) { if (pc->cols[1]) { @@ -894,6 +895,7 @@ putfilecol(char *group, char *filename, mode_t m, int special) return 0; } + } if (special != -1) { colour = special; @@ -1369,8 +1371,6 @@ compprintlist(int showall) } #endif if ((e = g->expls)) { - int l; - if (!lastused && lasttype == 1) { e = lastexpl; ml = lastml; @@ -1393,9 +1393,9 @@ compprintlist(int showall) } if (mlbeg < 0 && mfirstl < 0) mfirstl = ml; - l = compprintfmt((*e)->str, - ((*e)->always ? -1 : (*e)->count), - dolist(ml), 1, ml, &stop); + (void)compprintfmt((*e)->str, + ((*e)->always ? -1 : (*e)->count), + dolist(ml), 1, ml, &stop); if (mselect >= 0) { int mm = (mcols * ml), i; diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c index 6acedee70..3cdc3b2ed 100644 --- a/Src/Zle/zle_main.c +++ b/Src/Zle/zle_main.c @@ -53,11 +53,6 @@ mod_export int zlecs, zlell; /**/ mod_export int incompctlfunc; -/* != 0 if we are in a new style completion function */ - -/**/ -mod_export int incompfunc; - /* != 0 if completion module is loaded */ /**/ @@ -1233,7 +1228,7 @@ zleread(char **lp, char **rp, int flags, int context) alarm(0); freeundo(); - if (eofsent) { + if (eofsent || errflag) { s = NULL; } else { zleline[zlell++] = ZWC('\n'); diff --git a/Src/Zle/zle_refresh.c b/Src/Zle/zle_refresh.c index 797f86251..260df8bf6 100644 --- a/Src/Zle/zle_refresh.c +++ b/Src/Zle/zle_refresh.c @@ -341,7 +341,7 @@ zle_set_highlight(void) match_highlight(*atrs + 8, &special_atr_on); special_atr_on_set = 1; } else if (strpfx("region:", *atrs)) { - match_highlight(*atrs + 7, ®ion_highlights->atr); + match_highlight(*atrs + 7, ®ion_highlights[0].atr); region_atr_on_set = 1; } else if (strpfx("isearch:", *atrs)) { match_highlight(*atrs + 8, &(region_highlights[1].atr)); @@ -357,7 +357,7 @@ zle_set_highlight(void) if (!special_atr_on_set) special_atr_on = TXTSTANDOUT; if (!region_atr_on_set) - region_highlights->atr = TXTSTANDOUT; + region_highlights[0].atr = TXTSTANDOUT; if (!isearch_atr_on_set) region_highlights[1].atr = TXTUNDERLINE; if (!suffix_atr_on_set) @@ -1022,14 +1022,14 @@ zrefresh(void) /* check for region between point ($CURSOR) and mark ($MARK) */ if (region_active) { if (zlecs <= mark) { - region_highlights->start = zlecs; - region_highlights->end = mark; + region_highlights[0].start = zlecs; + region_highlights[0].end = mark; } else { - region_highlights->start = mark; - region_highlights->end = zlecs; + region_highlights[0].start = mark; + region_highlights[0].end = zlecs; } } else { - region_highlights->start = region_highlights->end = -1; + region_highlights[0].start = region_highlights[0].end = -1; } /* check for isearch string to highlight */ if (isearch_active) { @@ -2418,8 +2418,6 @@ singlerefresh(ZLE_STRING_T tmpline, int tmpll, int tmpcs) all_atr_off = TXT_ATTR_OFF_FROM_ON(all_atr_on); if (tmpline[t0] == ZWC('\t')) { - REFRESH_ELEMENT sp = zr_sp; - sp.atr = base_atr_on; for (*vp++ = zr_sp; (vp - vbuf) & 7; ) *vp++ = zr_sp; vp[-1].atr |= base_atr_off; diff --git a/Src/Zle/zle_thingy.c b/Src/Zle/zle_thingy.c index f712e1750..03e73b4ca 100644 --- a/Src/Zle/zle_thingy.c +++ b/Src/Zle/zle_thingy.c @@ -394,9 +394,13 @@ bin_zle_list(UNUSED(char *name), char **args, Options ops, UNUSED(char func)) Thingy t; for (; *args && !ret; args++) { - if (!(t = (Thingy) thingytab->getnode2(thingytab, *args)) || + HashNode hn = thingytab->getnode2(thingytab, *args); + if (!(t = (Thingy) hn) || (!OPT_ISSET(ops,'a') && (t->widget->flags & WIDGET_INT))) ret = 1; + else if (OPT_ISSET(ops,'L')) { + scanlistwidgets(hn, 1); + } } return ret; } @@ -483,6 +487,12 @@ bin_zle_keymap(char *name, char **args, UNUSED(Options ops), UNUSED(char func)) return selectkeymap(*args, 0); } +/* + * List a widget. + * If list is negative, just print the name. + * If list is 0, use abbreviated format. + * If list is positive, output as a command. + */ /**/ static void scanlistwidgets(HashNode hn, int list) diff --git a/Src/Zle/zle_tricky.c b/Src/Zle/zle_tricky.c index 8f7c2aac1..6fa887a1e 100644 --- a/Src/Zle/zle_tricky.c +++ b/Src/Zle/zle_tricky.c @@ -398,7 +398,18 @@ mod_export char *cmdstr; /**/ mod_export char *varname; -/* != 0 if we are in a subscript */ +/* + * != 0 if we are in a subscript. + * Of course, this being the completion code, you're expected to guess + * what the different numbers actually mean, but here's a cheat: + * 1: Key of an ordinary array + * 2: Key of a hash + * 3: Ummm.... this appears to be a special case of 2. After a lot + * of uncommented code looking for groups of brackets, we suddenly + * decide to set it to 2. The only upshot seems to be that compctl + * then doesn't add a matching ']' at the end, so I think it means + * there's one there already. + */ /**/ mod_export int insubscr; @@ -529,7 +540,7 @@ parambeg(char *s) * or $'...'). */ char *b = p + 1, *e = b; - int n = 0, br = 1, nest = 0; + int n = 0, br = 1; if (*b == Inbrace) { char *tb = b; @@ -541,10 +552,6 @@ parambeg(char *s) /* Ignore the possible (...) flags. */ b++, br++; n = skipparens(Inpar, Outpar, &b); - - for (tb = p - 1; tb > s && *tb != Outbrace && *tb != Inbrace; tb--); - if (tb > s && *tb == Inbrace && (tb[-1] == String || *tb == Qstring)) - nest = 1; } /* Ignore the stuff before the parameter name. */ @@ -1862,6 +1869,10 @@ get_comp_string(void) } } else if (p < curs) { if (*p == Outbrace) { + /* + * HERE: strip and remember code from last + * comma to here. + */ cant = 1; break; } @@ -1869,6 +1880,16 @@ get_comp_string(void) char *tp = p; if (!skipparens(Inbrace, Outbrace, &tp)) { + /* + * Balanced brace: skip. + * We only deal with unfinished braces, so + * something{foo<x>bar,morestuff}else + * doesn't work + * + * HERE: instead, continue, look for a comma. + * Stack tp and brace for popping when we + * find a comma at each level. + */ i += tp - p - 1; dp += tp - p - 1; p = tp - 1; @@ -1911,10 +1932,16 @@ get_comp_string(void) hascom = 1; } } else { + /* On or after the cursor position */ if (*p == Inbrace) { char *tp = p; if (!skipparens(Inbrace, Outbrace, &tp)) { + /* + * Balanced braces after the cursor. + * Could do the same with these as + * those before the cursor. + */ i += tp - p - 1; dp += tp - p - 1; p = tp - 1; @@ -1925,6 +1952,14 @@ get_comp_string(void) break; } if (p == curs) { + /* + * We've reached the cursor position. + * If there's a pending open brace at this + * point we need to stack the text. + * We've marked the bit we don't want from + * bbeg to bend, which might be a comma + * between the opening brace and us. + */ if (bbeg) { Brinfo new; int len = bend - bbeg; @@ -1954,10 +1989,23 @@ get_comp_string(void) bbeg = NULL; } if (*p == Comma) { + /* + * Comma on or after cursor. + * We set bbeg to NULL at the cursor; here + * it's being used to find the first comma + * afterwards. + */ if (!bbeg) bbeg = p; hascom = 2; } else if (*p == Outbrace) { + /* + * Closing brace on or after the cursor. + * Not sure how this can be after the cursor; + * if it was matched, wouldn't we have skipped + * over the group, and if it wasn't, surely we're + * not interested in it? + */ Brinfo new; int len; @@ -2150,10 +2198,6 @@ doexpansion(char *s, int lst, int olst, int explincmd) ss = quotename(ss, NULL); untokenize(ss); inststr(ss); -#if 0 - if (olst != COMP_EXPAND_COMPLETE || nonempty(vl) || - (zlemetacs && zlemetaline[zlemetacs-1] != '/')) { -#endif if (nonempty(vl) || !first) { spaceinline(1); zlemetaline[zlemetacs++] = ' '; |