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

Re: _arguments: normal arg spec with empty action

On 18 Oct, "Jun T." wrote:
> If I type
> zsh% awk -<TAB>
> then it shows the list of options (-F -f -v), as expected.
> But if I hit <TAB> again, it does not cycle through the options.
> It seems this is caused by the empty action in the spec:
> 	'1:program text:'

I took a closer look at this. The reason I couldn't reproduce it
is that I use _oldlist in my list of completers. Still, I need a
third tab to get menu completion which didn't seem right. Normally,
a first tab will insert an unambiguous prefix, the second does the
list and the third goes to menu completion. An empty action spec
such as that above results in _message doing compstate[insert]=''.
This forces listing and ensures that nothing is inserted so that
the user can see that "program text" is a valid thing to insert at
this point. So the first tab does the listing, the second still
won't insert any unambiguous prefix but completion does record that
that stage is done so the third will start menu completion.

This patch adds some logic so that when compstate[insert] is found
to be empty, and AUTO_MENU is set, it knows that it can consider
the unambiguous insert bit done.

This doesn't help if you don't use _oldlist because compstate[insert]
gets cleared for every tab press. I also noticed when doing testing
that with the BASH_AUTO_LIST option you never get anything useful
at all for functions that clear compstate[insert]. I'm surprised we
haven't had complaints about that:
  zsh -f
  autoload -U compinit; compinit
  setopt bash_auto_list
  grep -<tab><tab><tab><tab><tab>


diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c
index 5443018..d7fbea5 100644
--- a/Src/Zle/compcore.c
+++ b/Src/Zle/compcore.c
@@ -835,6 +835,7 @@ callcompfunc(char *s, char *fn)
 	lastcmd = 0;
 	incompfunc = icf;
+	startauto = 0;
 	if (!complist)
 	    uselist = 0;
@@ -882,8 +883,13 @@ callcompfunc(char *s, char *fn)
 		useline = 1, usemenu = 1;
 	    else if (strpfx("auto", compinsert))
 		useline = 1, usemenu = 2;
-	    else
+	    else {
 		useline = usemenu = 0;
+		/* if compstate[insert] was emptied, no unambiguous prefix
+		 * ever gets inserted so allow the next tab to already start
+		 * menu completion */
+		startauto = lastambig = isset(AUTOMENU);
+	    }
 	    if (useline && (p = strchr(compinsert, ':'))) {
 		insmnum = atoi(++p);
@@ -896,7 +902,7 @@ callcompfunc(char *s, char *fn)
-	startauto = ((compinsert &&
+	startauto = startauto || ((compinsert &&
 		      !strcmp(compinsert, "automenu-unambiguous")) ||
 		     (bashlistfirst && isset(AUTOMENU) &&
                       (!compinsert || !*compinsert)));

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