zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: Preserve $match while processing zstyles
       [not found]     ` <140308213732.ZM9579@torch.brasslantern.com>
@ 2014-03-09  6:42       ` Bart Schaefer
  0 siblings, 0 replies; only message in thread
From: Bart Schaefer @ 2014-03-09  6:42 UTC (permalink / raw)
  To: zsh-workers

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;


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-03-09  6:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1393780084.43996.YahooMailNeo@web194601.mail.sg3.yahoo.com>
     [not found] ` <140302121855.ZM1118@torch.brasslantern.com>
     [not found]   ` <2234.1393867510@thecus.kiddle.eu>
     [not found]     ` <140308213732.ZM9579@torch.brasslantern.com>
2014-03-09  6:42       ` PATCH: Preserve $match while processing zstyles Bart Schaefer

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).