Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: Preserve $match while processing zstyles
- X-seq: zsh-workers 32468
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: PATCH: Preserve $match while processing zstyles
- Date: Sat, 08 Mar 2014 22:42:57 -0800
- In-reply-to: <140308213732.ZM9579@torch.brasslantern.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <1393780084.43996.YahooMailNeo@web194601.mail.sg3.yahoo.com> <140302121855.ZM1118@torch.brasslantern.com> <2234.1393867510@thecus.kiddle.eu> <140308213732.ZM9579@torch.brasslantern.com>
On Mar 8, 9:37pm, Bart Schaefer wrote:
}
} zstyle -e '(#b)(:completion:*)' matcher-list \
} 'zstyle -a "word-$CURRENT$match" matcher-list reply'
}
} A bit of a glitch with this is that zstyle does not save and restore
} $match et al. around its pattern lookups, but that's easily fixable
} because zregexparse already provides the necessary machinery right
} there in zutils.c where zstyle is also defined.
Here's the patch for that. I wasn't able to come up with a way to fix
the line numbers for xtrace; or rather, I suspect it means copying the
entire funcstack push/pop mechanics from builtin.c:eval(), and I didn't
feel like messing with that.
Most of this is just moving the definition of MatchData to the top of
the file so zstyle can use it. The only good bit is the rewrite of
lookupstyle() in the middle hunk.
diff --git a/Src/Modules/zutil.c b/Src/Modules/zutil.c
index 46b29f2..1cca0c4 100644
--- a/Src/Modules/zutil.c
+++ b/Src/Modules/zutil.c
@@ -30,6 +30,55 @@
#include "zutil.mdh"
#include "zutil.pro"
+typedef struct {
+ char **match;
+ char **mbegin;
+ char **mend;
+} MatchData;
+
+static void
+savematch(MatchData *m)
+{
+ char **a;
+
+ queue_signals();
+ a = getaparam("match");
+ m->match = a ? zarrdup(a) : NULL;
+ a = getaparam("mbegin");
+ m->mbegin = a ? zarrdup(a) : NULL;
+ a = getaparam("mend");
+ m->mend = a ? zarrdup(a) : NULL;
+ unqueue_signals();
+}
+
+static void
+restorematch(MatchData *m)
+{
+ if (m->match)
+ setaparam("match", m->match);
+ else
+ unsetparam("match");
+ if (m->mbegin)
+ setaparam("mbegin", m->mbegin);
+ else
+ unsetparam("mbegin");
+ if (m->mend)
+ setaparam("mend", m->mend);
+ else
+ unsetparam("mend");
+}
+
+static void
+freematch(MatchData *m)
+{
+ if (m->match)
+ freearray(m->match);
+ if (m->mbegin)
+ freearray(m->mbegin);
+ if (m->mend)
+ freearray(m->mend);
+}
+
/* Style stuff. */
typedef struct stypat *Stypat;
@@ -370,15 +419,21 @@ lookupstyle(char *ctxt, char *style)
{
Style s;
Stypat p;
+ char **found = NULL;
s = (Style)zstyletab->getnode2(zstyletab, style);
- if (!s)
- return NULL;
- for (p = s->pats; p; p = p->next)
- if (pattry(p->prog, ctxt))
- return (p->eval ? evalstyle(p) : p->vals);
+ if (s) {
+ MatchData match;
+ savematch(&match);
+ for (p = s->pats; p; p = p->next)
+ if (pattry(p->prog, ctxt)) {
+ found = (p->eval ? evalstyle(p) : p->vals);
+ break;
+ }
+ restorematch(&match);
+ }
- return NULL;
+ return found;
}
static int
@@ -915,55 +970,6 @@ bin_zformat(char *nam, char **args, UNUSED(Options ops), UNUSED(int func))
/* Zregexparse stuff. */
typedef struct {
- char **match;
- char **mbegin;
- char **mend;
-} MatchData;
-
-static void
-savematch(MatchData *m)
-{
- char **a;
-
- queue_signals();
- a = getaparam("match");
- m->match = a ? zarrdup(a) : NULL;
- a = getaparam("mbegin");
- m->mbegin = a ? zarrdup(a) : NULL;
- a = getaparam("mend");
- m->mend = a ? zarrdup(a) : NULL;
- unqueue_signals();
-}
-
-static void
-restorematch(MatchData *m)
-{
- if (m->match)
- setaparam("match", m->match);
- else
- unsetparam("match");
- if (m->mbegin)
- setaparam("mbegin", m->mbegin);
- else
- unsetparam("mbegin");
- if (m->mend)
- setaparam("mend", m->mend);
- else
- unsetparam("mend");
-}
-
-static void
-freematch(MatchData *m)
-{
- if (m->match)
- freearray(m->match);
- if (m->mbegin)
- freearray(m->mbegin);
- if (m->mend)
- freearray(m->mend);
-}
-
-typedef struct {
int cutoff;
char *pattern;
Patprog patprog;
Messages sorted by:
Reverse Date,
Date,
Thread,
Author