zsh-workers
 help / color / mirror / code / Atom feed
* Re: Two missing completion functions that bug me
@ 2001-04-02  9:15 Sven Wischnowsky
  2001-04-02 12:04 ` Oliver Kiddle
  0 siblings, 1 reply; 3+ messages in thread
From: Sven Wischnowsky @ 2001-04-02  9:15 UTC (permalink / raw)
  To: zsh-workers


Oliver Kiddle wrote:

> --- Bart Schaefer <schaefer@candle.brasslantern.com> wrote:
> 
> > Yes, but when you're allowed to have other options intervene between
> > an
> > option and its argument (as in `tar -fxv file' for example) there has
> > to
> > be some way to prevent completion from inserting the space after
> > `-f'.
> 
> I accept this but would argue that there are more commands which don't
> allow other options to intervene. Things like tar can be achieved with
> with states. Maybe _arguments needs some way to describe whether or not
> options can intervene between an option and its argument.

Yes, I was beginning to think the same.  Would it be enough to make my 
other patch optional (i.e. adding a option to _arguments to select
either that behaviour or to de-select it)?  Which should be the
default?

> Things get
> messy if more than one of the options take an argument.

If I understand you correctly... I said in one of my previous messages 
that _arguments can do that.  Do we have to disallow it?  I'd prefer
it if we could keep it, mostly because I don't see a reason to make it 
optional -- either it's the intended reason or the specs given to
_arguments or the command line are messed up (only in the last case
there may be a reason to make _arguments smart enough to detect it and 
notify the user).

Bye
 Sven


--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Two missing completion functions that bug me
  2001-04-02  9:15 Two missing completion functions that bug me Sven Wischnowsky
@ 2001-04-02 12:04 ` Oliver Kiddle
  2001-04-04 11:25   ` PATCH: " Sven Wischnowsky
  0 siblings, 1 reply; 3+ messages in thread
From: Oliver Kiddle @ 2001-04-02 12:04 UTC (permalink / raw)
  To: zsh-workers

Sven Wischnowsky wrote: 

> > with states. Maybe _arguments needs some way to describe whether or
> not
> > options can intervene between an option and its argument.
> 
> Yes, I was beginning to think the same.  Would it be enough to make
> my 
> other patch optional (i.e. adding a option to _arguments to select
> either that behaviour or to de-select it)?  Which should be the
> default?

That sounds reasonable. I think the current behaviour (without your
other patch) should be the default because I think it is more common
but I'm not particularly bothered.

> If I understand you correctly... I said in one of my previous
> messages 
> that _arguments can do that.  Do we have to disallow it?  I'd prefer

Having just worked out how _arguments currently handles the situation,
I'd happy for it to be kept it as it is. It works in the most sensible
way which is possibly useful for some commands and not too harmful for
others.

Oliver

____________________________________________________________
Do You Yahoo!?
Get your free @yahoo.co.uk address at http://mail.yahoo.co.uk
or your free @yahoo.ie address at http://mail.yahoo.ie


^ permalink raw reply	[flat|nested] 3+ messages in thread

* PATCH: Re: Two missing completion functions that bug me
  2001-04-02 12:04 ` Oliver Kiddle
@ 2001-04-04 11:25   ` Sven Wischnowsky
  0 siblings, 0 replies; 3+ messages in thread
From: Sven Wischnowsky @ 2001-04-04 11:25 UTC (permalink / raw)
  To: zsh-workers

Oliver Kiddle wrote:

> > Yes, I was beginning to think the same.  Would it be enough to make
> > my 
> > other patch optional (i.e. adding a option to _arguments to select
> > either that behaviour or to de-select it)?  Which should be the
> > default?
> 
> That sounds reasonable. I think the current behaviour (without your
> other patch) should be the default because I think it is more common
> but I'm not particularly bothered.

Just what I thought... I've used `-W', couldn't think of a better character.


Bye
  Sven

Index: Completion/Base/Utility/_arguments
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/Utility/_arguments,v
retrieving revision 1.1
diff -u -r1.1 _arguments
--- Completion/Base/Utility/_arguments	2001/04/02 11:09:34	1.1
+++ Completion/Base/Utility/_arguments	2001/04/04 11:21:05
@@ -4,7 +4,7 @@
 # descriptions given as arguments to this function.
 
 local long cmd="$words[1]" descr mesg subopts opt usecc autod
-local oldcontext="$curcontext" hasopts rawret
+local oldcontext="$curcontext" hasopts rawret optarg singopt
 
 long=$argv[(I)--]
 if (( long )); then
@@ -173,18 +173,21 @@
 fi
 
 subopts=()
-while [[ "$1" = -(O*|[CR]) ]]; do
+singopt=()
+while [[ "$1" = -(O*|[CRWs]) ]]; 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;;
+  -W)  optarg=yes; shift;;
+  -s)  singopt=(-s); shift;;
   esac
 done
 
 zstyle -s ":completion:${curcontext}:options" auto-description autod
 
