zsh-workers
 help / color / mirror / code / Atom feed
* Re: Problem with motion commands defined using match-word-by-style used with vi-delete
       [not found]     ` <060424200611.ZM996@torch.brasslantern.com>
@ 2006-04-25  9:58       ` Peter Stephenson
  2006-04-25 11:19         ` Nikolai Weibull
  2006-04-25 14:28         ` Bart Schaefer
  0 siblings, 2 replies; 4+ messages in thread
From: Peter Stephenson @ 2006-04-25  9:58 UTC (permalink / raw)
  To: Zsh hackers list

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@csr.com>                  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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Problem with motion commands defined using match-word-by-style used with vi-delete
  2006-04-25  9:58       ` Problem with motion commands defined using match-word-by-style used with vi-delete Peter Stephenson
@ 2006-04-25 11:19         ` Nikolai Weibull
  2006-04-25 14:28         ` Bart Schaefer
  1 sibling, 0 replies; 4+ messages in thread
From: Nikolai Weibull @ 2006-04-25 11:19 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Zsh hackers list

On 4/25/06, Peter Stephenson <pws@csr.com> wrote:
> 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.

Thanks!  This sounds like what we need to be able to implement
vi-delete in the shell.  I'll try it out once I get home.

  nikolai


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Problem with motion commands defined using match-word-by-style used with vi-delete
  2006-04-25  9:58       ` Problem with motion commands defined using match-word-by-style used with vi-delete Peter Stephenson
  2006-04-25 11:19         ` Nikolai Weibull
@ 2006-04-25 14:28         ` Bart Schaefer
  2006-04-25 14:52           ` Peter Stephenson
  1 sibling, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2006-04-25 14:28 UTC (permalink / raw)
  To: Zsh hackers list

On Apr 25, 10:58am, Peter Stephenson wrote:
} Subject: Re: Problem with motion commands defined using match-word-by-styl
}
} 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?

I suppose, but that seems excessive.

} 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

So ... shouldn't getvirange() do this part too?  What harm could it be?

} +    bindk = t;
}      ret = execzlefunc(t, args);
} +    bindk = savbindk;


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Problem with motion commands defined using match-word-by-style used with vi-delete
  2006-04-25 14:28         ` Bart Schaefer
@ 2006-04-25 14:52           ` Peter Stephenson
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Stephenson @ 2006-04-25 14:52 UTC (permalink / raw)
  To: Zsh hackers list

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@csr.com>                  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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-04-25 14:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <060423085310.ZM31491@torch.brasslantern.com>
     [not found] ` <200604232308.k3NN8Wtj004945@pwslaptop.csr.com>
     [not found]   ` <dbfc82860604241239q34ee602an680fd20611d52018@mail.gmail.com>
     [not found]     ` <060424200611.ZM996@torch.brasslantern.com>
2006-04-25  9:58       ` Problem with motion commands defined using match-word-by-style used with vi-delete Peter Stephenson
2006-04-25 11:19         ` Nikolai Weibull
2006-04-25 14:28         ` Bart Schaefer
2006-04-25 14:52           ` Peter Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).