Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: Add $ZLE_STATE in zle widgets
- X-seq: zsh-workers 28122
- From: Frank Terbeck <ft@xxxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: PATCH: Add $ZLE_STATE in zle widgets
- Date: Tue, 3 Aug 2010 22:43:20 +0200
- In-reply-to: <20100803105823.1232a42b@xxxxxxx>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <20100803105823.1232a42b@xxxxxxx>
This is the $OVERWRITE idea converted to a string $ZLE_STATE, that may
contain more than one attribute. Currently it only handles the status of
the overwrite bit (!insmode).
---
Doc/Zsh/zle.yo | 7 +++++++
Src/Zle/zle_params.c | 22 ++++++++++++++++++++++
2 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo
index 0e2fea5..ab5ea3f 100644
--- a/Doc/Zsh/zle.yo
+++ b/Doc/Zsh/zle.yo
@@ -854,6 +854,13 @@ 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 sub-strings that describe the current tt(zle) state.
+Currently, this can only contain `tt(overwrite)' which is the case if
+tt(zle) will overwrite existing characters if the cursor is not at the
+end of a buffer line and new characters are entered. Read-only.
+)
enditem()
subsect(Special Widgets)
diff --git a/Src/Zle/zle_params.c b/Src/Zle/zle_params.c
index 2883c0f..ee8814d 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,22 @@ get_context(UNUSED(Param pm))
break;
}
}
+
+/**/
+static char *
+get_zle_state(UNUSED(Param pm))
+{
+ char *zle_state;
+
+ /*
+ * 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
+ */
+ zle_state = dupstring("");
+ if (!insmode) {
+ zle_state = dyncat(zle_state, "overwrite");
+ }
+
+ return zle_state;
+}
--
1.7.2.rc2
Messages sorted by:
Reverse Date,
Date,
Thread,
Author