Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Identify "active" region?



2008/5/4 Mikael Magnusson <mikachu@xxxxxxxxx>:
> 2008/5/4 Mikael Magnusson <mikachu@xxxxxxxxx>:
>
> > 2008/5/4 Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>:
>
> > >  No, that's worth adding.  I'll do it if no one gets to it first.  It
> > >  should be trivial: a new ZLE variable tied into the integer controlling
> > >  this.  There's no reason it shouldn't be writable, either.
> >
> >  This seems to do the trick:
> >
> >  +    { "REGION", PM_INTEGER, GSU(region_gsu), NULL},
>
>  I realize two things just after hitting send, 1) the variable should
>  probably be called something like REGIONACTIVE, and 2) I didn't write
>  any documentation for it.

diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo
index f8435c1..e07c955 100644
--- a/Doc/Zsh/zle.yo
+++ b/Doc/Zsh/zle.yo
@@ -774,6 +774,11 @@ The part of the buffer that lies to the right of
the cursor position.
 If it is assigned to, only that part of the buffer is replaced, and the
 cursor remains between the old tt($LBUFFER) and the new tt($RBUFFER).
 )
+vindex(REGIONACTIVE)
+item(tt(REGIONACTIVE) (integer))(
+Indicates if the region is currently active. It can be assigned 0 or 1
+to deactivate and deactivate the region respectively.
+)
 vindex(region_highlight)
 item(tt(region_highlight) (array))(
 Each element of this array may be set to a string that describes
diff --git a/Src/Zle/zle_params.c b/Src/Zle/zle_params.c
index a04ee72..a114596 100644
--- a/Src/Zle/zle_params.c
+++ b/Src/Zle/zle_params.c
@@ -89,6 +89,8 @@ static const struct gsu_integer numeric_gsu =
 { get_numeric, set_numeric, unset_numeric };
 static const struct gsu_integer pending_gsu =
 { get_pending, NULL, zleunsetfn };
+static const struct gsu_integer region_gsu =
+{ get_region_active, set_region_active, zleunsetfn };

 static const struct gsu_array killring_gsu =
 { get_killring, set_killring, unset_killring };
@@ -125,7 +127,8 @@ static struct zleparam {
     { "POSTDISPLAY", PM_SCALAR, GSU(postdisplay_gsu), NULL },
     { "PREBUFFER",  PM_SCALAR | PM_READONLY,  GSU(prebuffer_gsu), NULL },
     { "PREDISPLAY", PM_SCALAR, GSU(predisplay_gsu), NULL },
-    { "RBUFFER", PM_SCALAR,  GSU(rbuffer_gsu), NULL },
+    { "RBUFFER", PM_SCALAR, GSU(rbuffer_gsu), NULL },
+    { "REGIONACTIVE", PM_INTEGER, GSU(region_gsu), NULL},
     { "region_highlight", PM_ARRAY, GSU(region_highlight_gsu), NULL },
     { "WIDGET", PM_SCALAR | PM_READONLY, GSU(widget_gsu), NULL },
     { "WIDGETFUNC", PM_SCALAR | PM_READONLY, GSU(widgetfunc_gsu), NULL },
@@ -252,6 +255,20 @@ get_mark(UNUSED(Param pm))

 /**/
 static void
+set_region_active(UNUSED(Param pm), zlong x)
+{
+    region_active = !!x;
+}
+
+/**/
+static zlong
+get_region_active(UNUSED(Param pm))
+{
+    return region_active;
+}
+
+/**/
+static void
 set_lbuffer(UNUSED(Param pm), char *x)
 {
     ZLE_STRING_T y;


-- 
Mikael Magnusson



Messages sorted by: Reverse Date, Date, Thread, Author