* PATCH: completion funcs (was: Re: Problems with _arguments)
@ 1999-10-20 13:27 Sven Wischnowsky
0 siblings, 0 replies; only message in thread
From: Sven Wischnowsky @ 1999-10-20 13:27 UTC (permalink / raw)
To: zsh-workers
Andrej Borsenkow wrote:
> #compdef sudo
>
> _arguments \
> ... \
> '*::complete command and/or arguments:_normal'
I had this still in a test file and happened to see it again yesterday...
I think for such sub-command completion we probably should use
something like:
_arguments \
... \
':command: _command_names -e' \
'*::arguments: _normal'
This will ensure that only external commands will be completed in
command position.
Anyway, I found a little problem with my last change to `_path_files':
completion on an empty string was broken.
And I found a small bug in `computil' where it got confused about the
range of words to restrict `compwords' to. The indexes stored in the
C-code are now zero-based, hopefully making things easier to
understand.
Then there were two allocation bugs (well, one was a free() bug: the
array for the argument information for options wasn't freed). The
other one was a missing ztrdup().
Ahem.
Bye
Sven
diff -u oldsrc/Zle/computil.c Src/Zle/computil.c
--- oldsrc/Zle/computil.c Tue Oct 19 15:51:04 1999
+++ Src/Zle/computil.c Wed Oct 20 15:24:12 1999
@@ -926,6 +926,8 @@
while (i--)
if (*p++)
freelinklist(p[-1], freestr);
+
+ zfree(ca_laststate.oargs, ca_laststate.d->nopts * sizeof(LinkList));
}
for (ptr = d->opts; ptr; ptr = ptr->next)
ptr->active = 1;
@@ -1051,7 +1053,10 @@
(state.def->type == CAA_RREST ||
state.def->type == CAA_RARGS)) {
state.inrest = 0;
- state.argbeg = cur;
+ state.opt = 0;
+ state.optbeg = state.nargbeg;
+ state.argbeg = cur - 1;
+
for (; line; line = compwords[cur++]) {
PERMALLOC {
addlinknode(state.args, ztrdup(line));
@@ -1082,11 +1087,10 @@
else {
LinkList l = state.oargs[state.curopt->num];
- for (; line; line = compwords[cur++]) {
- PERMALLOC {
- addlinknode(l, line);
- } LASTALLOC;
- }
+ PERMALLOC {
+ for (; line; line = compwords[cur++])
+ addlinknode(l, ztrdup(line));
+ } LASTALLOC;
memcpy(&ca_laststate, &state, sizeof(state));
ca_laststate.ddef = NULL;
ca_laststate.doff = 0;
@@ -1103,8 +1107,8 @@
else {
ca_laststate.def = adef;
ca_laststate.ddef = NULL;
- ca_laststate.argbeg = state.nargbeg;
- ca_laststate.optbeg = state.restbeg;
+ ca_laststate.optbeg = state.nargbeg;
+ ca_laststate.argbeg = state.restbeg;
ca_laststate.singles = state.singles;
}
}
@@ -1116,21 +1120,26 @@
{
if (l) {
LinkNode n;
- int len = 1;
+ int len = 0;
char *p, *ret, *q;
- for (n = firstnode(l); n; incnode(n))
+ for (n = firstnode(l); n; incnode(n)) {
+ len++;
for (p = (char *) getdata(n); *p; p++)
len += (*p == ':' ? 2 : 1);
-
+ }
ret = q = (char *) zalloc(len);
- for (n = firstnode(l); n; incnode(n))
+ for (n = firstnode(l); n;) {
for (p = (char *) getdata(n); *p; p++) {
if (*p == ':')
*q++ = '\\';
*q++ = *p;
}
+ incnode(n);
+ if (n)
+ *q++ = ':';
+ }
*q = '\0';
return ret;
@@ -1206,10 +1215,10 @@
if (ca_laststate.doff > 0)
ignore_prefix(ca_laststate.doff);
if (arg->type == CAA_RARGS)
- restrict_range(ca_laststate.argbeg - 1,
+ restrict_range(ca_laststate.optbeg,
arrlen(compwords) - 1);
else if (arg->type == CAA_RREST)
- restrict_range(ca_laststate.optbeg - 1,
+ restrict_range(ca_laststate.argbeg,
arrlen(compwords) - 1);
return 0;
}
diff -u -r oldcompletion/Core/_path_files Completion/Core/_path_files
--- oldcompletion/Core/_path_files Mon Oct 18 13:20:37 1999
+++ Completion/Core/_path_files Wed Oct 20 08:46:29 1999
@@ -277,7 +277,7 @@
# otherwise this would keep `_files' from completing all filenames
# if none of the patterns match.
- if [[ -z "$tpre$tsuf" ]]; then
+ if [[ -z "$tpre$tsuf" && -n "$pre$suf" ]]; then
tmp1=( "$tmp2[@]" )
addsfx=(-S '')
remsfx=()
--
Sven Wischnowsky wischnow@informatik.hu-berlin.de
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~1999-10-20 20:42 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-10-20 13:27 PATCH: completion funcs (was: Re: Problems with _arguments) Sven Wischnowsky
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).