* Re: compctl -y problem.
2001-05-25 15:11 ` compctl -y problem Bart Schaefer
@ 2001-05-25 16:35 ` Bart Schaefer
2001-05-28 11:39 ` Sven Wischnowsky
1 sibling, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 2001-05-25 16:35 UTC (permalink / raw)
To: zsh-workers; +Cc: Cesar Crusius
(Part of this thread went to zsh-workers ... returning now to zsh-users
with a workaround)
On May 25, 3:11pm, Bart Schaefer wrote:
}
} I know Sven won't be thrilled about being asked to fix anything in the
} old compctl code ... perhaps we should just remove the `-y' option, as
} it's new since 3.0 anyway, and document the correct way to achieve the
} same effect by using the new completion system (which, incidentally, I
} don't know how to do ... `compadd -d' doesn't quite cut it).
On further reading of the compadd doc, `compadd -ld ...' appears to be
the thing to do, though it's a bit convoluted.
autoload -U compinit
compinit
function _aecd {
local change_descriptions reply
# Force change_descriptions to be a one-element array
change_descriptions=("$(aereport changes -unf | grep -v completed)")
# The name "reply" is not special here, I just happened to use it
reply=($(aereport changes -terse | grep -v completed | sed -e 's/ .*$//'))
# Display the change_descriptions in place of the first completion
compadd -ld change_descriptions $reply[1]
# Add the rest of the completions, but don't display them in the list
compadd -na 'reply[2,-1]'
# Force the list to appear so the descriptions are visible
compstate[list]='list force'
}
compdef _aecd aecd
It does appear that "compadd -d" still produces a sub-optimal display in
this case if there are any lines in $change_descriptions that have exactly
$COLUMNS characters; but it properly returns the cursor to the right spot
even so.
I don't know what the output of `aereport changes` looks like, so it may
be that there's a simpler solution. For example, if the same number of
lines will be returned by `aereport changes -unf` and `... -terse`, this
will work:
function _aecd {
local change_descriptions reply
change_descriptions=(${(f)"$(aereport changes -unf | grep -v completed)"})
reply=($(aereport changes -terse | grep -v completed | sed -e 's/ .*$//'))
compadd -ld change_descriptions -a reply
compstate[list]='list force'
}
You may also wish to drop that compstate[list] assignment and instead use
the force-list style to control it:
zstyle ':completion:*:aecd' force-list always
See the manual for more.
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: compctl -y problem.
2001-05-25 15:11 ` compctl -y problem Bart Schaefer
2001-05-25 16:35 ` Bart Schaefer
@ 2001-05-28 11:39 ` Sven Wischnowsky
1 sibling, 0 replies; 3+ messages in thread
From: Sven Wischnowsky @ 2001-05-28 11:39 UTC (permalink / raw)
To: zsh-workers
Bart Schaefer wrote:
> ...
>
> I know Sven won't be thrilled about being asked to fix anything in the
> old compctl code ...
Indeed, though the patch below seems to fix it for me.
> perhaps we should just remove the `-y' option, as
> it's new since 3.0 anyway,
I think I suggested this some time ago. It would be really nice because
currently it's the biggest piece of code dangling in the base completion
code (`complete' module) that's specific to compctl.
> and document the correct way to achieve the
> same effect by using the new completion system (which, incidentally, I
> don't know how to do ... `compadd -d' doesn't quite cut it).
You already mentioned `compadd -ld' in another mail. I prefer this a lot
because there we have a one-to-one correspondence between matches and
strings to display, meaning that things like menu selection work
properly. If there are other strings one want to have displayed
together with the list one can always use `compadd -X' or `compadd -x'.
Bye
Sven
Index: Src/Zle/compresult.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/compresult.c,v
retrieving revision 1.36
diff -u -r1.36 compresult.c
--- Src/Zle/compresult.c 2001/03/27 09:14:52 1.36
+++ Src/Zle/compresult.c 2001/05/28 11:40:13
@@ -1398,9 +1398,12 @@
if (!onlyexpl && pp) {
/* We have an ylist, lets see, if it contains newlines. */
hidden = 1;
- while (!nl && *pp)
- nl = !!strchr(*pp++, '\n');
-
+ while (!nl && *pp) {
+ if (ztrlen(*pp) >= columns)
+ nl = 1;
+ else
+ nl = !!strchr(*pp++, '\n');
+ }
pp = g->ylist;
if (nl || !pp[1]) {
/* Yup, there are newlines, count lines. */
@@ -1411,17 +1414,17 @@
while ((sptr = *pp)) {
while (sptr && *sptr) {
nlines += (nlptr = strchr(sptr, '\n'))
- ? 1 + (nlptr-sptr) / columns
- : strlen(sptr) / columns;
+ ? 1 + (nlptr - sptr - 1) / columns
+ : (ztrlen(sptr) - 1) / columns;
sptr = nlptr ? nlptr+1 : NULL;
}
nlines++;
pp++;
}
- nlines--;
+ /*** nlines--; */
} else {
while (*pp) {
- l = strlen(*pp);
+ l = ztrlen(*pp);
ndisp++;
if (l > glong)
glong = l;
@@ -1524,7 +1527,7 @@
g->width = 1;
while (*pp)
- glines += 1 + (strlen(*pp++) / columns);
+ glines += 1 + (ztrlen(*pp++) / columns);
}
}
} else {
@@ -1566,7 +1569,7 @@
VARARR(int, ylens, yl);
for (i = 0; *pp; i++, pp++)
- ylens[i] = strlen(*pp) + add;
+ ylens[i] = ztrlen(*pp) + add;
if (g->flags & CGF_ROWS) {
int count, tcol, first, maxlines = 0, llines;
@@ -1913,10 +1916,16 @@
}
}
if (g->flags & CGF_LINES) {
- while (*pp) {
- zputs(*pp, shout);
- if (*++pp)
- putc('\n', shout);
+ char *p;
+
+ while ((p = *pp++)) {
+ zputs(p, shout);
+ if (*pp) {
+ if (ztrlen(p) % columns)
+ putc('\n', shout);
+ else
+ fputs(" \010", shout);
+ }
}
} else {
int n = g->lcount, nl, nc, i, a;
--
Sven Wischnowsky wischnow@informatik.hu-berlin.de
^ permalink raw reply [flat|nested] 3+ messages in thread