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

Re: new menu selection and Re: New compinstall and bindkey



I wrote:

> Oliver Kiddle wrote:
> 
> > I've now looked at the new selection for menu completion. Firstly,
> > thanks Sven: it's great. There is one thing I don't like. When I move
> > the cursors to highlight the string I want to complete to and press
> > return, the highlighting is removed but menu-completion continues so if
> > I press tab again, it cycles through the selections as opposed to
> > accepting my selection and going on to complete whatever is next.
> 
> This once was intentional, when menu-select was intended as a
> menu-completion add-on. Now that it is more of a replacement we should 
> probably change this.

I've just taken send-break for it. So: send-break leaves selection
and you'll be in normal menu-completion and accept-line leaves
selection and accepts the current match. Accepting is done as for a
completion with only one match.

With that you can do

  bindkey -M menuselect '^J' send-break

to have return continue with menu-completion

Ok? Or should the meaning of send-break and accept-line be changed
(meaning: should the default for return be changed)?


Andrej Borsenkow wrote:

> I wanted to write about this anyway. Unfortunately, current widget system is not
> well suited for programming (in user-defined widgets). Currently widgets mostly
> are "high-level" ones, that do fairly complex tasks. That was fine when all
> widgets were builtin ones. But now more of a low-level, primitive widgets are
> needed - that do some well defined atomic action. Good example is completion.
> What is needed is probably such primitives as next-match, previous-match,
> insert-match, exit-menu etc. Using these most of other tasks could be easily
> porgrammed with user-defined widgets - and if some prove universally useful,
> they could be implemented as builtin.

That's what I suggested when I sent my first widget-args-patch. The
problem is to find out the generic functions behind all the
widgets. Also I was mainly thinking about (and still prefer in some
cases) changing more builtin widgets to accept options to get a
specific behavior, e.g. by changing complete-word to be able to do
everything the other completion widgets can (and probably more) by
giving it the right options. I hadn't thought about splitting the
completion stuff -- probably because I know too much about the
completion code ;-)

Bye
 Sven

diff -u od/Zsh/mod_complist.yo Doc/Zsh/mod_complist.yo
--- od/Zsh/mod_complist.yo	Tue Jun 29 12:51:32 1999
+++ Doc/Zsh/mod_complist.yo	Thu Jul  1 11:21:53 1999
@@ -99,7 +99,10 @@
 Selecting matches is done by moving the mark around using the zle movement
 functions. The zle functions tt(send-break) and tt(accept-line) can be used
 to leave menu-selection, leaving the match currently inserted into the line
-in place. The functions tt(accept-and-hold) and
+in place. In the case of tt(accept-line), the match currently inserted
+will be accepted and the immediatly trying completion again will
+complete after it. Using tt(send-break) leaves menu-selection and
+continues with normal menu-completion. The functions tt(accept-and-hold) and
 tt(accept-and-menu-complete) can be used to accept the match currently
 inserted and continue inserting matches after that. Matches inserted this
 way can be removed by invoking the tt(undo) function. Keys bound to one of
@@ -118,4 +121,9 @@
 tt(bindkey) builtin command (see
 ifzman(zmanref(zshmodules))\
 ifnzman(noderef(The zle Module))\
-).
+). For example, to make the return key leave menu-selection and
+continue with normal menu-completion one can call
+
+indent(tt(bindkey -M menuselect '^J' send-break))
+
+after loading the tt(complist) module.
diff -u os/Zle/complist.c Src/Zle/complist.c
--- os/Zle/complist.c	Wed Jun 30 11:56:57 1999
+++ Src/Zle/complist.c	Thu Jul  1 11:22:17 1999
@@ -649,12 +649,12 @@
     Cmgroup *pg;
     Thingy cmd;
     Menustack u = NULL;
-    int i = 0;
+    int i = 0, acc = 0;
     char *s;
 
     if (dummy && (!(s = getsparam("SELECTMIN")) ||
 		  (dat && dat->num < atoi(s))))
-	return 1;
+	return 0;
 
     selectlocalmap(mskeymap);
     noselect = 0;
@@ -681,10 +681,12 @@
 
     getk:
 
-	if (!(cmd = getkeycmd()) || cmd == Th(z_sendbreak) ||
-	    cmd == Th(z_acceptline))
+	if (!(cmd = getkeycmd()) || cmd == Th(z_sendbreak))
 	    break;
-	else if (cmd == Th(z_acceptandhold) ||
+	else if (cmd == Th(z_acceptline)) {
+	    acc = 1;
+	    break;
+	} else if (cmd == Th(z_acceptandhold) ||
 		 cmd == Th(z_acceptandmenucomplete)) {
 	    Menustack s = (Menustack) zhalloc(sizeof(*s));
 
@@ -847,11 +849,16 @@
     selectlocalmap(NULL);
     mselect = -1;
     inselect = 0;
+    if (acc) {
+	menucmp = 0;
+	lastambig = 0;
+	do_single(*(minfo.cur));
+    }
     if (!noselect) {
 	showinglist = -2;
 	zrefresh();
     }
-    return noselect;
+    return (!noselect ^ acc);
 }
 
 /* The widget function. */
diff -u os/Zle/zle_tricky.c Src/Zle/zle_tricky.c
--- os/Zle/zle_tricky.c	Wed Jun 30 11:56:59 1999
+++ Src/Zle/zle_tricky.c	Thu Jul  1 11:04:29 1999
@@ -108,7 +108,8 @@
 
 /* != 0 if we are in the middle of a menu completion */
 
-static int menucmp;
+/**/
+int menucmp;
 
 /* Information about menucompletion. */
 
@@ -346,7 +347,8 @@
  * on the second tab, a` la bash, and then automenu kicks in when     *
  * lastambig == 2.                                                    */
 
-static int lastambig;
+/**/
+int lastambig;
 
 /* This says what of the state the line is in when completion is started *
  * came from a previous completion. If the FC_LINE bit is set, the       *
@@ -1058,7 +1060,8 @@
 	dat.matches = amatches;
 	dat.num = nmatches;
 	dat.cur = NULL;
-	runhookdef(MENUSTARTHOOK, (void *) &dat);
+	if (runhookdef(MENUSTARTHOOK, (void *) &dat))
+	    menucmp = 0;
     }
     return ret;
 }

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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