zsh-workers
 help / color / mirror / code / Atom feed
* _arguments: normal arg spec with empty action
@ 2016-10-18 13:35 Jun T.
  2016-10-21  6:31 ` Oliver Kiddle
  2016-11-03 23:53 ` Oliver Kiddle
  0 siblings, 2 replies; 5+ messages in thread
From: Jun T. @ 2016-10-18 13:35 UTC (permalink / raw)
  To: zsh-workers

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:'
Adding a space ('1:program text: ') does not work.

The following patch fixes the problem, but is this the best way to go?


diff --git a/Completion/Unix/Command/_awk b/Completion/Unix/Command/_awk
index c493c3b..1645048 100644
--- a/Completion/Unix/Command/_awk
+++ b/Completion/Unix/Command/_awk
@@ -17,5 +17,5 @@
 _arguments -S -s '-F+[define input field separator to be an extended regular expression]:extended regular expression:' \
     '*-v+[assign values to variables]:assignment:' \
     '(1)-f+[program file]:program file:_files' \
-    '1:program text:' \
+    '1: : _message "program text"' \
     '*:input files:_files'



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

* Re: _arguments: normal arg spec with empty action
  2016-10-18 13:35 _arguments: normal arg spec with empty action Jun T.
@ 2016-10-21  6:31 ` Oliver Kiddle
  2016-10-21 11:12   ` Jun T.
  2016-11-03 23:53 ` Oliver Kiddle
  1 sibling, 1 reply; 5+ messages in thread
From: Oliver Kiddle @ 2016-10-21  6:31 UTC (permalink / raw)
  To: Jun T.; +Cc: zsh-workers

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.

I can't reproduce this so perhaps there's something setup related.
Does pressing tab a third time work?

> The following patch fixes the problem, but is this the best way to go?
> +    '1: : _message "program text"' \

Does _guard work? For a heading without matches, _message -e should be
used but that roughly what _arguments is doing.

Oliver


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

* Re: _arguments: normal arg spec with empty action
  2016-10-21  6:31 ` Oliver Kiddle
@ 2016-10-21 11:12   ` Jun T.
  0 siblings, 0 replies; 5+ messages in thread
From: Jun T. @ 2016-10-21 11:12 UTC (permalink / raw)
  To: zsh-workers


On 2016/10/21, at 15:31, Oliver Kiddle <okiddle@yahoo.co.uk> wrote:
> 
> I can't reproduce this so perhaps there's something setup related.
> Does pressing tab a third time work?

For me it happens even with 'zsh -f':

$ zsh -f
% autoload -Uz compinit
% compinit
% awk -<TAB>

The first <TAB> lists the options, but hitting <TAB> again (or
again and again ...) does not complete options.

>> The following patch fixes the problem, but is this the best way to go?
>> +    '1: : _message "program text"' \
> 
> Does _guard work? For a heading without matches, _message -e should be
> used but that roughly what _arguments is doing.

Thanks, the following seems to work:

	'1: : _guard "^-*" "program text"'

and I think this is better, because with the style

% zstyle ':completion:*:descriptions' format '%d'

and if _message is used, then

% awk -<TAB>

will print both "program text" and "options", but only
"options" is printed if _guard is used.


Jun


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

* Re: _arguments: normal arg spec with empty action
  2016-10-18 13:35 _arguments: normal arg spec with empty action Jun T.
  2016-10-21  6:31 ` Oliver Kiddle
@ 2016-11-03 23:53 ` Oliver Kiddle
  2016-11-15  0:31   ` Oliver Kiddle
  1 sibling, 1 reply; 5+ messages in thread
From: Oliver Kiddle @ 2016-11-03 23:53 UTC (permalink / raw)
  To: Jun T.; +Cc: zsh-workers

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>

Oliver

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)
 	endparamscope();
 	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)
 #endif
 	    }
 	}
