zsh-workers
 help / color / mirror / code / Atom feed
From: Jun T <takimoto-j@kba.biglobe.ne.jp>
To: zsh-workers@zsh.org
Subject: Re: [BUG] _gnu_generic completer produces broken output
Date: Wed, 28 Jul 2021 18:38:53 +0900	[thread overview]
Message-ID: <2DB7CAE3-29F6-41C2-95CE-687CD5E6BA92@kba.biglobe.ne.jp> (raw)
In-Reply-To: <8FC07840-27C0-48AD-A8AF-120924B44491@kba.biglobe.ne.jp>

> 2021/07/27 12:57, Jun T <takimoto-j@kba.biglobe.ne.jp> wrote:
> 
> The case in workers/48091 is more obscure for me:
> 
>> autoload -Uz compinit; compinit
>> zstyle ':completion:*:functions' ignored-patterns '[[:punct:]]*[[:alnum:]]*'
>> zstyle ':completion:*:options' matcher 'b:-=+'
> 
> First _main_complete:218 calls _complete, but it fails (returns 1); why?

It fails because _functions (the last command run in _typeset) fails,
and _functions fails because there is no functions whose name starts with '-'.
Not calling _functions when completing options (as in my previous patch)
solves the problem, but I think it would be better to correctly set the
return value of _typeset as in the patch below.

If return value is correctly set, the previous patch

-    else
+    elif [[ $PREFIX != [-+]* ]]; then

is not necessary, but I kept it because calling _functions when completing
options is just a waste of time (I assume no one would create a function whose
name starts with '-' or '+').

Also added state_descr to the list of local parameters.


diff --git a/Completion/Zsh/Command/_typeset b/Completion/Zsh/Command/_typeset
index aecacb112..be1fc7e85 100644
--- a/Completion/Zsh/Command/_typeset
+++ b/Completion/Zsh/Command/_typeset
@@ -1,6 +1,6 @@
 #compdef autoload declare export functions integer float local readonly typeset
 
-local expl state line func i use curcontext="$curcontext"
+local expl state state_descr line func i use curcontext="$curcontext" ret=1
 local fopts="-f -k -z +k +z"
 local popts="-A -E -F -L -R -T -Z -a -g -h -H -i -l -r -x"
 local -A allargs opt_args
@@ -86,31 +86,31 @@ for ((i=1;i<=$#use;++i)); do
   args+=( ${allargs[${use[$i]}${${(s::)use[$i]}[(r)[dUurRtT]]:+$func}]} )
 done
 
-_arguments -C -s -A "-*" -S "${args[@]}" '*::vars:= ->vars_eq'
+_arguments -C -s -A "-*" -S "${args[@]}" '*::vars:= ->vars_eq' && ret=0
 
 if [[ "$state" = vars_eq ]]; then
   if [[ $func = f ]]; then
     if (( $+opt_args[+M] || ( $+opt_args[-M] && $+opt_args[-m] ) )); then
       _wanted functions expl 'math function' compadd -F line - \
-          ${${${(f)"$(functions -M)"}##*-M }%% *}
+          ${${${(f)"$(functions -M)"}##*-M }%% *} && ret=0
     elif (( $+opt_args[-M] )); then
       _arguments ':new math function:_functions' \
 	":minimum arguments${(k)opt_args[-s]:+:(1)}" \
 	":maximum arguments${(k)opt_args[-s]:+:(1)}" \
-	':shell function:_functions'
+	':shell function:_functions' && ret=0
     elif (( $+opt_args[-w] )); then
-      _wanted files expl 'zwc file' _files -g '*.zwc(-.)'
+      _wanted files expl 'zwc file' _files -g '*.zwc(-.)' && ret=0
     elif [[ $service = autoload || -n $opt_args[(i)-[uU]] ]]; then
       if [[ $PREFIX[1] = [/~] ]]; then
 	# Autoload by absolute path
-	_files
+	_files && ret=0
       else
 	  args=(${^fpath}/*(-.:t))
 	  # Filter out functions already loaded or marked for autoload.
 	  local -a funckeys
 	  funckeys=(${(k)functions})
 	  args=(${args:|funckeys})
-	  _wanted functions expl 'shell function' compadd -a args
+	  _wanted functions expl 'shell function' compadd -a args && ret=0
       fi
     elif [[ -n $onopts$offopts ]]; then
       if [[ -n $offopts ]]; then
@@ -127,22 +127,23 @@ if [[ "$state" = vars_eq ]]; then
 	[[ $PREFIX != [_.]* ]]; then
 	args=(${args:#_*})
       fi
-      _wanted functions expl 'shell function' compadd -a args
-    else
-      _functions
+      _wanted functions expl 'shell function' compadd -a args && ret=0
+    elif [[ $PREFIX != [-+]* ]]; then
+      _functions && ret=0
     fi
   elif [[ "$PREFIX" = *\=* ]]; then
     compstate[parameter]="${PREFIX%%\=*}"
     compset -P 1 '*='
-    _value
+    _value && ret=0
   elif (( $+opt_args[-a] || $+opt_args[-A] )); then
-    _parameters -q
+    _parameters -q && ret=0
   elif (( $+opt_args[-T] )); then
     _arguments \
       ':scalar parameter:_parameters -g "*scalar*" -q -S "="' \
       ':array parameter:_parameters -g "*array*"' \
-      ':separator character'
+      ':separator character' && ret=0
   else
-    _parameters -q -S '='
+    _parameters -q -S '=' && ret=0
   fi
 fi
+return ret




  reply	other threads:[~2021-07-28  9:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-22 19:39 Marlon Richert
2021-07-27  3:57 ` Jun T
2021-07-28  9:38   ` Jun T [this message]
2021-07-28 10:29     ` Mikael Magnusson
2021-07-28 11:13       ` Jun T
2021-08-01 14:26 ` Marlon Richert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2DB7CAE3-29F6-41C2-95CE-687CD5E6BA92@kba.biglobe.ne.jp \
    --to=takimoto-j@kba.biglobe.ne.jp \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).