From: "Jun T." <takimoto-j@kba.biglobe.ne.jp>
To: zsh-workers@zsh.org
Subject: Re: [PATCH] handle options of _arguments correctly
Date: Wed, 30 Sep 2015 01:12:51 +0900 [thread overview]
Message-ID: <3D6A6B84-A584-4915-BB8F-521AB490FA01@kba.biglobe.ne.jp> (raw)
In-Reply-To: <150928164855.ZM29167@torch.brasslantern.com>
2015/09/29 08:48, Bart Schaefer <schaefer@brasslantern.com> 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 --
>
> 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 -<TAB>
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==1 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="$curcontext" hasopts rawret optarg singopt alwopt
local setnormarg start rest
local -a match mbegin mend
+subopts=()
+singopt=()
+while [[ "$1" = -([AMO]*|[CRSWnsw]) ]]; do
+ case "$1" in
+ -C) usecc=yes; shift ;;
+ -O) subopts=( "${(@P)2}" ); shift 2 ;;
+ -O*) subopts=( "${(@P)${1[3,-1]}}" ); shift ;;
+ -R) rawret=yes; shift;;
+ -n) setnormarg=yes; NORMARG=-1; shift;;
+ -w) optarg=yes; shift;;
+ -W) alwopt=arg; shift;;
+ -[Ss]) singopt+=( $1 ); shift;;
+ -[AM]) singopt+=( $1 $2 ); shift 2 ;;
+ -[AM]*) singopt+=( $1 ); shift ;;
+ esac
+done
+
+[[ $1 == ':' ]] && shift
+singopt+=( ':' ) # always end with ':' to indicate the end of options
+
+[[ "$PREFIX" = [-+] ]] && alwopt=arg
+
long=$argv[(I)--]
if (( long )); then
local name tmp tmpargv
- if [[ long -eq 1 ]]; then
- tmpargv=()
- else
- tmpargv=( "${(@)argv[1,long-1]}" )
- fi
+ tmpargv=( "${(@)argv[1,long-1]}" ) # optspec's before --, if any
name=${~words[1]}
[[ "$name" = [^/]*/* ]] && name="$PWD/$name"
@@ -290,23 +308,6 @@ if (( long )); then
set -- "$tmpargv[@]" "${(@P)name}"
fi
-subopts=()
-singopt=()
-while [[ "$1" = -(O*|[CRWnsw]) ]]; do
- case "$1" in
- -C) usecc=yes; shift ;;
- -O) subopts=( "${(@P)2}" ); shift 2 ;;
- -O*) subopts=( "${(@P)${1[3,-1]}}" ); shift ;;
- -R) rawret=yes; shift;;
- -n) setnormarg=yes; NORMARG=-1; shift;;
- -w) optarg=yes; shift;;
- -s) singopt=(-s); shift;;
- -W) alwopt=arg; shift;;
- esac
-done
-
-[[ "$PREFIX" = [-+] ]] && alwopt=arg
-
zstyle -s ":completion:${curcontext}:options" auto-description autod
if (( $# )) && comparguments -i "$autod" "$singopt[@]" "$@"; then
next prev parent reply other threads:[~2015-09-29 16:53 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-28 16:55 Jun T.
2015-09-28 23:48 ` Bart Schaefer
2015-09-29 16:12 ` Jun T. [this message]
2015-09-29 20:41 ` Bart Schaefer
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=3D6A6B84-A584-4915-BB8F-521AB490FA01@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).