Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: Re: completion in quotes - " vs ' - no suffix added
- X-seq: zsh-workers 17195
- From: Sven Wischnowsky <wischnow@xxxxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: PATCH: Re: completion in quotes - " vs ' - no suffix added
- Date: Tue, 21 May 2002 10:06:18 +0200
- In-reply-to: <15584.49227.780505.590251@xxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <15576.54689.459113.686818@xxxxxxxxxxxxxxxxxx> <6134254DE87BD411908B00A0C99B044F02E89A73@xxxxxxxxxxxxxxxxxxxxxxx> <15577.7296.682622.411849@xxxxxxxxxxxxxxxxxx> <1020508153855.ZM7837@xxxxxxxxxxxxxxxxxxxxxxx> <15583.34740.981994.404489@xxxxxxxxxxxxxxxxxx> <6134254DE87BD411908B00A0C99B044F02E89A8C@xxxxxxxxxxxxxxxxxxxxxxx> <1020513173320.ZM12360@xxxxxxxxxxxxxxxxxxxxxxx> <1021313089.2926.10.camel@xxxxxxxxxxxxxxxxxxxxx> <15584.49227.780505.590251@xxxxxxxxxxxxxxxxxx>
Sven Wischnowsky wrote:
> ...
>
> So the next steps are to get the file-type testing right. I'd like to
> do that more thoroughly to finally be able to implement this other
> thing we've been talking about, where a space as a file-type character
> (with LIST_TYPES) isn't counted to allow tighter packing of rows in
> listings.
Here is the patch for this. Also, Andrej's `zsh -c "ls dir<TAB>'
should now work ;-)
Bye
Sven
Index: Src/Zle/comp.h
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/comp.h,v
retrieving revision 1.13
diff -u -r1.13 comp.h
--- Src/Zle/comp.h 1 Mar 2002 10:42:02 -0000 1.13
+++ Src/Zle/comp.h 21 May 2002 08:05:00 -0000
@@ -92,6 +92,7 @@
struct cmatch {
char *str; /* the match itself */
+ char *orig; /* the match string unquoted */
char *ipre; /* ignored prefix, has to be re-inserted */
char *ripre; /* ignored prefix, unquoted */
char *isuf; /* ignored suffix */
@@ -111,6 +112,8 @@
int qisl; /* length of quote-suffix */
int rnum; /* group relative number */
int gnum; /* global number */
+ mode_t mode; /* mode field of a stat */
+ char modec; /* LIST_TYPE-character for mode or nul */
};
#define CMF_FILE (1<< 0) /* this is a file */
@@ -286,8 +289,7 @@
int showall; /* != 0 if hidden matches should be shown */
};
-typedef void (*CLPrintFunc)(Cmgroup, Cmatch *, int, int, int, int,
- char *, struct stat *);
+typedef void (*CLPrintFunc)(Cmgroup, Cmatch *, int, int, int, int);
/* Flags for fromcomp. */
Index: Src/Zle/compcore.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/compcore.c,v
retrieving revision 1.59
diff -u -r1.59 compcore.c
--- Src/Zle/compcore.c 21 May 2002 07:47:35 -0000 1.59
+++ Src/Zle/compcore.c 21 May 2002 08:05:00 -0000
@@ -2104,7 +2104,7 @@
for (bp = obsl; bp; bp = bp->next)
bp->curpos += bsadd;
- if ((cm = add_match_data(0, ms, lc, dat->ipre, NULL,
+ if ((cm = add_match_data(0, ms, s, lc, dat->ipre, NULL,
dat->isuf, dat->pre, dat->prpre,
dat->ppre, pline,
dat->psuf, sline,
@@ -2184,7 +2184,7 @@
/**/
mod_export Cmatch
-add_match_data(int alt, char *str, Cline line,
+add_match_data(int alt, char *str, char *orig, Cline line,
char *ipre, char *ripre, char *isuf,
char *pre, char *prpre,
char *ppre, Cline pline,
@@ -2412,6 +2412,7 @@
/* Allocate and fill the match structure. */
cm = (Cmatch) zhalloc(sizeof(struct cmatch));
cm->str = str;
+ cm->orig = dupstring(orig);
cm->ppre = (ppre && *ppre ? ppre : NULL);
cm->psuf = (psuf && *psuf ? psuf : NULL);
cm->prpre = ((flags & CMF_FILE) && prpre && *prpre ? prpre : NULL);
@@ -2430,7 +2431,22 @@
(complist ?
((strstr(complist, "packed") ? CMF_PACKED : 0) |
(strstr(complist, "rows") ? CMF_ROWS : 0)) : 0));
-
+ cm->mode = 0;
+ cm->modec = '\0';
+ if ((flags & CMF_FILE) && orig[0] && orig[strlen(orig) - 1] != '/') {
+ struct stat buf;
+ char *pb;
+
+ pb = (char *) zhalloc((cm->prpre ? strlen(cm->prpre) : 0) +
+ 3 + strlen(orig));
+ sprintf(pb, "%s%s", (cm->prpre ? cm->prpre : "./"), orig);
+
+ if (!ztat(pb, &buf, 1)) {
+ cm->mode = buf.st_mode;
+ if ((cm->modec = file_type(buf.st_mode)) == ' ')
+ cm->modec = '\0';
+ }
+ }
if ((*compqstack == '\\' && compqstack[1]) ||
(autoq && *compqstack && compqstack[1] == '\\'))
cm->flags |= CMF_NOSPACE;
@@ -2803,6 +2819,7 @@
r = (Cmatch) zcalloc(sizeof(struct cmatch));
r->str = ztrdup(m->str);
+ r->orig = ztrdup(m->orig);
r->ipre = ztrdup(m->ipre);
r->ripre = ztrdup(m->ripre);
r->isuf = ztrdup(m->isuf);
@@ -2836,6 +2853,8 @@
r->qipl = m->qipl;
r->qisl = m->qisl;
r->disp = ztrdup(m->disp);
+ r->mode = m->mode;
+ r->modec = m->modec;
return r;
}
@@ -2994,6 +3013,7 @@
if (!m) return;
zsfree(m->str);
+ zsfree(m->orig);
zsfree(m->ipre);
zsfree(m->ripre);
zsfree(m->isuf);
Index: Src/Zle/compctl.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/compctl.c,v
retrieving revision 1.12
diff -u -r1.12 compctl.c
--- Src/Zle/compctl.c 22 Jan 2002 10:22:48 -0000 1.12
+++ Src/Zle/compctl.c 21 May 2002 08:05:00 -0000
@@ -2025,7 +2025,7 @@
}
if (!ms)
return;
- add_match_data(isalt, ms, lc, ipre, ripre, isuf,
+ add_match_data(isalt, ms, s, lc, ipre, ripre, isuf,
(incompfunc ? dupstring(curcc->prefix) : curcc->prefix),
prpre,
(isfile ? lppre : NULL), NULL,
Index: Src/Zle/complist.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/complist.c,v
retrieving revision 1.45
diff -u -r1.45 complist.c
--- Src/Zle/complist.c 22 Jan 2002 10:22:48 -0000 1.45
+++ Src/Zle/complist.c 21 May 2002 08:05:00 -0000
@@ -1199,7 +1199,7 @@
mfirstl = ml;
if (dolist(ml))
printed++;
- if (clprintm(g, p, 0, ml, 1, 0, NULL, NULL))
+ if (clprintm(g, p, 0, ml, 1, 0))
goto end;
ml += mlprinted;
if (dolistcl(ml) && (cl -= mlprinted) <= 1) {
@@ -1250,26 +1250,12 @@
while (n && i--) {
wid = (g->widths ? g->widths[mc] : g->width);
if (!(m = *q)) {
- if (clprintm(g, NULL, mc, ml, (!i), wid, NULL, NULL))
+ if (clprintm(g, NULL, mc, ml, (!i), wid))
goto end;
break;
}
- if (!m->disp && (m->flags & CMF_FILE) &&
- m->str[0] && m->str[strlen(m->str) - 1] != '/') {
- struct stat buf;
- char *pb;
-
- pb = (char *) zhalloc((m->prpre ? strlen(m->prpre) : 0) +
- 3 + strlen(m->str));
- sprintf(pb, "%s%s", (m->prpre ? m->prpre : "./"),
- m->str);
-
- if (ztat(pb, &buf, 1) ?
- clprintm(g, q, mc, ml, (!i), wid, NULL, NULL) :
- clprintm(g, q, mc, ml, (!i), wid, pb, &buf))
- goto end;
- } else if (clprintm(g, q, mc, ml, (!i), wid, NULL, NULL))
- goto end;
+ if (clprintm(g, q, mc, ml, (!i), wid))
+ goto end;
if (dolist(ml))
printed++;
@@ -1290,8 +1276,7 @@
}
while (i-- > 0) {
if (clprintm(g, NULL, mc, ml, (!i),
- (g->widths ? g->widths[mc] : g->width),
- NULL, NULL))
+ (g->widths ? g->widths[mc] : g->width)))
goto end;
mc++;
}
@@ -1366,8 +1351,7 @@
/**/
static int
-clprintm(Cmgroup g, Cmatch *mp, int mc, int ml, int lastc, int width,
- char *path, struct stat *buf)
+clprintm(Cmgroup g, Cmatch *mp, int mc, int ml, int lastc, int width)
{
Cmatch m;
int len, subcols = 0, stop = 0, ret = 0;
@@ -1467,8 +1451,8 @@
zcputs(&mcolors, g->name, COL_HI);
else if (mselect >= 0 && (m->flags & (CMF_MULT | CMF_FMULT)))
zcputs(&mcolors, g->name, COL_DU);
- else if (buf)
- subcols = putfilecol(&mcolors, g->name, m->str, buf->st_mode);
+ else if (m->mode)
+ subcols = putfilecol(&mcolors, g->name, m->str, m->mode);
else
subcols = putmatchcol(&mcolors, g->name, (m->disp ? m->disp : m->str));
@@ -1483,12 +1467,12 @@
len = niceztrlen(m->disp ? m->disp : m->str);
mlprinted = len / columns;
- if ((g->flags & CGF_FILES) && buf) {
+ if ((g->flags & CGF_FILES) && m->modec) {
if (m->gnum != mselect) {
zcoff();
zcputs(&mcolors, g->name, COL_TC);
}
- putc(file_type(buf->st_mode), shout);
+ putc(m->modec, shout);
len++;
}
if ((len = width - len - 2) > 0) {
Index: Src/Zle/compresult.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/compresult.c,v
retrieving revision 1.43
diff -u -r1.43 compresult.c
--- Src/Zle/compresult.c 22 Jan 2002 10:22:48 -0000 1.43
+++ Src/Zle/compresult.c 21 May 2002 08:05:00 -0000
@@ -30,6 +30,10 @@
#include "complete.mdh"
#include "compresult.pro"
+/* The number of columns to leave empty between rows of matches. */
+
+#define CM_SPACE 2
+
/* This counts how often the list of completions was invalidated.
* Can be used to detect if we have a new list. */
@@ -929,7 +933,7 @@
int l, sr = 0, scs;
int havesuff = 0;
int partest = (m->ripre || ((m->flags & CMF_ISPAR) && parpre));
- char *str = m->str, *ppre = m->ppre, *psuf = m->psuf, *prpre = m->prpre;
+ char *str = m->orig, *ppre = m->ppre, *psuf = m->psuf, *prpre = m->prpre;
if (!prpre) prpre = "";
if (!ppre) ppre = "";
@@ -1380,7 +1384,7 @@
Cmgroup g;
Cmatch *p, m;
Cexpl *e;
- int hidden = 0, nlist = 0, nlines = 0, add;
+ int hidden = 0, nlist = 0, nlines = 0;
int max = 0, i;
VARARR(int, mlens, nmatches + 1);
@@ -1474,7 +1478,7 @@
if (!(m->flags & CMF_ROWS))
g->flags &= ~CGF_ROWS;
} else {
- l = niceztrlen(m->str);
+ l = niceztrlen(m->str) + !!m->modec;
ndisp++;
if (l > glong)
glong = l;
@@ -1503,19 +1507,16 @@
e++;
}
}
- if (isset(LISTTYPES) && hasf) {
+ if (isset(LISTTYPES) && hasf)
g->flags |= CGF_FILES;
- add = 3;
- } else
- add = 2;
- g->totl = totl + (ndisp * add);
+ g->totl = totl + (ndisp * CM_SPACE);
g->dcount = ndisp;
- g->width = glong + add;
- g->shortest = gshort + add;
+ g->width = glong + CM_SPACE;
+ g->shortest = gshort + CM_SPACE;
if ((g->cols = columns / g->width) > g->dcount)
g->cols = g->dcount;
if (g->cols) {
- i = g->cols * g->width - add;
+ i = g->cols * g->width - CM_SPACE;
if (i > max)
max = i;
}
@@ -1525,7 +1526,6 @@
int *ws, tlines, tcols, width, glines;
for (g = amatches; g; g = g->next) {
- add = 2 + !!(g->flags & CGF_FILES);
glines = 0;
zfree(g->widths, 0);
@@ -1536,7 +1536,8 @@
if (g->cols) {
glines += (arrlen(pp) + g->cols - 1) / g->cols;
if (g->cols > 1)
- g->width += ((max - (g->width * g->cols - add)) /
+ g->width += ((max - (g->width * g->cols -
+ CM_SPACE)) /
g->cols);
} else {
g->cols = 1;
@@ -1550,7 +1551,8 @@
if (g->cols) {
glines += (g->dcount + g->cols - 1) / g->cols;
if (g->cols > 1)
- g->width += (max - (g->width * g->cols - add)) / g->cols;
+ g->width += ((max - (g->width * g->cols - CM_SPACE)) /
+ g->cols);
} else if (!(g->flags & CGF_LINES)) {
g->cols = 1;
g->width = 0;
@@ -1573,8 +1575,6 @@
if (!(g->flags & CGF_PACKED))
continue;
- add = 2 + !!(g->flags & CGF_FILES);
-
ws = g->widths = (int *) zalloc(columns * sizeof(int));
memset(ws, 0, columns * sizeof(int));
tlines = g->lins;
@@ -1587,12 +1587,13 @@
VARARR(int, ylens, yl);
for (i = 0; *pp; i++, pp++)
- ylens[i] = ztrlen(*pp) + add;
+ ylens[i] = ztrlen(*pp) + CM_SPACE;
if (g->flags & CGF_ROWS) {
int nth, tcol, len;
- for (tcols = columns / (g->shortest + add); tcols > g->cols;
+ for (tcols = columns / (g->shortest + CM_SPACE);
+ tcols > g->cols;
tcols--) {
memset(ws, 0, tcols * sizeof(int));
@@ -1620,7 +1621,8 @@
} else {
int nth, tcol, tline, len;
- for (tcols = columns / (g->shortest + add); tcols > g->cols;
+ for (tcols = columns / (g->shortest + CM_SPACE);
+ tcols > g->cols;
tcols--) {
if ((tlines = (g->dcount + tcols - 1) / tcols) <= 0)
@@ -1658,7 +1660,8 @@
if (g->flags & CGF_ROWS) {
int nth, tcol, len;
- for (tcols = columns / (g->shortest + add); tcols > g->cols;
+ for (tcols = columns / (g->shortest + CM_SPACE);
+ tcols > g->cols;
tcols--) {
memset(ws, 0, tcols * sizeof(int));
@@ -1675,7 +1678,7 @@
tlines++;
}
len = (mlens[m->gnum] +
- (tcol == tcols - 1 ? 0 : add));
+ (tcol == tcols - 1 ? 0 : CM_SPACE));
if (len > ws[tcol]) {
width += len - ws[tcol];
@@ -1688,7 +1691,8 @@
} else {
int nth, tcol, tline, len;
- for (tcols = columns / (g->shortest + add); tcols > g->cols;
+ for (tcols = columns / (g->shortest + CM_SPACE);
+ tcols > g->cols;
tcols--) {
if ((tlines = (g->dcount + tcols - 1) / tcols) <= 0)
@@ -1712,7 +1716,7 @@
tlines++;
}
len = (mlens[m->gnum] +
- (tcol == tcols - 1 ? 0 : add));
+ (tcol == tcols - 1 ? 0 : CM_SPACE));
if (len > ws[tcol]) {
width += len - ws[tcol];
@@ -1737,20 +1741,19 @@
g->lins = tlines;
g->cols = tcols;
g->totl = width;
- width -= add;
+ width -= CM_SPACE;
if (width > max)
max = width;
}
}
for (g = amatches; g; g = g->next) {
- add = 2 + !!(g->flags & CGF_FILES);
if (g->widths) {
- int *p, a = (max - g->totl + add) / g->cols;
+ int *p, a = (max - g->totl + CM_SPACE) / g->cols;
for (i = g->cols, p = g->widths; i; i--, p++)
*p += a;
} else if (g->width && g->cols > 1)
- g->width += (max - (g->width * g->cols - add)) / g->cols;
+ g->width += (max - (g->width * g->cols - CM_SPACE)) / g->cols;
}
}
listdat.valid = 1;
@@ -1949,7 +1952,7 @@
}
}
printed++;
- printm(g, p, 0, ml, 1, 0, NULL, NULL);
+ printm(g, p, 0, ml, 1, 0);
pnl = 1;
}
}
@@ -1970,25 +1973,10 @@
while (n && i--) {
wid = (g->widths ? g->widths[mc] : g->width);
if (!(m = *q)) {
- printm(g, NULL, mc, ml, (!i), wid, NULL, NULL);
+ printm(g, NULL, mc, ml, (!i), wid);
break;
}
- if (!m->disp && (m->flags & CMF_FILE) &&
- m->str[0] && m->str[strlen(m->str) - 1] != '/') {
- struct stat buf;
- char *pb;
-
- pb = (char *) zhalloc((m->prpre ? strlen(m->prpre) : 0) +
- 3 + strlen(m->str));
- sprintf(pb, "%s%s", (m->prpre ? m->prpre : "./"),
- m->str);
-
- if (ztat(pb, &buf, 1))
- printm(g, q, mc, ml, (!i), wid, NULL, NULL);
- else
- printm(g, q, mc, ml, (!i), wid, pb, &buf);
- } else
- printm(g, q, mc, ml, (!i), wid, NULL, NULL);
+ printm(g, q, mc, ml, (!i), wid);
printed++;
@@ -2000,7 +1988,7 @@
}
while (i-- > 0) {
printm(g, NULL, mc, ml, (!i),
- (g->widths ? g->widths[mc] : g->width), NULL, NULL);
+ (g->widths ? g->widths[mc] : g->width));
mc++;
}
if (n) {
@@ -2091,8 +2079,7 @@
/**/
static void
-iprintm(Cmgroup g, Cmatch *mp, int mc, int ml, int lastc, int width,
- char *path, struct stat *buf)
+iprintm(Cmgroup g, Cmatch *mp, int mc, int ml, int lastc, int width)
{
Cmatch m;
int len = 0;
@@ -2114,8 +2101,8 @@
nicezputs(m->str, shout);
len = niceztrlen(m->str);
- if ((g->flags & CGF_FILES) && buf) {
- putc(file_type(buf->st_mode), shout);
+ if ((g->flags & CGF_FILES) && m->modec) {
+ putc(m->modec, shout);
len++;
}
}
--
Sven Wischnowsky wischnow@xxxxxxxxx
Messages sorted by:
Reverse Date,
Date,
Thread,
Author