zsh-workers
 help / color / mirror / code / Atom feed
* Difficulties with _oldlist
@ 2004-08-23 15:51 Bart Schaefer
  2004-09-08 16:56 ` Peter Stephenson
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2004-08-23 15:51 UTC (permalink / raw)
  To: zsh-workers

In _oldlist is this test:

elif [[ $WIDGET = *complete(|-prefix|-word) ]] &&
     zstyle -T ":completion:${curcontext}:" old-menu; then

This effectively means that, in order to use _oldlist, user-defined 
completion widgets must have names ending in "complete".

This should at the very least be documented.  A better solution would be 
if $WIDGET could be replaced by a different variable, say $WIDGETSTYLE for 
example, which is set corresponding to the second argument of "zle -C".
I.e. if the widget were defined with

	zle -C blather list-choices blather

then at time of call $WIDGETSTYLE would be "list-choices", and _oldlist
could examine that instead of $WIDGET.

This would also solve a longstanding problem with _complete_debug (which
could be tweaked by renaming it to _debug_complete in the meantime).


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

* Re: Difficulties with _oldlist
  2004-08-23 15:51 Difficulties with _oldlist Bart Schaefer
@ 2004-09-08 16:56 ` Peter Stephenson
  2004-09-10  8:04   ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Stephenson @ 2004-09-08 16:56 UTC (permalink / raw)
  To: zsh-workers

Bart Schaefer wrote:
> A better solution would be 
> if $WIDGET could be replaced by a different variable, say $WIDGETSTYLE for 
> example, which is set corresponding to the second argument of "zle -C".
> I.e. if the widget were defined with
> 
> 	zle -C blather list-choices blather
> 
> then at time of call $WIDGETSTYLE would be "list-choices", and _oldlist
> could examine that instead of $WIDGET.

This is the internal implementation.  For a "zle -N" widget $WIDGETSTYLE
gives the name of the function that implements the widget.  Altering the
completion system is left as an exercise to the reader.

