From: Sven Wischnowsky <wischnow@informatik.hu-berlin.de>
To: zsh-workers@sunsite.auc.dk
Subject: PATCH: completion funcs (was: Re: Problems with _arguments)
Date: Wed, 20 Oct 1999 15:27:07 +0200 (MET DST) [thread overview]
Message-ID: <199910201327.PAA01571@beta.informatik.hu-berlin.de> (raw)
In-Reply-To: "Andrej Borsenkow"'s message of Fri, 15 Oct 1999 19:06:35 +0400
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
reply other threads:[~1999-10-20 20:42 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=199910201327.PAA01571@beta.informatik.hu-berlin.de \
--to=wischnow@informatik.hu-berlin.de \
--cc=zsh-workers@sunsite.auc.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).