-if (( $# )) && comparguments -i "$autod" "$@"; then
+if (( $# )) && comparguments -i "$autod" "$singopt[@]" "$@"; then
   local action noargs aret expl local tried
   local next direct odirect equal single matcher matched ws tmp1 tmp2 tmp3
   local opts subc tc prefix suffix descrs actions subcs anum
@@ -335,14 +338,19 @@
           if [[ "$single" = direct ]]; then
             _all_labels options expl option \
 	        compadd -QS '' - "${PREFIX}${SUFFIX}"
-          elif [[ "$single" = next ]]; then
+          elif [[ -z "$optarg" && "$single" = next ]]; then
             _all_labels options expl option \
 	        compadd -Q - "${PREFIX}${SUFFIX}"
           elif [[ "$single" = equal ]]; then
             _all_labels options expl option \
 	        compadd -QqS= - "${PREFIX}${SUFFIX}"
           else
+
 	    tmp1=( "$next[@]" "$direct[@]" "$odirect[@]" "$equal[@]" )
+
+            [[ "$single" = next ]] &&
+                tmp1=( "${(@)tmp1:#[-+]${PREFIX[-1]}((#e)|:*)}" )
+
 	    [[ "$PREFIX" != --* ]] && tmp1=( "${(@)tmp1:#--*}" )
 	    tmp3=( "${(M@)tmp1:#[-+]?[^:]*}" )
 	    tmp1=( "${(M@)tmp1:#[-+]?(|:*)}" )
@@ -351,6 +359,11 @@
             _describe -o option \
                       tmp1 tmp2 -Q -S '' -- \
 		      tmp3 -Q
+
+            [[ -n "$optarg" && "$single" = next && nm -eq $compstate[nmatches] ]] &&
+                _all_labels options expl option \
+	            compadd -Q - "${PREFIX}${SUFFIX}"
+
           fi
           single=yes
         else
Index: Completion/X/Utility/_x_arguments
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/X/Utility/_x_arguments,v
retrieving revision 1.1
diff -u -r1.1 _x_arguments
--- Completion/X/Utility/_x_arguments	2001/04/02 12:13:15	1.1
+++ Completion/X/Utility/_x_arguments	2001/04/04 11:21:05
@@ -17,7 +17,7 @@
 fi
 
 opts=()
-while [[ $1 = -(O*|[CR]) ]]; do
+while [[ $1 = -(O*|[CRWs]) ]]; do
   opts=($opts $1)
   [[ $1 = -R ]] && rawret=yes
   shift
Index: Completion/X/Utility/_xt_arguments
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/X/Utility/_xt_arguments,v
retrieving revision 1.1
diff -u -r1.1 _xt_arguments
--- Completion/X/Utility/_xt_arguments	2001/04/02 12:13:30	1.1
+++ Completion/X/Utility/_xt_arguments	2001/04/04 11:21:05
@@ -53,7 +53,7 @@
 fi
 
 opts=()
-while [[ $1 = -(O*|[CR]) ]]; do
+while [[ $1 = -(O*|[CRWs]) ]]; do
   opts=($opts $1)
   [[ $1 = -R ]] && rawret=yes
   shift
Index: Doc/Zsh/compsys.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v
retrieving revision 1.116
diff -u -r1.116 compsys.yo
--- Doc/Zsh/compsys.yo	2001/04/02 13:04:05	1.116
+++ Doc/Zsh/compsys.yo	2001/04/04 11:21:07
@@ -2930,6 +2930,13 @@
 one option name.  This allows the use of the `tt(-s)' option to describe
 single-letter options together with such long option names.
 
+The tt(-s) option may be combined with the option tt(-W) to say that more
+option characters are to be expected even after an option that takes an
+argument.  For example, if a command takes the options `tt(a)' and `tt(b)',
+where `tt(a)' takes an argument in the next word, tt(_arguments) would
+normally not complete the other option directly after `tt(-a)', but it would
+allow that if given the tt(-W) option.
+
 The forms of var(optspec) are:
 
 startitem()
@@ -3202,6 +3209,13 @@
   - '(uncompress)' \ 
     {-d,--decompress}'[decompress]')
 
+Note that using multiple sets will be slower than using only one set
+because the completion code has to parse the command line once for
+every set. So more than one set should only be used if the command
+syntax is too complicated. Note also that an option specification with
+rest-arguments (as in `tt(-foo:*:...)') often allows the use of
+multiple sets to be avoided.
+
 To simplify the specifications for commands with standard option
 parsing, the options tt(-S) and tt(-A) may be given.  With tt(-S), no
 option will be completed after a `tt(-)tt(-)' on the line and this
@@ -3212,13 +3226,6 @@
 completing options after the first normal argument, but ignoring all
 strings starting with a hyphen even if they are not described by one
 of the var(optspec)s, one would use: `tt(-A "-*")'.
-
-Note that using multiple sets will be slower than using only one set
-because the completion code has to parse the command line once for
-every set. So more than one set should only be used if the command
-syntax is too complicated. Note also that an option specification with
-rest-arguments (as in `tt(-foo:*:...)') often allows the use of
-multiple sets to be avoided.
 
 Another option supported is `tt(-O) var(name)'. The var(name) will be
 taken as the name of an array and its elements will be given to

-- 
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2001-04-04 11:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-04-02  9:15 Two missing completion functions that bug me Sven Wischnowsky
2001-04-02 12:04 ` Oliver Kiddle
2001-04-04 11:25   ` PATCH: " Sven Wischnowsky

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).