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

Re: configure --with- completion



2015/10/20 22:00, Vincent Lefevre <vincent@xxxxxxxxxx> wrote:

> The problem seems to come to the fact that
> 
>  --with-gmp-build=DIR    GMP build directory (please read INSTALL file)
> 
> is listed after
> 
>  --with-gmp=DIR          GMP install directory

Yes. For example, 

% _foo() { 
_arguments : '-x=:switch:(on off)' '-xy=:answer:(yes no)' '*:file:_files'
}
% compdef _foo foo
% foo -xy=<TAB>

this completes nothing. If -x and -xy are exchanged, it works as expected.

In ca_get_opt() (computil.c:1167), the current word seems to be compared
with optspecs in the order they are passed to _arguments.  In the example
above, the current word "-xy=" is first compared with '-x', and since
'-x' matches with the beginning of "-xy=" (strpfx() at line 1695),
it is considered as the option -x followed by 'y='. So the next (correct)
optspec '-xy' is not tried.

Probably we need to look at the next character after the option '-x'
('y' in the above example), and if the type of the option is CAO_OEQUAL
and the next character is not '=' (or NULL), then reject '-x' and 
go to the next possible option '-xy'. But I rather hesitate to modify
functions which I don't understand well yet.

A workaround (for '_arguments --') would be to modify _arguments as in
the patch below. It sorts the optspecs generated by '_arguments --'
so that --with-gmp-build comes before --with-gmp.

But this patch has effect only with '_arguments --', and does not fix
the example above (-x and -xy). Patching computil.c would be better ...



diff --git a/Completion/Base/Utility/_arguments b/Completion/Base/Utility/_arguments
index 87fb20e..fa9750e 100644
--- a/Completion/Base/Utility/_arguments
+++ b/Completion/Base/Utility/_arguments
@@ -303,7 +303,13 @@ if (( long )); then
         fi
       fi
     done
-    set -A "$name" "${(@)cache:# #}"
+    # Sort the optspecs in $cache so that -xy comes before -x (this
+    # seems to be required by a restriction (or bug) of comparguments).
+    # We do this by the following steps:
+    #     add '~' at the end of option name,  sort,  and remove '~'.
+    #     ('~'=0x7e comes after any other printable ASCII characters)
+    tmp=( ${${(o)${${cache:# #}/(#b)([a-zA-Z0-9_-]#)/$match[1]~}}/\~/} )
+    set -A "$name" "$tmp[@]"
   fi
   set -- "$tmpargv[@]" "${(@P)name}"
 fi





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