1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-01-10 20:11:16 +01:00

28122 (Frank) / 28139: add ZLE_STATE

This commit is contained in:
Peter Stephenson 2010-08-11 12:48:19 +00:00
parent 0bb608abc4
commit 80eee3a4a3
3 changed files with 77 additions and 1 deletions

View file

@ -1,3 +1,8 @@
2010-08-11 Peter Stephenson <pws@csr.com>
* 28139: based on Frank Terbeck: 28122: Src/Zle/zle_params.c,
Doc/Zsh/zle.yo: add ZLE_STATE variable.
2010-08-10 Clint Adams <clint@zsh.org>
* unposted: Functions/Newuser/zsh-newuser-install: tweak
@ -13513,5 +13518,5 @@
*****************************************************
* This is used by the shell to define $ZSH_PATCHLEVEL
* $Revision: 1.5054 $
* $Revision: 1.5055 $
*****************************************************

View file

@ -854,6 +854,17 @@ executed; the second argument that followed tt(zle -C) when the widget was
defined. This is the name of a builtin completion widget. For widgets
defined with tt(zle -N) this is set to the empty string. Read-only.
)
vindex(ZLE_STATE)
item(tt(ZLE_STATE) (scalar))(
Contains a set of space-separated words that describe the current tt(zle)
state.
Currently, the only state shown is the insert mode as set by the
tt(overwrite-mode) or tt(vi-replace) widgets. The string contains
`tt(insert)' if characters to be inserted on the command line move existing
characters to the right, `tt(overwrite)' if characters to be inserted
overwrite existing characters.
)
enditem()
subsect(Special Widgets)

View file

@ -76,6 +76,8 @@ static const struct gsu_scalar widgetfunc_gsu =
{ get_widgetfunc, nullstrsetfn, zleunsetfn };
static const struct gsu_scalar widgetstyle_gsu =
{ get_widgetstyle, nullstrsetfn, zleunsetfn };
static const struct gsu_scalar zle_state_gsu =
{ get_zle_state, nullstrsetfn, zleunsetfn };
static const struct gsu_integer bufferlines_gsu =
{ get_bufferlines, NULL, zleunsetfn };
@ -134,6 +136,7 @@ static struct zleparam {
{ "WIDGET", PM_SCALAR | PM_READONLY, GSU(widget_gsu), NULL },
{ "WIDGETFUNC", PM_SCALAR | PM_READONLY, GSU(widgetfunc_gsu), NULL },
{ "WIDGETSTYLE", PM_SCALAR | PM_READONLY, GSU(widgetstyle_gsu), NULL },
{ "ZLE_STATE", PM_SCALAR | PM_READONLY, GSU(zle_state_gsu), NULL },
{ NULL, 0, NULL, NULL }
};
@ -695,3 +698,60 @@ get_context(UNUSED(Param pm))
break;
}
}
/**/
static char *
get_zle_state(UNUSED(Param pm))
{
char *zle_state = NULL, *ptr = NULL;
int itp, istate, len = 0;
/*
* When additional substrings are added, they should be kept in
* alphabetical order, so the user can easily match against this
* parameter: if [[ $ZLE_STATE == *bar*foo*zonk* ]]; then ...; fi
*/
for (itp = 0; itp < 2; itp++) {
char *str;
/*
* Currently there is only one state: insert or overwrite.
* This loop is to make it easy to add others.
*/
for (istate = 0; istate < 1; istate++) {
int slen;
switch (istate) {
case 0:
if (insmode) {
str = "insert";
} else {
str = "overwrite";
}
break;
default:
str = "";
}
slen = strlen(str);
if (itp == 0) {
/* Accumulating length */
if (istate)
len++; /* for space */
len += slen;
} else {
/* Accumulating string */
if (istate)
*ptr++ = ' ';
memcpy(ptr, str, slen);
ptr += slen;
}
}
if (itp == 0) {
len++; /* terminating NULL */
ptr = zle_state = (char *)zhalloc(len);
} else {
*ptr = '\0';
}
}
return zle_state;
}