zsh-workers
 help / color / mirror / code / Atom feed
From: "Jun T." <takimoto-j@kba.biglobe.ne.jp>
To: zsh-workers@zsh.org
Subject: Re: configure --with- completion
Date: Thu, 22 Oct 2015 01:11:55 +0900	[thread overview]
Message-ID: <B63BC678-98DD-4BDF-9C77-6EB2FA21C290@kba.biglobe.ne.jp> (raw)
In-Reply-To: <20151020130008.GA20896@zira.vinc17.org>


2015/10/20 22:00, Vincent Lefevre <vincent@vinc17.net> 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




  reply	other threads:[~2015-10-21 17:44 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20150904084027.GA15509@zira.vinc17.org>
2015-10-20 13:00 ` Vincent Lefevre
2015-10-21 16:11   ` Jun T. [this message]
2015-10-22  7:51     ` Jun T.
2015-10-24 17:00       ` Peter Stephenson

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=B63BC678-98DD-4BDF-9C77-6EB2FA21C290@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).