From c82ce14950c327d45fe8a1dfece0f883a420641a Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 11 Mar 2016 22:18:11 +0000 Subject: 38135: internal: bin_compadd: Add a few comments. --- Src/Zle/complete.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'Src/Zle/complete.c') diff --git a/Src/Zle/complete.c b/Src/Zle/complete.c index ee4e5b0a5..30fab541a 100644 --- a/Src/Zle/complete.c +++ b/Src/Zle/complete.c @@ -704,15 +704,18 @@ bin_compadd(char *name, char **argv, UNUSED(Options ops), UNUSED(int func)) } if (sp) { if (p[1]) { + /* Pasted argument: -Xfoo. */ if (!*sp) *sp = p + 1; p = "" - 1; } else if (argv[1]) { + /* Argument in a separate word: -X foo. */ argv++; if (!*sp) *sp = *argv; p = "" - 1; } else { + /* Missing argument: argv[N] == "-X", argv[N+1] == NULL. */ zwarnnam(name, e, *p); zsfree(mstr); return 1; -- cgit v1.2.3 From e83489fc4ba168abeb5ea7e23e64383fed181ed3 Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Wed, 22 Jun 2016 01:37:07 +0200 Subject: 38714: add x: syntax to match specs to make it possible to disable match specs hardcoded in completion functions --- ChangeLog | 4 ++++ Doc/Zsh/compsys.yo | 5 +++-- Doc/Zsh/compwid.yo | 7 +++++++ Src/Zle/complete.c | 10 ++++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) (limited to 'Src/Zle/complete.c') diff --git a/ChangeLog b/ChangeLog index 3c722b79d..d352067e7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2016-06-22 Oliver Kiddle + * 38714: Src/Zle/complete.c, Doc/Zsh/compsys.yo, + Doc/Zsh/compwid.yo: add x: syntax to match specs to make it + possible to disable match specs hardcoded in completion functions + * 38735: Completion/Unix/Command/_find, Completion/Zsh/Type/_globquals: support verbose style to allow clearer but less compact descriptions for time specifiers diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index c97f80f27..fb0abcef3 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -2023,8 +2023,9 @@ only be performed with the `tt(*)' inserted. kindex(matcher, completion style) item(tt(matcher))( This style is tested separately for each tag valid in the current -context. Its value is tried before any match specifications given by the -tt(matcher-list) style. It should be in the form described in +context. Its value is placed before any match specifications given by the +tt(matcher-list) style so can override them via the use of an tt(x:) +specification. The value should be in the form described in ifzman(the section `Completion Matching Control' in zmanref(zshcompwid))\ ifnzman(noderef(Completion Matching Control))\ . For examples of this, see the description of the tt(tag-order) style. diff --git a/Doc/Zsh/compwid.yo b/Doc/Zsh/compwid.yo index c01763316..1cc94bf95 100644 --- a/Doc/Zsh/compwid.yo +++ b/Doc/Zsh/compwid.yo @@ -913,6 +913,13 @@ line and trial completion patterns are anchored on the right side. Here an empty var(ranchor) and the tt(e) and tt(E) forms force the match to the end of the command line or trial completion string. ) +item(tt(x:))( +This form is used to mark the end of matching specifications: +subsequent specifications are ignored. In a single standalone list +of specifications this has no use but where matching specifications +are accumulated, such as from nested function calls, it can allow one +function to override another. +) enditem() Each var(lpat), var(tpat) or var(anchor) is either an empty string or diff --git a/Src/Zle/complete.c b/Src/Zle/complete.c index 30fab541a..0c14d86d5 100644 --- a/Src/Zle/complete.c +++ b/Src/Zle/complete.c @@ -241,6 +241,7 @@ parse_cmatcher(char *name, char *s) case 'E': fl2 = CMF_INTER; case 'R': fl = CMF_RIGHT | CMF_LINE; break; case 'M': fl = CMF_LINE; break; + case 'x': break; default: if (name) zwarnnam(name, "unknown match specification character `%c'", @@ -252,6 +253,15 @@ parse_cmatcher(char *name, char *s) zwarnnam(name, "missing `:'"); return pcm_err; } + if (*s == 'x') { + if (s[2] && !inblank(s[2])) { + if (name) + zwarnnam(name, + "unexpected pattern following x: specification"); + return pcm_err; + } + return ret; + } s += 2; if (!*s) { if (name) -- cgit v1.2.3 From 02bb3de2575aca2b0e823b96d8281c89a77eba42 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 4 Sep 2016 21:14:52 +0000 Subject: unposted: internals: Document zshcompwid(1) parameter implementations. --- ChangeLog | 5 +++++ Src/Zle/comp.h | 4 ++-- Src/Zle/complete.c | 20 +++++++++++++++++++- 3 files changed, 26 insertions(+), 3 deletions(-) (limited to 'Src/Zle/complete.c') diff --git a/ChangeLog b/ChangeLog index 1241789de..b6f4836d7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-09-04 Daniel Shahaf + + * unposted: Src/Zle/comp.h, Src/Zle/complete.c: internals: + Document zshcompwid(1) parameter implementations. + 2016-09-03 Oliver Kiddle * Marko Myllynen: 39158: Completion/Unix/Command/_libvirt: diff --git a/Src/Zle/comp.h b/Src/Zle/comp.h index 023c41814..dfac35cfb 100644 --- a/Src/Zle/comp.h +++ b/Src/Zle/comp.h @@ -367,7 +367,7 @@ typedef void (*CLPrintFunc)(Cmgroup, Cmatch *, int, int, int, int); #define CP_QISUFFIX (1 << CPN_QISUFFIX) #define CPN_COMPSTATE 9 #define CP_COMPSTATE (1 << CPN_COMPSTATE) - +/* See comprpms */ #define CP_REALPARAMS 10 #define CP_ALLREALS ((unsigned int) 0x3ff) @@ -424,7 +424,7 @@ typedef void (*CLPrintFunc)(Cmgroup, Cmatch *, int, int, int, int); #define CP_QUOTES (1 << CPN_QUOTES) #define CPN_IGNORED 25 #define CP_IGNORED (1 << CPN_IGNORED) - +/* See compkpms */ #define CP_KEYPARAMS 26 #define CP_ALLKEYS ((unsigned int) 0x3ffffff) diff --git a/Src/Zle/complete.c b/Src/Zle/complete.c index 0c14d86d5..b28b95ef9 100644 --- a/Src/Zle/complete.c +++ b/Src/Zle/complete.c @@ -72,8 +72,26 @@ char *compiprefix, *compoldins, *compvared; +/* + * An array of Param structures for compsys special parameters; + * see 'comprparams' below. An entry for $compstate is added + * by makecompparams(). + * + * See CP_REALPARAMS. + */ + +/**/ +Param *comprpms; + +/* + * An array of Param structures for elemens of $compstate; see + * 'compkparams' below. + * + * See CP_KEYPARAMS. + */ + /**/ -Param *comprpms, *compkpms; +Param *compkpms; /**/ mod_export void -- cgit v1.2.3 From fe3a63fa6cdffa020e380d3e27cf0eb8f3b46b1f Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Tue, 6 Sep 2016 09:42:33 +0100 Subject: 39181: Add PM_SINGLE and use for compstate. This flags that compstate (or any other special) can only have a single instance and an attempt to create a new one is an error. Given the very fiddly semantics of compstate any other usage seems pointless. No investigation yet of other variables that could use this. Note it's still possible to hide such variables; only instances that keep the special nature are affected. --- ChangeLog | 5 +++++ Src/Zle/complete.c | 5 +++-- Src/builtin.c | 4 ++++ Src/zsh.h | 1 + 4 files changed, 13 insertions(+), 2 deletions(-) (limited to 'Src/Zle/complete.c') diff --git a/ChangeLog b/ChangeLog index 341555f9d..618a45e43 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-09-06 Peter Stephenson + + * 39181: Src/builtin.c, Src/zsh.h, Src/Zle/complete.c: Add + PM_SINGLE for single instance and use for compstate. + 2016-09-06 Marko Myllynen * 39179 (plus tweak): Completion/Unix/Command/_libvirt: More diff --git a/Src/Zle/complete.c b/Src/Zle/complete.c index b28b95ef9..4bf238fab 100644 --- a/Src/Zle/complete.c +++ b/Src/Zle/complete.c @@ -1238,8 +1238,9 @@ makecompparams(void) addcompparams(comprparams, comprpms); - if (!(cpm = createparam(COMPSTATENAME, - PM_SPECIAL|PM_REMOVABLE|PM_LOCAL|PM_HASHED))) + if (!(cpm = createparam( + COMPSTATENAME, + PM_SPECIAL|PM_REMOVABLE|PM_SINGLE|PM_LOCAL|PM_HASHED))) cpm = (Param) paramtab->getnode(paramtab, COMPSTATENAME); DPUTS(!cpm, "param not set in makecompparams"); diff --git a/Src/builtin.c b/Src/builtin.c index da453000c..3b82c9e7f 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -2266,6 +2266,10 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func), zerrnam(cname, "%s: restricted", pname); return pm; } + if (pm->node.flags & PM_SINGLE) { + zerrnam(cname, "%s: can only have a single instance", pname); + return pm; + } /* * For specials, we keep the same struct but zero everything. * Maybe it would be easier to create a new struct but copy diff --git a/Src/zsh.h b/Src/zsh.h index 36fddd000..87e6a9868 100644 --- a/Src/zsh.h +++ b/Src/zsh.h @@ -1792,6 +1792,7 @@ struct tieddata { #define PM_ZSHSTORED (1<<18) /* function stored in zsh form */ /* Remaining flags do not correspond directly to command line arguments */ +#define PM_SINGLE (1<<20) /* special can only have a single instance */ #define PM_LOCAL (1<<21) /* this parameter will be made local */ #define PM_SPECIAL (1<<22) /* special builtin parameter */ #define PM_DONTIMPORT (1<<23) /* do not import this variable */ -- 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/complete.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 952e607395ffd7e7592227344139e611854cf2c8 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 1 Nov 2016 17:26:09 +0000 Subject: 39803: internal: Document bin_compadd(). --- ChangeLog | 2 ++ Src/Zle/complete.c | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) (limited to 'Src/Zle/complete.c') diff --git a/ChangeLog b/ChangeLog index 63b9342c1..c761eb2c2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2016-11-03 Daniel Shahaf + * 39803: Src/Zle/complete.c: internal: Document bin_compadd(). + * 39802: Src/Zle/compcore.c, Src/Zle/complete.c: internal: Document and simplify multiquote(). diff --git a/Src/Zle/complete.c b/Src/Zle/complete.c index 73619347c..484754bee 100644 --- a/Src/Zle/complete.c +++ b/Src/Zle/complete.c @@ -555,8 +555,8 @@ static int bin_compadd(char *name, char **argv, UNUSED(Options ops), UNUSED(int func)) { struct cadata dat; - char *p, **sp, *e, *m = NULL, *mstr = NULL; - int dm; + char *mstr = NULL; /* argument of -M options, accumulated */ + int added; /* return value */ Cmatcher match = NULL; if (incompfunc != 1) { @@ -572,14 +572,16 @@ bin_compadd(char *name, char **argv, UNUSED(Options ops), UNUSED(int func)) dat.dummies = -1; for (; *argv && **argv == '-'; argv++) { + char *p; /* loop variable, points into argv */ if (!(*argv)[1]) { argv++; break; } for (p = *argv + 1; *p; p++) { - sp = NULL; - e = NULL; - dm = 0; + char *m = NULL; /* argument of -M option (this one only) */ + char **sp = NULL; /* the argument to an option should be copied + to *sp. */ + const char *e; /* error message */ switch (*p) { case 'q': dat.flags |= CMF_REMOVE; @@ -661,7 +663,6 @@ bin_compadd(char *name, char **argv, UNUSED(Options ops), UNUSED(int func)) case 'M': sp = &m; e = "matching specification expected after -%c"; - dm = 1; break; case 'X': sp = &(dat.exp); @@ -748,14 +749,13 @@ bin_compadd(char *name, char **argv, UNUSED(Options ops), UNUSED(int func)) zsfree(mstr); return 1; } - if (dm) { + if (m) { if (mstr) { char *tmp = tricat(mstr, " ", m); zsfree(mstr); mstr = tmp; } else mstr = ztrdup(m); - m = NULL; } } } @@ -774,10 +774,10 @@ bin_compadd(char *name, char **argv, UNUSED(Options ops), UNUSED(int func)) return 1; dat.match = match = cpcmatcher(match); - dm = addmatches(&dat, argv); + added = addmatches(&dat, argv); freecmatcher(match); - return dm; + return added; } #define CVT_RANGENUM 0 -- cgit v1.2.3 From b4d5a55b39399e391132fb15cc47533cc2547991 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 1 Nov 2016 17:26:10 +0000 Subject: 39804: internal: Document matchspec flags. --- ChangeLog | 3 +++ Src/Zle/comp.h | 6 ++++++ Src/Zle/complete.c | 8 ++++---- 3 files changed, 13 insertions(+), 4 deletions(-) (limited to 'Src/Zle/complete.c') diff --git a/ChangeLog b/ChangeLog index c761eb2c2..f2ec7cc25 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2016-11-03 Daniel Shahaf + * 39804: Src/Zle/comp.h, Src/Zle/complete.c: internal: Document + matchspec flags. + * 39803: Src/Zle/complete.c: internal: Document bin_compadd(). * 39802: Src/Zle/compcore.c, Src/Zle/complete.c: internal: diff --git a/Src/Zle/comp.h b/Src/Zle/comp.h index dfac35cfb..14af6173c 100644 --- a/Src/Zle/comp.h +++ b/Src/Zle/comp.h @@ -160,9 +160,15 @@ struct cmatcher { int ralen; /* length of right anchor */ }; +/* Flags for cmatcher::flags */ +/* Upon match, insert the string from the line rather than the string + * from the trial completion ("word"). */ #define CMF_LINE 1 +/* Match with an anchor on the left. */ #define CMF_LEFT 2 +/* Match with an anchor on the right. */ #define CMF_RIGHT 4 +/* ... */ #define CMF_INTER 8 /* diff --git a/Src/Zle/complete.c b/Src/Zle/complete.c index 484754bee..7980518b7 100644 --- a/Src/Zle/complete.c +++ b/Src/Zle/complete.c @@ -249,14 +249,14 @@ parse_cmatcher(char *name, char *s) if (!*s) break; switch (*s) { - case 'b': fl2 = CMF_INTER; + case 'b': fl2 = CMF_INTER; /* FALLTHROUGH */ case 'l': fl = CMF_LEFT; break; - case 'e': fl2 = CMF_INTER; + case 'e': fl2 = CMF_INTER; /* FALLTHROUGH */ case 'r': fl = CMF_RIGHT; break; case 'm': fl = 0; break; - case 'B': fl2 = CMF_INTER; + case 'B': fl2 = CMF_INTER; /* FALLTHROUGH */ case 'L': fl = CMF_LEFT | CMF_LINE; break; - case 'E': fl2 = CMF_INTER; + case 'E': fl2 = CMF_INTER; /* FALLTHROUGH */ case 'R': fl = CMF_RIGHT | CMF_LINE; break; case 'M': fl = CMF_LINE; break; case 'x': break; -- cgit v1.2.3