-	startauto = ((compinsert &&
+	startauto = startauto || ((compinsert &&
 		      !strcmp(compinsert, "automenu-unambiguous")) ||
 		     (bashlistfirst && isset(AUTOMENU) &&
                       (!compinsert || !*compinsert)));


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

* Re: _arguments: normal arg spec with empty action
  2016-11-03 23:53 ` Oliver Kiddle
@ 2016-11-15  0:31   ` Oliver Kiddle
  0 siblings, 0 replies; 5+ messages in thread
From: Oliver Kiddle @ 2016-11-15  0:31 UTC (permalink / raw)
  To: Jun T., zsh-workers

On 4 Nov, I wrote:
> 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:

This further patch covers these cases. There's many combinations of
options and zstyles that might affect this. So to test with your
configuration try repeated presses of <tab> for the following completion
definition:
  compdef '_arguments --ab --ac :arg:' foo

The first case is handled by making _message only clear
compstate[insert] if the current value contains unambiguous. This makes
sense for _message -e style messages because all we want to do is
prevent the insertion of unambiguous characters (other characters may be
relevant to the group indicated by the message). menu completion
is not really a problem because it is inserting more characters than the
unambiguous ones by definition.

For BASH_AUTO_LIST, setting lastambig seems appropriate. It causes
subsequent invocations of completion to set bashautolist. So first tab
does nothing, second lists, third does menu completion if AUTO_MENU is
set.

Test cases have gone in Y03arguments because _arguments is the easiest
way to test this but it doesn't really have much to do with _arguments.
It's more about _message.

Oliver

diff --git a/Completion/Base/Core/_message b/Completion/Base/Core/_message
index 13c8398..4d5645e 100644
--- a/Completion/Base/Core/_message
+++ b/Completion/Base/Core/_message
@@ -18,7 +18,8 @@ if [[ "$1" = -e ]]; then
     ret=0
   done
 
-  (( $compstate[nmatches] )) || compstate[insert]=
+  (( ! $compstate[nmatches] )) && [[ $compstate[insert] = *unambiguous* ]] &&
+      compstate[insert]=
 
   return ret
 fi
diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c
index 536bca7..d1cf7a0 100644
--- a/Src/Zle/compcore.c
+++ b/Src/Zle/compcore.c
@@ -425,6 +425,7 @@ do_completion(UNUSED(Hookdef dummy), Compldat dat)
 	}
     } else {
 	invalidatelist();
+	lastambig = isset(BASHAUTOLIST);
 	if (forcelist)
 	    clearlist = 1;
 	zlemetacs = 0;
diff --git a/Test/Y03arguments.ztst b/Test/Y03arguments.ztst
index 3ada168..0763c41 100644
--- a/Test/Y03arguments.ztst
+++ b/Test/Y03arguments.ztst
@@ -243,6 +243,67 @@
 >NO:{-a}
 >NO:{-b}
 
+ tst_arguments --abc --aah :arg:
+ comptesteval 'setopt bashautolist automenu'
+ comptest $'tst --a\t\t\t'
+0:with message and bashautolist, a third tab will get menu completion
+>line: {tst --a}{}
+>line: {tst --a}{}
+>DESCRIPTION:{arg}
+>DESCRIPTION:{option}
+>NO:{--aah}
+>NO:{--abc}
+>line: {tst --aah}{}
+
+ tst_arguments --abc --aah :arg:
+ comptesteval 'setopt bashautolist noautomenu'
+ comptest $'tst --a\t\t\t'
+0:with message and bashautolist, a third tab is needed to display the list
+>line: {tst --a}{}
+>line: {tst --a}{}
+>DESCRIPTION:{arg}
+>DESCRIPTION:{option}
+>NO:{--aah}
+>NO:{--abc}
+>line: {tst --a}{}
+
+ tst_arguments --abc --aah :arg:
+ comptesteval 'setopt nobashautolist noautomenu'
+ comptest $'tst --\t\t'
+0:with message and noautomenu second tab redisplays the list
+>line: {tst --}{}
+>DESCRIPTION:{arg}
+>DESCRIPTION:{option}
+>NO:{--aah}
+>NO:{--abc}
+>line: {tst --}{}
+>DESCRIPTION:{arg}
+>DESCRIPTION:{option}
+>NO:{--aah}
+>NO:{--abc}
+
+ tst_arguments --abc --aah :arg:
+ comptesteval 'setopt nobashautolist automenu'
+ comptest $'tst --\t\t'
+0:with message two tabs will start menu completion
+>line: {tst --}{}
+>DESCRIPTION:{arg}
+>DESCRIPTION:{option}
+>NO:{--aah}
+>NO:{--abc}
+>line: {tst --aah}{}
+
+ tst_arguments --abc --aah :arg:
+ comptesteval 'zstyle ":completion:*::::" completer _oldlist _complete'
+ comptest $'tst --\t\t'
+0:with message and _oldlist, two tabs will start menu completion
+>line: {tst --}{}
+>DESCRIPTION:{arg}
+>DESCRIPTION:{option}
+>NO:{--aah}
+>NO:{--abc}
+>line: {tst --aah}{}
+
 %clean
 
   zmodload -ui zsh/zpty


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

end of thread, other threads:[~2016-11-15  0:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-18 13:35 _arguments: normal arg spec with empty action Jun T.
2016-10-21  6:31 ` Oliver Kiddle
2016-10-21 11:12   ` Jun T.
2016-11-03 23:53 ` Oliver Kiddle
2016-11-15  0:31   ` Oliver Kiddle

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