Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: playing with backreferences in list-colors
- X-seq: zsh-workers 9419
- From: Alexandre Duret-Lutz <duret_g@xxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxxx
- Subject: Re: playing with backreferences in list-colors
- Date: 24 Jan 2000 16:07:31 +0100
- In-reply-to: Sven Wischnowsky's message of "Mon, 24 Jan 2000 10:54:43 +0100 (MET)"
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
- References: <200001240954.KAA09754@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>
After 9408 and 9416, I have still some problems :
1) listcolor stop colorization on the first (-1,-1) backref,
even if there are valid backrefs after.
2) colorization of enclosed backrefs are wrongs.
Let's say O denotes color for the outer block, I the inner color,
N means no color. And I am matching over a 8 letter string.
((??)??)* -> OOOONNNN
(?(??)?)* -> 0IIIONNN
(??(??))* -> OOIIONNN
I expect the patch below to fix these two points. Sorting the
end positions was needed to fix this second point (at least I
didn't find any better way to do that).
The test `endpos[curisbeg] < begpos[curisbeg]' of the patch
is there to handle cases like :
~ % [[ fbar = (#b)f((o)#)bar ]]
~ % echo $mbegin / $mend
2 -1 / 1 -1
where the outer backref matched the empty string
(empty strings don't need to be colored, I think).
Index: Src/Zle/complist.c
--- Src/Zle/complist.c Mon, 24 Jan 2000 13:43:41 +0100 Alexandre
+++ Src/Zle/complist.c Mon, 24 Jan 2000 15:25:07 +0100 Alexandre
@@ -391,7 +391,8 @@
static int nrefs;
static int begpos[MAX_POS], curisbeg;
-static int endpos[MAX_POS], curisend;
+static int endpos[MAX_POS];
+static int sendpos[MAX_POS], curissend; /* sorted end positions */
static char **patcols, *curiscols[MAX_POS];
static int curiscol;
@@ -450,29 +451,45 @@
curiscols[curiscol = 0] = *patcols++;
- curisbeg = curisend = 0;
+ curisbeg = curissend = 0;
- for (i = nrefs; i < MAX_POS; i++)
- begpos[i] = endpos[i] = -1;
+ for (i = 0; i < nrefs; i++)
+ sendpos[i] = 0xfffffff;
+ for (; i < MAX_POS; i++)
+ begpos[i] = endpos[i] = sendpos[i] = 0xfffffff;
}
static void
doiscol(Listcols c, int pos)
{
- if (endpos[curisend] >= 0 && pos > endpos[curisend]) {
- curisend++;
+ int fi;
+
+ while (pos > sendpos[curissend]) {
+ curissend++;
if (curiscol) {
zcputs(c, NULL, COL_NO);
zlrputs(c, curiscols[--curiscol]);
}
}
- if (pos == begpos[curisbeg] && *patcols) {
- curisbeg++;
-
- zcputs(c, NULL, COL_NO);
- zlrputs(c, *patcols);
-
- curiscols[++curiscol] = *patcols++;
+ while (((fi = (endpos[curisbeg] < begpos[curisbeg] ||
+ begpos[curisbeg] == -1)) ||
+ pos == begpos[curisbeg]) && *patcols) {
+ if (!fi) {
+ int i, j, e = endpos[curisbeg];
+
+ /* insert e in sendpos */
+ for (i = curissend; sendpos[i] <= e; ++i)
+ ;
+ for (j = i + 1; j < MAX_POS; ++j)
+ sendpos[j] = sendpos[j-1];
+ sendpos[i] = e;
+
+ zcputs(c, NULL, COL_NO);
+ zlrputs(c, *patcols);
+ curiscols[++curiscol] = *patcols;
+ }
+ ++patcols;
+ ++curisbeg;
}
}
--
Alexandre Duret-Lutz
Messages sorted by:
Reverse Date,
Date,
Thread,
Author