zsh-workers
 help / color / mirror / code / Atom feed
* Re: PATCH: zle parameters in completion widgets
@ 1999-02-01  8:15 Sven Wischnowsky
  0 siblings, 0 replies; 3+ messages in thread
From: Sven Wischnowsky @ 1999-02-01  8:15 UTC (permalink / raw)
  To: zsh-workers


Bart Schaefer wrote:

> On Jan 29, 11:08am, Sven Wischnowsky wrote:
> } Subject: PATCH: zle parameters in completion widgets
> }
> } Now, to get completion only on the second tab, just add
> } 
> }   [[ "$WIDGET" != "$LASTWIDGET" ]] && return
> 
> Actually, the request as for completion on the first tab, but autolist
> only on the second tab.

[That would be only `setopt LIST_AMBIGUOUS'.]

After playing with bash a bit, it seems that to fully copy the
behaviour one would have to setopt LIST_AMBIGUOUS and use something
like:

  lastbuffer=''  # non-local variable definition

  ...

  completion-widget() {
    ...
    [[ "$BUFFER" = "$lastbuffer" && "$WIDGET" != "$LASTWIDGET" ]] && return
    ...
  }

At least I get completion of the unambiguous stuff on the first tab,
nothing on the second and the list on the third.


> So it'd have to be something like
> 
>     [[ "$WIDGET" != "$LASTWIDGET" ]] && complist ...
> 
> where "..." gets filled in appropriately for whatever other completion
> is in progress.  Right?

See above. Also: to allow the completion widget to say if only
something should be inserted or if also the list should be shown, we
would need a way to control this kind of stuff from the widget. This
is on my wish list (it also appears somewhere in my longish
description mail), but not yet implemented.

Bye
 Sven


--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


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

* Re: PATCH: zle parameters in completion widgets
  1999-01-29 10:08 Sven Wischnowsky
@ 1999-01-29 17:04 ` Bart Schaefer
  0 siblings, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 1999-01-29 17:04 UTC (permalink / raw)
  To: zsh-workers

On Jan 29, 11:08am, Sven Wischnowsky wrote:
} Subject: PATCH: zle parameters in completion widgets
}
} Now, to get completion only on the second tab, just add
} 
}   [[ "$WIDGET" != "$LASTWIDGET" ]] && return

Actually, the request as for completion on the first tab, but autolist
only on the second tab.  So it'd have to be something like

    [[ "$WIDGET" != "$LASTWIDGET" ]] && complist ...

where "..." gets filled in appropriately for whatever other completion
is in progress.  Right?

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


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

* PATCH: zle parameters in completion widgets
@ 1999-01-29 10:08 Sven Wischnowsky
  1999-01-29 17:04 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Sven Wischnowsky @ 1999-01-29 10:08 UTC (permalink / raw)
  To: zsh-workers


The patch below does two things:

  - making the zle-parameters (BUFFER, ...) available in completion
    widgets; for now they are readonly inside completion widgets
  - adding two new zle parameters: `WIDGET' and `LASTWIDGET' hold the
    names of the widget that is currently being executed and the name
    of the widget that was executed before; both of them are always
    readonly

I'm not sure if you like that second addition, but I think it may be
handy in some cases. Still, I can remove it again, if you want (or
send a patch with only the first change).

Now, to get completion only on the second tab, just add

  [[ "$WIDGET" != "$LASTWIDGET" ]] && return

add the top of you completion widget (main-complete in the example
file).

Bye
 Sven

P.S.: Yes, I saw that my last example code for the double-tab stuff
      couldn't work.

diff -u os/Zle/zle_main.c Src/Zle/zle_main.c
--- os/Zle/zle_main.c	Fri Jan 29 10:05:03 1999
+++ Src/Zle/zle_main.c	Fri Jan 29 10:56:32 1999
@@ -45,10 +45,10 @@
 /**/
 int c;
 
-/* the binding for this key */
+/* the bindings for the previous and for this key */
 
 /**/
-Thingy bindk;
+Thingy lbindk, bindk;
 
 /* insert mode/overwrite mode flag */
 