Index: Src/Zle/zle_params.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_params.c,v
retrieving revision 1.16
diff -u -r1.16 zle_params.c
--- Src/Zle/zle_params.c	29 Jul 2004 14:22:22 -0000	1.16
+++ Src/Zle/zle_params.c	8 Sep 2004 16:52:53 -0000
@@ -55,43 +55,45 @@
 } zleparams[] = {
     { "BUFFER",  PM_SCALAR,  FN(set_buffer),  FN(get_buffer),
 	zleunsetfn, NULL },
-    { "CURSOR",  PM_INTEGER, FN(set_cursor),  FN(get_cursor),
-	zleunsetfn, NULL },
-    { "MARK",  PM_INTEGER, FN(set_mark),  FN(get_mark),
-	zleunsetfn, NULL },
-    { "LBUFFER", PM_SCALAR,  FN(set_lbuffer), FN(get_lbuffer),
-	zleunsetfn, NULL },
-    { "RBUFFER", PM_SCALAR,  FN(set_rbuffer), FN(get_rbuffer),
+    { "BUFFERLINES", PM_INTEGER | PM_READONLY, NULL, FN(get_bufferlines),
+        zleunsetfn, NULL },
+    { "CONTEXT", PM_SCALAR | PM_READONLY, NULL, FN(get_context),
 	zleunsetfn, NULL },
-    { "PREBUFFER",  PM_SCALAR | PM_READONLY,  NULL,  FN(get_prebuffer),
+    { "CURSOR",  PM_INTEGER, FN(set_cursor),  FN(get_cursor),
 	zleunsetfn, NULL },
-    { "WIDGET", PM_SCALAR | PM_READONLY, NULL, FN(get_widget),
-        zleunsetfn, NULL },
-    { "LASTWIDGET", PM_SCALAR | PM_READONLY, NULL, FN(get_lwidget),
+    { "CUTBUFFER", PM_SCALAR, FN(set_cutbuffer), FN(get_cutbuffer),
+	unset_cutbuffer, NULL },
+    { "HISTNO", PM_INTEGER, FN(set_histno), FN(get_histno),
         zleunsetfn, NULL },
     { "KEYMAP", PM_SCALAR | PM_READONLY, NULL, FN(get_keymap),
         zleunsetfn, NULL },
     { "KEYS", PM_SCALAR | PM_READONLY, NULL, FN(get_keys),
         zleunsetfn, NULL },
-    { "NUMERIC", PM_INTEGER | PM_UNSET, FN(set_numeric), FN(get_numeric),
-        unset_numeric, NULL },
-    { "HISTNO", PM_INTEGER, FN(set_histno), FN(get_histno),
+    { "killring", PM_ARRAY, FN(set_killring), FN(get_killring),
+	unset_killring, NULL },
+    { "LASTSEARCH", PM_SCALAR | PM_READONLY, NULL, FN(get_lsearch),
         zleunsetfn, NULL },
-    { "BUFFERLINES", PM_INTEGER | PM_READONLY, NULL, FN(get_bufferlines),
+    { "LASTWIDGET", PM_SCALAR | PM_READONLY, NULL, FN(get_lwidget),
         zleunsetfn, NULL },
+    { "LBUFFER", PM_SCALAR,  FN(set_lbuffer), FN(get_lbuffer),
+	zleunsetfn, NULL },
+    { "MARK",  PM_INTEGER, FN(set_mark),  FN(get_mark),
+	zleunsetfn, NULL },
+    { "NUMERIC", PM_INTEGER | PM_UNSET, FN(set_numeric), FN(get_numeric),
+        unset_numeric, NULL },
     { "PENDING", PM_INTEGER | PM_READONLY, NULL, FN(get_pending),
         zleunsetfn, NULL },
-    { "CUTBUFFER", PM_SCALAR, FN(set_cutbuffer), FN(get_cutbuffer),
-	unset_cutbuffer, NULL },
-    { "killring", PM_ARRAY, FN(set_killring), FN(get_killring),
-	unset_killring, NULL },
+    { "POSTDISPLAY", PM_SCALAR, FN(set_postdisplay), FN(get_postdisplay),
+	zleunsetfn, NULL },
+    { "PREBUFFER",  PM_SCALAR | PM_READONLY,  NULL,  FN(get_prebuffer),
+	zleunsetfn, NULL },
     { "PREDISPLAY", PM_SCALAR, FN(set_predisplay), FN(get_predisplay),
 	zleunsetfn, NULL },
-    { "POSTDISPLAY", PM_SCALAR, FN(set_postdisplay), FN(get_postdisplay),
+    { "RBUFFER", PM_SCALAR,  FN(set_rbuffer), FN(get_rbuffer),
 	zleunsetfn, NULL },
-    { "LASTSEARCH", PM_SCALAR | PM_READONLY, NULL, FN(get_lsearch),
+    { "WIDGET", PM_SCALAR | PM_READONLY, NULL, FN(get_widget),
         zleunsetfn, NULL },
-    { "CONTEXT", PM_SCALAR | PM_READONLY, NULL, FN(get_context),
+    { "WIDGETSTYLE", PM_SCALAR | PM_READONLY, NULL, FN(get_widgetstyle),
 	zleunsetfn, NULL },
     { NULL, 0, NULL, NULL, NULL, NULL }
 };
@@ -280,6 +282,21 @@
 
 /**/
 static char *
+get_widgetstyle(UNUSED(Param pm))
+{
+    Widget widget = bindk->widget;
+    int flags = widget->flags;
+
+    if (flags & WIDGET_INT)
+	return ".internal";	/* Don't see how this can ever be returned... */
+    else if (flags & WIDGET_NCOMP)
+	return widget->u.comp.wid;
+    else
+	return widget->u.fnnam;
+}
+
+/**/
+static char *
 get_lwidget(UNUSED(Param pm))
 {
     return (lbindk ? lbindk->nam : "");
Index: Doc/Zsh/zle.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/zle.yo,v
retrieving revision 1.41
diff -u -r1.41 zle.yo
--- Doc/Zsh/zle.yo	8 Sep 2004 15:24:08 -0000	1.41
+++ Doc/Zsh/zle.yo	8 Sep 2004 16:52:55 -0000
@@ -732,6 +732,16 @@
 item(tt(WIDGET) (scalar))(
 The name of the widget currently being executed; read-only.
 )
+vindex(WIDGETSTYLE)
+item(tt(WIDGET) (scalar))(
+Describes the implementation behind the widget currently being executed;
+the second argument that followed tt(zle -C) or tt(zle -N) when the widget
+was defined, if any.  If the widget was defined with tt(zle -N) and there was
+no second argument this is the same as the first argument.  Hence for
+tt(zle -N) this gives the name of the function that implements the widget,
+and for tt(zle -C) this gives the internal completion widget that defines
+the type of completion.  Read-only.
+)
 enditem()
 
 subsect(Special Widget)

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************


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

* Re: Difficulties with _oldlist
  2004-09-08 16:56 ` Peter Stephenson
@ 2004-09-10  8:04   ` Bart Schaefer
  2004-09-10 10:59     ` Peter Stephenson
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2004-09-10  8:04 UTC (permalink / raw)
  To: zsh-workers

On Wed, 8 Sep 2004, Peter Stephenson wrote:

> Bart Schaefer wrote:
> > $WIDGET could be replaced by a different variable, say $WIDGETSTYLE for
> > example, which is set corresponding to the second argument of "zle -C".
> 
> This is the internal implementation.  For a "zle -N" widget $WIDGETSTYLE
> gives the name of the function that implements the widget.

Hmm, interesting.  I'd rather put the name of the function in yet another
variable (WIDGETFUNC ?) and have it available for "zle -C" widgets, too.

For "zle -N" widgets, I think WIDGETSTYLE should initially be unset, so it 
can be tested with [[ -z ]] to differentiate completion from "normal" when 
inside a widget function.  (If it's just the function name, there's no way 
of preventing a function having the same name as a builtin widget, thereby
confusing matters.)


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

* Re: Difficulties with _oldlist
  2004-09-10  8:04   ` Bart Schaefer
@ 2004-09-10 10:59     ` Peter Stephenson
  2004-09-13 13:21       ` Peter Stephenson
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Stephenson @ 2004-09-10 10:59 UTC (permalink / raw)
  To: zsh-workers

Bart Schaefer wrote:
> Hmm, interesting.  I'd rather put the name of the function in yet another
> variable (WIDGETFUNC ?) and have it available for "zle -C" widgets, too.
> 
> For "zle -N" widgets, I think WIDGETSTYLE should initially be unset, so it 
> can be tested with [[ -z ]] to differentiate completion from "normal" when 
> inside a widget function.  (If it's just the function name, there's no way 
> of preventing a function having the same name as a builtin widget, thereby
> confusing matters.)

This sounds reasonable.  It's easier to make WIDGETSTYLE set to the
empty string for zle -N widgets, rather than unset, since otherwise we
need to set up the parameters differently for the two types.  However,
it would be possible to post process the list to unset it.  (Not setting
up the variable at all isn't an option since then we can't guarantee
it's unset.)  I think it's OK as it is, however, since it gives you an
easy test.

Index: Doc/Zsh/zle.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/zle.yo,v
retrieving revision 1.42
diff -u -r1.42 zle.yo
--- Doc/Zsh/zle.yo	9 Sep 2004 10:12:46 -0000	1.42
+++ Doc/Zsh/zle.yo	10 Sep 2004 09:56:53 -0000
@@ -732,15 +732,21 @@
 item(tt(WIDGET) (scalar))(
 The name of the widget currently being executed; read-only.
 )
+vindex(WIDGETFUNC)
+item(tt(WIDGETFUNC) (scalar))(
+The name of the shell function that implements a widget defined with
+either tt(zle -N) or tt(zle -C).  In the former case, this is the second
+argument to the tt(zle -N) command that defined the widget, or
+the first argument if there was no second argument.  In the latter case
+this is the the third argument to the tt(zle -C) command that defined the
+widget.  Read-only.
+)
 vindex(WIDGETSTYLE)
-item(tt(WIDGET) (scalar))(
-Describes the implementation behind the widget currently being executed;
-the second argument that followed tt(zle -C) or tt(zle -N) when the widget
-was defined, if any.  If the widget was defined with tt(zle -N) and there was
-no second argument this is the same as the first argument.  Hence for
-tt(zle -N) this gives the name of the function that implements the widget,
-and for tt(zle -C) this gives the internal completion widget that defines
-the type of completion.  Read-only.
+item(tt(WIDGETSTYLE) (scalar))(
+Describes the implementation behind the completion widget currently being
+executed; the second argument that followed tt(zle -C) when the widget was
+defined.  This is the name of a builtin completion widget.  For widgets
+defined with tt(zle -N) this is set to the empty string.  Read-only.
 )
 enditem()
 
Index: Src/Zle/zle_params.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_params.c,v
retrieving revision 1.17
diff -u -r1.17 zle_params.c
--- Src/Zle/zle_params.c	9 Sep 2004 10:12:47 -0000	1.17
+++ Src/Zle/zle_params.c	10 Sep 2004 09:56:53 -0000
@@ -93,6 +93,8 @@
 	zleunsetfn, NULL },
     { "WIDGET", PM_SCALAR | PM_READONLY, NULL, FN(get_widget),
         zleunsetfn, NULL },
+    { "WIDGETFUNC", PM_SCALAR | PM_READONLY, NULL, FN(get_widgetfunc),
+        zleunsetfn, NULL },
     { "WIDGETSTYLE", PM_SCALAR | PM_READONLY, NULL, FN(get_widgetstyle),
 	zleunsetfn, NULL },
     { NULL, 0, NULL, NULL, NULL, NULL }
@@ -282,6 +284,21 @@
 
 /**/
 static char *
+get_widgetfunc(UNUSED(Param pm))
+{
+    Widget widget = bindk->widget;
+    int flags = widget->flags;
+
+    if (flags & WIDGET_INT)
+	return ".internal";	/* Don't see how this can ever be returned... */
+    else if (flags & WIDGET_NCOMP)
+	return widget->u.comp.func;
+    else
+	return widget->u.fnnam;
+}
+
+/**/
+static char *
 get_widgetstyle(UNUSED(Param pm))
 {
     Widget widget = bindk->widget;
@@ -292,7 +309,7 @@
     else if (flags & WIDGET_NCOMP)
 	return widget->u.comp.wid;
     else
-	return widget->u.fnnam;
+	return "";
 }
 
 /**/

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************


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

* Re: Difficulties with _oldlist
  2004-09-10 10:59     ` Peter Stephenson
@ 2004-09-13 13:21       ` Peter Stephenson
  0 siblings, 0 replies; 5+ messages in thread
From: Peter Stephenson @ 2004-09-13 13:21 UTC (permalink / raw)
  To: zsh-workers

As far as I can tell, this is working.

Index: Completion/Base/Completer/_oldlist
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/Completer/_oldlist,v
retrieving revision 1.1
diff -u -r1.1 _oldlist
--- Completion/Base/Completer/_oldlist	2 Apr 2001 11:08:37 -0000	1.1
+++ Completion/Base/Completer/_oldlist	13 Sep 2004 13:20:28 -0000
@@ -15,7 +15,7 @@
 
 if [[ -n $compstate[old_list] && $list != never &&
       $LASTWIDGET != _complete_help && $WIDGET != _complete_help ]]; then
-  if [[ $WIDGET = *list* && ( $list = always || $list != shown ) ]]; then
+  if [[ $WIDGETSTYLE = *list* && ( $list = always || $list != shown ) ]]; then
     compstate[old_list]=keep
     return 0
   elif [[ $list = *${_lastcomp[completer]}* ]]; then
@@ -39,11 +39,11 @@
       $LASTWIDGET != _complete_help && $WIDGET != _complete_help ]]; then
   compstate[old_list]=keep
   return 0
-elif [[ $WIDGET = *complete(|-prefix|-word) ]] &&
+elif [[ $WIDGETSTYLE = *complete(|-prefix|-word) ]] &&
      zstyle -T ":completion:${curcontext}:" old-menu; then
   if [[ -n $compstate[old_insert] ]]; then
     compstate[old_list]=keep
-    if [[ $WIDGET = *reverse* ]]; then
+    if [[ $WIDGETSTYLE = *reverse* ]]; then
       compstate[insert]=$(( compstate[old_insert] - 1 ))
     else
       compstate[insert]=$(( compstate[old_insert] + 1 ))

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************


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

end of thread, other threads:[~2004-09-13 13:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-23 15:51 Difficulties with _oldlist Bart Schaefer
2004-09-08 16:56 ` Peter Stephenson
2004-09-10  8:04   ` Bart Schaefer
2004-09-10 10:59     ` Peter Stephenson
2004-09-13 13:21       ` 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).