From: Sven Wischnowsky <wischnow@informatik.hu-berlin.de>
To: zsh-workers@sunsite.auc.dk
Subject: Re: PATCH: Re: The `zle' command and traps
Date: Tue, 14 Mar 2000 10:54:59 +0100 (MET) [thread overview]
Message-ID: <200003140954.KAA07267@beta.informatik.hu-berlin.de> (raw)
In-Reply-To: Sven Wischnowsky's message of Mon, 13 Mar 2000 16:07:25 +0100 (MET)
I wrote:
> ...
>
> > If we can restrict widgets to those that do "safe" things, then we can
> > allow "zle widgetname" and there's no need for the special parameters to
> > be visible directly to the trap function. If instead we must prohibit
> > widget-calling entirely, then perhaps the parameters should be available
> > to the trap function.
>
> No patch for that yet, either. The problem is that traps are called
> from the core (of course) and the zle module might not be there. Maybe
> calling a hook in dotrapargs() so that zle can install its own hook
> function when it is loaded to make the parameters available read-only
> when zle is active. Or does this sound too complicated to anyone?
Well, it didn't look too complicated to me... this also documents in
zle.yo that the zle parameters are available in completion widgets and
traps called when zle is active.
Bye
Sven
diff -ru ../z.old/Doc/Zsh/zle.yo Doc/Zsh/zle.yo
--- ../z.old/Doc/Zsh/zle.yo Tue Mar 14 10:39:02 2000
+++ Doc/Zsh/zle.yo Tue Mar 14 10:42:35 2000
@@ -115,6 +115,9 @@
when the widget function exits. These special parameters in fact have
local scope, like parameters created in a function using tt(local).
+Inside completion widgets and traps called while ZLE is active, these
+parameters are available read-only.
+
startitem()
vindex(BUFFER)
item(tt(BUFFER) (scalar))(
diff -ru ../z.old/Src/Zle/zle_main.c Src/Zle/zle_main.c
--- ../z.old/Src/Zle/zle_main.c Tue Mar 14 10:38:53 2000
+++ Src/Zle/zle_main.c Tue Mar 14 10:41:09 2000
@@ -992,6 +992,28 @@
kungetct = 0;
}
+/* Hook functions. Used to allow access to zle parameters if zle is
+ * active. */
+
+static int
+zlebeforetrap(Hookdef dummy, void *dat)
+{
+ if (zleactive) {
+ startparamscope();
+ makezleparams(1);
+ }
+ return 0;
+}
+
+static int
+zleaftertrap(Hookdef dummy, void *dat)
+{
+ if (zleactive)
+ endparamscope();
+
+ return 0;
+}
+
static struct builtin bintab[] = {
BUILTIN("bindkey", 0, bin_bindkey, 0, -1, 0, "evaMldDANmrsLR", NULL),
BUILTIN("vared", 0, bin_vared, 1, 7, 0, NULL, NULL),
@@ -1049,6 +1071,8 @@
int
boot_(Module m)
{
+ addhookfunc("before_trap", (Hookfn) zlebeforetrap);
+ addhookfunc("after_trap", (Hookfn) zleaftertrap);
addbuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab));
addhookdefs(m->nam, zlehooks, sizeof(zlehooks)/sizeof(*zlehooks));
return 0;
@@ -1063,6 +1087,8 @@
NULL, 0);
return 1;
}
+ deletehookfunc("before_trap", (Hookfn) zlebeforetrap);
+ deletehookfunc("after_trap", (Hookfn) zleaftertrap);
deletebuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab));
deletehookdefs(m->nam, zlehooks, sizeof(zlehooks)/sizeof(*zlehooks));
return 0;
diff -ru ../z.old/Src/init.c Src/init.c
--- ../z.old/Src/init.c Tue Mar 14 10:38:47 2000
+++ Src/init.c Tue Mar 14 10:41:09 2000
@@ -90,6 +90,8 @@
/**/
mod_export struct hookdef zshhooks[] = {
HOOKDEF("exit", NULL, HOOKF_ALL),
+ HOOKDEF("before_trap", NULL, HOOKF_ALL),
+ HOOKDEF("after_trap", NULL, HOOKF_ALL),
};
/* keep executing lists until EOF found */
diff -ru ../z.old/Src/signals.c Src/signals.c
--- ../z.old/Src/signals.c Tue Mar 14 10:38:49 2000
+++ Src/signals.c Tue Mar 14 10:41:09 2000
@@ -894,6 +894,7 @@
lexsave();
execsave();
breaks = 0;
+ runhookdef(BEFORETRAPHOOK, NULL);
if (*sigtr & ZSIG_FUNC) {
int osc = sfcontext;
@@ -912,6 +913,7 @@
zsfree(name);
} else
execode(sigfn, 1, 0);
+ runhookdef(AFTERTRAPHOOK, NULL);
if (trapreturn > 0)
trapret = trapreturn;
diff -ru ../z.old/Src/zsh.h Src/zsh.h
--- ../z.old/Src/zsh.h Tue Mar 14 10:38:50 2000
+++ Src/zsh.h Tue Mar 14 10:41:10 2000
@@ -1675,4 +1675,6 @@
/* Hooks in core. */
/***************************************/
-#define EXITHOOK (zshhooks + 0)
+#define EXITHOOK (zshhooks + 0)
+#define BEFORETRAPHOOK (zshhooks + 1)
+#define AFTERTRAPHOOK (zshhooks + 2)
--
Sven Wischnowsky wischnow@informatik.hu-berlin.de
next reply other threads:[~2000-03-14 9:55 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-03-14 9:54 Sven Wischnowsky [this message]
-- strict thread matches above, loose matches on Subject: below --
2000-03-14 10:35 Sven Wischnowsky
2000-03-14 16:56 ` Bart Schaefer
2000-03-13 16:49 Sven Wischnowsky
2000-03-13 17:08 ` Bart Schaefer
2000-03-13 15:07 Sven Wischnowsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200003140954.KAA07267@beta.informatik.hu-berlin.de \
--to=wischnow@informatik.hu-berlin.de \
--cc=zsh-workers@sunsite.auc.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).