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:
> So ... shouldn't getvirange() do this part too?  What harm could it be?
> 
> } +    bindk = t;
> }      ret = execzlefunc(t, args);
> } +    bindk = savbindk;

It depends:  is it useful to know that the motion commands are running
as part of a vi command?  Changing it would make it more consistent with
Nicholas' proposed use.

The following patch makes this feature an argument to execzlefunc(); it
looks like it would be sensible to use this for stand-alone widgets that
aren't run directly by the user, too.

Index: Src/Zle/zle_main.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_main.c,v
retrieving revision 1.84
diff -u -r1.84 zle_main.c
--- Src/Zle/zle_main.c	7 Mar 2006 21:31:43 -0000	1.84
+++ Src/Zle/zle_main.c	25 Apr 2006 14:48:10 -0000
@@ -862,7 +862,7 @@
 		eofsent = 1;
 		break;
 	    }
-	    if (execzlefunc(bindk, zlenoargs)) {
+	    if (execzlefunc(bindk, zlenoargs, 0)) {
 		handlefeep(zlenoargs);
 		if (eofsent)
 		    break;
@@ -1011,7 +1011,7 @@
 	char *args[2];
 	args[0] = initthingy->nam;
 	args[1] = NULL;
-	execzlefunc(initthingy, args);
+	execzlefunc(initthingy, args, 1);
 	unrefthingy(initthingy);
 	errflag = retflag = 0;
     }
@@ -1040,14 +1040,22 @@
     return s;
 }
 
-/* execute a widget */
+/*
+ * Execute a widget.  The third argument indicates that the global
+ * variable bindk should be set temporarily so that WIDGET etc.
+ * reflect the command being executed.
+ */
 
 /**/
 int
-execzlefunc(Thingy func, char **args)
+execzlefunc(Thingy func, char **args, int set_bindk)
 {
     int r = 0, ret = 0;
     Widget w;
+    Thingy save_bindk = bindk;
+
+    if (set_bindk)
+	bindk = func;
 
     if(func->flags & DISABLED) {
 	/* this thingy is not the name of a widget */
@@ -1143,6 +1151,8 @@
 	refthingy(func);
 	lbindk = func;
     }
+    if (set_bindk)
+	bindk = save_bindk;
     return ret;
 }
 
Index: Src/Zle/zle_thingy.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_thingy.c,v
retrieving revision 1.27
diff -u -r1.27 zle_thingy.c
--- Src/Zle/zle_thingy.c	25 Apr 2006 10:10:51 -0000	1.27
+++ Src/Zle/zle_thingy.c	25 Apr 2006 14:48:11 -0000
@@ -639,7 +639,7 @@
 static int
 bin_zle_call(char *name, char **args, UNUSED(Options ops), UNUSED(char func))
 {
-    Thingy t, savbindk = bindk;
+    Thingy t;
     struct modifier modsave = zmod;
     int ret, saveflag = 0, setbindk = 0;
     char *wname = *args++, *keymap_restore = NULL, *keymap_tmp;
@@ -704,10 +704,7 @@
     }
 
     t = rthingy(wname);
-    if (setbindk)
-	bindk = t;
-    ret = execzlefunc(t, args);
-    bindk = savbindk;
+    ret = execzlefunc(t, args, setbindk);
     unrefthingy(t);
     if (saveflag)
 	zmod = modsave;
Index: Src/Zle/zle_vi.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_vi.c,v
retrieving revision 1.13
diff -u -r1.13 zle_vi.c
--- Src/Zle/zle_vi.c	1 Nov 2005 02:50:30 -0000	1.13
+++ Src/Zle/zle_vi.c	25 Apr 2006 14:48:12 -0000
@@ -181,7 +181,7 @@
 	 * a number of lines is used.  If the function used
 	 * returns 1, we fail.
 	 */
-	if ((k2 == bindk) ? dovilinerange() : execzlefunc(k2, zlenoargs))
+	if ((k2 == bindk) ? dovilinerange() : execzlefunc(k2, zlenoargs, 1))
 	    ret = -1;
 	if(vichgrepeat)
 	    zmult = mult1;

-- 
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