From 80eee3a4a336a0a91d73be5cd752d5f788661d4b Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Wed, 11 Aug 2010 12:48:19 +0000 Subject: 28122 (Frank) / 28139: add ZLE_STATE --- Src/Zle/zle_params.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'Src') diff --git a/Src/Zle/zle_params.c b/Src/Zle/zle_params.c index 2883c0fbd..1a23d3c67 100644 --- a/Src/Zle/zle_params.c +++ b/Src/Zle/zle_params.c @@ -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; +} -- cgit 1.4.1