summary refs log tree commit diff
path: root/Src/Zle
diff options
context:
space:
mode:
Diffstat (limited to 'Src/Zle')
-rw-r--r--Src/Zle/zle_params.c60
1 files changed, 60 insertions, 0 deletions
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;
+}