mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-10 12:40:58 +02:00
zsh-workers/10128
This commit is contained in:
parent
0e7c726c32
commit
e91bdf82c9
5 changed files with 36 additions and 1 deletions
|
@ -115,6 +115,9 @@ outside ZLE, that value is temporarily inaccessible, but will return
|
||||||
when the widget function exits. These special parameters in fact have
|
when the widget function exits. These special parameters in fact have
|
||||||
local scope, like parameters created in a function using tt(local).
|
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()
|
startitem()
|
||||||
vindex(BUFFER)
|
vindex(BUFFER)
|
||||||
item(tt(BUFFER) (scalar))(
|
item(tt(BUFFER) (scalar))(
|
||||||
|
|
|
@ -992,6 +992,28 @@ trashzle(void)
|
||||||
kungetct = 0;
|
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[] = {
|
static struct builtin bintab[] = {
|
||||||
BUILTIN("bindkey", 0, bin_bindkey, 0, -1, 0, "evaMldDANmrsLR", NULL),
|
BUILTIN("bindkey", 0, bin_bindkey, 0, -1, 0, "evaMldDANmrsLR", NULL),
|
||||||
BUILTIN("vared", 0, bin_vared, 1, 7, 0, NULL, NULL),
|
BUILTIN("vared", 0, bin_vared, 1, 7, 0, NULL, NULL),
|
||||||
|
@ -1049,6 +1071,8 @@ setup_(Module m)
|
||||||
int
|
int
|
||||||
boot_(Module m)
|
boot_(Module m)
|
||||||
{
|
{
|
||||||
|
addhookfunc("before_trap", (Hookfn) zlebeforetrap);
|
||||||
|
addhookfunc("after_trap", (Hookfn) zleaftertrap);
|
||||||
addbuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab));
|
addbuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab));
|
||||||
addhookdefs(m->nam, zlehooks, sizeof(zlehooks)/sizeof(*zlehooks));
|
addhookdefs(m->nam, zlehooks, sizeof(zlehooks)/sizeof(*zlehooks));
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1063,6 +1087,8 @@ cleanup_(Module m)
|
||||||
NULL, 0);
|
NULL, 0);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
deletehookfunc("before_trap", (Hookfn) zlebeforetrap);
|
||||||
|
deletehookfunc("after_trap", (Hookfn) zleaftertrap);
|
||||||
deletebuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab));
|
deletebuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab));
|
||||||
deletehookdefs(m->nam, zlehooks, sizeof(zlehooks)/sizeof(*zlehooks));
|
deletehookdefs(m->nam, zlehooks, sizeof(zlehooks)/sizeof(*zlehooks));
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -90,6 +90,8 @@ mod_export sigset_t sigchld_mask;
|
||||||
/**/
|
/**/
|
||||||
mod_export struct hookdef zshhooks[] = {
|
mod_export struct hookdef zshhooks[] = {
|
||||||
HOOKDEF("exit", NULL, HOOKF_ALL),
|
HOOKDEF("exit", NULL, HOOKF_ALL),
|
||||||
|
HOOKDEF("before_trap", NULL, HOOKF_ALL),
|
||||||
|
HOOKDEF("after_trap", NULL, HOOKF_ALL),
|
||||||
};
|
};
|
||||||
|
|
||||||
/* keep executing lists until EOF found */
|
/* keep executing lists until EOF found */
|
||||||
|
|
|
@ -894,6 +894,7 @@ dotrapargs(int sig, int *sigtr, void *sigfn)
|
||||||
lexsave();
|
lexsave();
|
||||||
execsave();
|
execsave();
|
||||||
breaks = 0;
|
breaks = 0;
|
||||||
|
runhookdef(BEFORETRAPHOOK, NULL);
|
||||||
if (*sigtr & ZSIG_FUNC) {
|
if (*sigtr & ZSIG_FUNC) {
|
||||||
int osc = sfcontext;
|
int osc = sfcontext;
|
||||||
|
|
||||||
|
@ -912,6 +913,7 @@ dotrapargs(int sig, int *sigtr, void *sigfn)
|
||||||
zsfree(name);
|
zsfree(name);
|
||||||
} else
|
} else
|
||||||
execode(sigfn, 1, 0);
|
execode(sigfn, 1, 0);
|
||||||
|
runhookdef(AFTERTRAPHOOK, NULL);
|
||||||
|
|
||||||
if (trapreturn > 0)
|
if (trapreturn > 0)
|
||||||
trapret = trapreturn;
|
trapret = trapreturn;
|
||||||
|
|
|
@ -1676,3 +1676,5 @@ typedef unsigned char * (*ZleReadFn) _((char *, char *, int));
|
||||||
/***************************************/
|
/***************************************/
|
||||||
|
|
||||||
#define EXITHOOK (zshhooks + 0)
|
#define EXITHOOK (zshhooks + 0)
|
||||||
|
#define BEFORETRAPHOOK (zshhooks + 1)
|
||||||
|
#define AFTERTRAPHOOK (zshhooks + 2)
|
||||||
|
|
Loading…
Reference in a new issue