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

Re: Problem with motion commands defined using match-word-by-style used with vi-delete



Bart Schaefer wrote:
> Incidentally I just noticed that within a widget called by using
> execute-named-command, the value of $KEYS is carriage return.  I'm not
> sure what I expected it to be, but that wasn't it.

I suppose the right answer is the \M-x sequence, or whatever called
execute-named-command, followed by the command name, followed by a
newline?

> } There's still no easy way to execute the command in the right
> } environment so that WIDGET is set to the read command that we want to
> } execute.
> 
> It really *should* be the case that
> 
>     local -h WIDGET
> 
> creates a new parameter named WIDGET that is neither read-only nor
> special, but apparently the usual parameter rules don't apply to the
> ZLE specials.

I think it's not just ZLE; I think it's all readonly specials are
treated in such away that you can't replace them.  The big problem in
this case is that the zle parameters need to be removed after the
execution of the widget, so they're paranoid about being hidden
(although here the local scope should end first).  I'm not sure how easy
this is to fix generally.

Here's a patch that allows you to request that zle sets the widget in
the way that it does at the top level.  It's actually done by storing
the global Thingy in the variable bindk, so it's not quite that simple,
but should have the desired effect, and do it more consistently than
just setting WIDGET.  Note that the option comes after the widget (zle
widget -w) as with other options specific to calling widgets.

Index: Doc/Zsh/zle.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/zle.yo,v
retrieving revision 1.52
diff -u -r1.52 zle.yo
--- Doc/Zsh/zle.yo	23 Apr 2006 23:13:47 -0000	1.52
+++ Doc/Zsh/zle.yo	25 Apr 2006 09:46:31 -0000
@@ -338,7 +338,7 @@
 xitem(tt(zle) tt(-K) var(keymap))
 xitem(tt(zle) tt(-F) [ tt(-L) ] [ var(fd) [ var(handler) ] ])
 xitem(tt(zle) tt(-I))
-item(tt(zle) var(widget) tt([ -n) var(num) tt(]) tt([ -N ] [ -K) var(keymap) tt(]) var(args) ...)(
+item(tt(zle) var(widget) tt([ -n) var(num) tt(]) tt([ -Nw ] [ -K) var(keymap) tt(]) var(args) ...)(
 The tt(zle) builtin performs a number of different actions concerning
 ZLE.
 
@@ -535,7 +535,7 @@
 notification.  To test if a zle widget may be called at this point, execute
 tt(zle) with no arguments and examine the return status.
 )
-item(var(widget) tt([ -n) var(num) tt(]) tt([ -N ] [ -K) var(keymap) tt(]) var(args) ...)(
+item(var(widget) tt([ -n) var(num) tt(]) tt([ -Nw ] [ -K) var(keymap) tt(]) var(args) ...)(
 Invoke the specified widget.  This can only be done when ZLE is
 active; normally this will be within a user-defined widget.
 
@@ -548,6 +548,12 @@
 during the execution of the widget.  The previous keymap will be
 restored when the widget exits.
 
+Normally, calling a widget in this way does not set the special
+parameter tt(WIDGET) and related parameters, so that the environment
+appears as if the top-level widget called by the user were still
+active.  With the option tt(-w), tt(WIDGET) and related parameters are set
+to reflect the widget being executed by the tt(zle) call.
+
 Any further arguments will be passed to the widget.  If it is a shell
 function, these are passed down as positional parameters; for builtin
 widgets it is up to the widget in question what it does with them.
@@ -559,7 +565,7 @@
 
 The return status reflects the success or failure of the operation carried
 out by the widget, or if it is a user-defined widget the return status of
-the shell function.  
+the shell function.
 
 A non-zero return status causes the shell to beep when the widget exits,
 unless the tt(BEEP) options was unset or the widget was called via the
Index: Src/Zle/zle_thingy.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_thingy.c,v
retrieving revision 1.26
diff -u -r1.26 zle_thingy.c
--- Src/Zle/zle_thingy.c	25 Mar 2006 18:50:44 -0000	1.26
+++ Src/Zle/zle_thingy.c	25 Apr 2006 09:46:32 -0000
@@ -639,9 +639,9 @@
 static int
 bin_zle_call(char *name, char **args, UNUSED(Options ops), UNUSED(char func))
 {
-    Thingy t;
+    Thingy t, savbindk = bindk;
     struct modifier modsave = zmod;
-    int ret, saveflag = 0;
+    int ret, saveflag = 0, setbindk = 0;
     char *wname = *args++, *keymap_restore = NULL, *keymap_tmp;
 
     if (!wname)
@@ -692,6 +692,9 @@
 		if (selectkeymap(keymap_tmp, 0))
 		    return 1;
 		break;
+	    case 'w':
+		setbindk = 1;
+		break;
 	    default:
 		zwarnnam(name, "unknown option: %s", *args, 0);
 		return 1;
@@ -701,7 +704,10 @@
     }
 
     t = rthingy(wname);
+    if (setbindk)
+	bindk = t;
     ret = execzlefunc(t, args);
+    bindk = savbindk;
     unrefthingy(t);
     if (saveflag)
 	zmod = modsave;

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


To access the latest news from CSR copy this link into a web browser:  http://www.csr.com/email_sig.php



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