@@ -554,6 +554,7 @@
 void
 execzlefunc(Thingy func)
 {
+    int r = 0;
     Widget w;
 
     if(func->flags & DISABLED) {
@@ -594,6 +595,7 @@
 	    w->u.fn();
 	if (!(wflags & ZLE_NOTCOMMAND))
 	    lastcmd = wflags;
+	r = 1;
     } else {
 	List l = getshfunc(w->u.fnnam);
 
@@ -610,14 +612,20 @@
 	    int osc = sfcontext;
 
 	    startparamscope();
-	    makezleparams();
+	    makezleparams(0);
 	    sfcontext = SFC_WIDGET;
 	    doshfunc(w->u.fnnam, l, NULL, 0, 1);
 	    sfcontext = osc;
 	    endparamscope();
 	    lastcmd = 0;
+	    r = 1;
 	}
     }
+    if (r) {
+	unrefthingy(lbindk);
+	refthingy(func);
+	lbindk = func;
+    }
 }
 
 /* initialise command modifiers */
@@ -881,6 +889,7 @@
 
     /* initialise the thingies */
     init_thingies();
+    lbindk = NULL;
 
     /* miscellaneous initialisations */
     stackhist = stackcs = -1;
@@ -920,6 +929,8 @@
 finish_zle(Module m)
 {
     int i;
+
+    unrefthingy(lbindk);
 
     cleanup_keymaps();
     deletehashtable(thingytab);
diff -u os/Zle/zle_params.c Src/Zle/zle_params.c
--- os/Zle/zle_params.c	Fri Jan 29 10:05:04 1999
+++ Src/Zle/zle_params.c	Fri Jan 29 10:57:05 1999
@@ -61,17 +61,22 @@
 	zleunsetfn, NULL },
     { "RBUFFER", PM_SCALAR,  FN(set_rbuffer), FN(get_rbuffer),
 	zleunsetfn, NULL },
+    { "WIDGET", PM_SCALAR | PM_READONLY, NULL, FN(get_widget),
+        zleunsetfn, NULL },
+    { "LASTWIDGET", PM_SCALAR | PM_READONLY, NULL, FN(get_lwidget),
+        zleunsetfn, NULL },
     { NULL, 0, NULL, NULL, NULL, NULL }
 };
 
 /**/
 void
-makezleparams(void)
+makezleparams(int ro)
 {
     struct zleparam *zp;
 
     for(zp = zleparams; zp->name; zp++) {
-	Param pm = createparam(zp->name, zp->type | PM_SPECIAL);
+	Param pm = createparam(zp->name, (zp->type | PM_SPECIAL |
+					  (ro ? PM_READONLY : 0)));
 	if (!pm)
 	    pm = (Param) paramtab->getnode(paramtab, zp->name);
 	DPUTS(!pm, "param not set in makezleparams");
@@ -196,4 +201,18 @@
 get_rbuffer(Param pm)
 {
     return metafy((char *)line + cs, ll - cs, META_HEAPDUP);
+}
+
+/**/
+static char *
+get_widget(Param pm)
+{
+    return bindk->nam;
+}
+
+/**/
+static char *
+get_lwidget(Param pm)
+{
+    return (lbindk ? lbindk->nam : "");
 }
diff -u os/Zle/zle_tricky.c Src/Zle/zle_tricky.c
--- os/Zle/zle_tricky.c	Fri Jan 29 10:05:05 1999
+++ Src/Zle/zle_tricky.c	Fri Jan 29 10:16:54 1999
@@ -3276,6 +3276,7 @@
 	incompfunc = 1;
 	startparamscope();
 	makecompparamsptr();
+	makezleparams(1);
 	sfcontext = SFC_CWIDGET;
 	NEWHEAPS(compheap) {
 	    doshfunc(fn, list, args, 0, 1);

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


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

end of thread, other threads:[~1999-02-01  8:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-02-01  8:15 PATCH: zle parameters in completion widgets Sven Wischnowsky
  -- strict thread matches above, loose matches on Subject: below --
1999-01-29 10:08 Sven Wischnowsky
1999-01-29 17:04 ` Bart Schaefer

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