From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9079 invoked by alias); 29 Sep 2015 16:53:57 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 36697 Received: (qmail 16038 invoked from network); 29 Sep 2015 16:53:55 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.0 X-Biglobe-Sender: Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) Subject: Re: [PATCH] handle options of _arguments correctly From: "Jun T." In-Reply-To: <150928164855.ZM29167@torch.brasslantern.com> Date: Wed, 30 Sep 2015 01:12:51 +0900 Content-Transfer-Encoding: quoted-printable Message-Id: <3D6A6B84-A584-4915-BB8F-521AB490FA01@kba.biglobe.ne.jp> References: <150928164855.ZM29167@torch.brasslantern.com> To: zsh-workers@zsh.org X-Mailer: Apple Mail (2.1878.6) X-Biglobe-Spnum: 53407 2015/09/29 08:48, Bart Schaefer wrote: > I don't see anything immediate (though this renders the name "singsub" > for the array somewhat nonsensical). Do you mean 'singopt'? I guess it means 'single-letter option'. It may not be a good name because all the options of _arugments are single-letter. It only saves the options -s -S -A -M which need be passed to 'comparguments -i' (line 2499 of Zle/computil.c). > _arguments -s -w -q -s -- > and > _arguments -s -w : -q -s -- >=20 > are equivalent becaue of the -q (even though I'd hope no one wrote the > former in an actual completion function). Which I think is what your > patch accomplishes Yes, but it was not sufficient. % bar() { echo '\t-S\n\t-a' } % compdef '_arguments --' bar % bar - this only offers -a. '_arguments : --' will offer both -S and -a. When 'comparguments -i' is called, $singopt is empty and "$@" is "-S" = "-a". But comparguments considers the first -S as an options to _arguments (line 1203 and below in computil.c). I think we need explicitly pass ':' to comparguments. The following is a patch against the current master and includes my = previous one. I also dropped the "if [[ long -eq 1 ]]; then ...", because this = always evaluates to false (it should have been $long, but anyway $argv[1,0] = expands to null string and long=3D=3D1 need not be treated specially). diff --git a/Completion/Base/Utility/_arguments = b/Completion/Base/Utility/_arguments index 1f35e8d..95ef621 100644 --- a/Completion/Base/Utility/_arguments +++ b/Completion/Base/Utility/_arguments @@ -8,15 +8,33 @@ local oldcontext=3D"$curcontext" hasopts rawret optarg = singopt alwopt local setnormarg start rest local -a match mbegin mend =20 +subopts=3D() +singopt=3D() +while [[ "$1" =3D -([AMO]*|[CRSWnsw]) ]]; do + case "$1" in + -C) usecc=3Dyes; shift ;; + -O) subopts=3D( "${(@P)2}" ); shift 2 ;; + -O*) subopts=3D( "${(@P)${1[3,-1]}}" ); shift ;; + -R) rawret=3Dyes; shift;; + -n) setnormarg=3Dyes; NORMARG=3D-1; shift;; + -w) optarg=3Dyes; shift;; + -W) alwopt=3Darg; shift;; + -[Ss]) singopt+=3D( $1 ); shift;; + -[AM]) singopt+=3D( $1 $2 ); shift 2 ;; + -[AM]*) singopt+=3D( $1 ); shift ;; + esac +done + +[[ $1 =3D=3D ':' ]] && shift +singopt+=3D( ':' ) # always end with ':' to indicate the end of = options + +[[ "$PREFIX" =3D [-+] ]] && alwopt=3Darg + long=3D$argv[(I)--] if (( long )); then local name tmp tmpargv =20 - if [[ long -eq 1 ]]; then - tmpargv=3D() - else - tmpargv=3D( "${(@)argv[1,long-1]}" ) - fi + tmpargv=3D( "${(@)argv[1,long-1]}" ) # optspec's before --, if any =20 name=3D${~words[1]} [[ "$name" =3D [^/]*/* ]] && name=3D"$PWD/$name" @@ -290,23 +308,6 @@ if (( long )); then set -- "$tmpargv[@]" "${(@P)name}" fi =20 -subopts=3D() -singopt=3D() -while [[ "$1" =3D -(O*|[CRWnsw]) ]]; do - case "$1" in - -C) usecc=3Dyes; shift ;; - -O) subopts=3D( "${(@P)2}" ); shift 2 ;; - -O*) subopts=3D( "${(@P)${1[3,-1]}}" ); shift ;; - -R) rawret=3Dyes; shift;; - -n) setnormarg=3Dyes; NORMARG=3D-1; shift;; - -w) optarg=3Dyes; shift;; - -s) singopt=3D(-s); shift;; - -W) alwopt=3Darg; shift;; - esac -done - -[[ "$PREFIX" =3D [-+] ]] && alwopt=3Darg - zstyle -s ":completion:${curcontext}:options" auto-description autod =20 if (( $# )) && comparguments -i "$autod" "$singopt[@]" "$@"; then