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

PATCH: _yp (was: completion for perldoc)



Adam Spiers wrote:

> Sven Wischnowsky (wischnow@xxxxxxxxxxxxxxxxxxxxxxx) wrote:
> > Adam Spiers wrote:
> > > - Why can't you have multiple MESSAGE:ACTION pairs with the
> > >   *:MESSAGE:ACTION form?  I'm having to resort to using an auxiliary
> > >   function, e.g.:
> > 
> > There three forms that allow you to specify completion for
> > (non-option-) arguments:
> 
> [snip]
> 
> Sorry, badly phrased question.  I understood the three forms;
> my question was, why can't the third form:
> 
> >    `*:mesg:action'
> >      specify completion for `all other' arguments
> 
> look like this:
> 
>      `*:mesg1:action1:mesg2:action2:...'
> 
> ?

Ah, you want to have *all* actions be executed for all `rest'
arguments? You could use the `{...}' form for actions, but I think
this is better split into a separate function or using the state stuff 
I keep promoting -- to increase readability.

> ... [ about a way to say that if a certain option is present, no
>       normal arguments should be completed ]

I have to apologize here. I just tried to build a `_yp' function and
of course immediatly found a place where this might be useful to
have.

So, the patch below allows a colon as one element of the exclusion
lists to say that if that option is given, no normal arguments should
be completed. E.g. the spec `(: -b)-a:...' says that if `-a' is given, 
neither `-b' nor normal arguments should be completed.

>     `(-f)-q:FAQ keyword::*:'
> 
> gets confused by the empty ACTION.  I tried
> 
>     `(-f)-q:FAQ keyword:():*:'
> 
> but then it doesn't print `FAQ keyword'.

A single space as the `action' should be used for that. The patch
documents this, too.

Bye
 Sven

diff -u -r oldcompletion/Base/_arguments Completion/Base/_arguments
--- oldcompletion/Base/_arguments	Mon Sep  6 13:08:50 1999
+++ Completion/Base/_arguments	Tue Sep  7 11:48:46 1999
@@ -417,6 +417,10 @@
       argbeg="$beg"
       inopt=yes
       if [[ -n "$xors[$ws[1]]" ]]; then
+	if [[ "$xors[$ws[1]]" = (*\ |):(\ *|) ]]; then
+          args=()
+	  rest=''
+        fi
         odescr=( "${(@)odescr:#(${(j:|:)~${=xors[$ws[1]]}}):*}" )
         unset {{,d,od}opts,xors}\[${^=xors[$ws[1]]}\]
       fi
@@ -475,6 +479,10 @@
 	  argbeg="$beg"
 	  inopt=yes
 	  if [[ -n "$xors[$tmp[1]]" ]]; then
+	    if [[ "$xors[$ws[1]]" = (*\ |):(\ *|) ]]; then
+              args=()
+	      rest=''
+            fi
             odescr=( "${(@)odescr:#(${(j:|:)~${=xors[$tmp[1]]}}):*}" )
             unset {{,d,od}opts,xors}\[${^=xors[$tmp[1]]}\]
           fi
@@ -521,6 +529,10 @@
 	  argbeg="$beg"
 	  inopt=yes
 	  if [[ -n "$xors[$tmp[1]]" ]]; then
+	    if [[ "$xors[$ws[1]]" = (*\ |):(\ *|) ]]; then
+              args=()
+	      rest=''
+            fi
             odescr=( "${(@)odescr:#(${(j:|:)~${=xors[$tmp[1]]}}):*}" )
             unset {{,d,od}opts,xors}\[${^=xors[$tmp[1]]}\]
           fi
--- oldcompletion/User/_yp	Tue Sep  7 11:59:30 1999
+++ Completion/User/_yp	Tue Sep  7 12:53:52 1999
@@ -0,0 +1,105 @@
+#compdef ypcat ypmatch yppasswd ypwhich ypset ypserv ypbind yppush yppoll ypxfr domainname
+
+local line state ret=1
+typeset -A options
+
+if (( ! $+_yp_cache_maps )); then
+  _yp_cache_maps=( "${(@)${(@f)$(ypwhich -m)}%% *}" )
+  _yp_cache_nicks=( "${(@)${(@)${(@f)$(ypwhich -x)}#*\"}%%\"*}" )
+  _yp_args=(
+    '(-x)-d[specify domain]:domain name:' \
+    '(-x)-k[display keys]' \
+    '(-x)-t[inhibit nicknames]' \
+    '(: -d -k -t)-x[display nicknames]' \
+  )
+fi
+
+case "$words[1]" in
+ypcat)
+  _arguments -s "$_yp_args[@]" ':map name:->map' && ret=0
+  ;;
+ypmatch)
+  _arguments -s "$_yp_args[@]" '*::key map:->keymap' && ret=0
+  ;;
+yppasswd)
+  _users
+  return
+  ;;
+ypwhich)
+  _arguments \
+    '(-x)-d[specify domain]:domain name:' \
+    '(-x -V2 -m -t)-V1[identify version 1 servers]' \
+    '(-x -V1 -m -t)-V2[identify version 2 servers]' \
+    '(: -x -V1 -V2 -m)-t[specify map name]:map name:->maponly' \
+    '(: -x -V1 -V2 -t)-m[specify map or nick name]:map or nick name:->map' \
+    '(: -d -m -t -V1 -V2)-x[display nicknames]' \
+    ':host:_hosts' && ret=0
+  ;;
+ypset)
+  _arguments \
+    '(-V2)-V1[bind version 1 servers]' \
+    '(-V1)-V2[bind version 2 servers]' \
+    '-d[specify domain]:domain name:' \
+    '-h[specify host]:set binding on host:_hosts' \
+    ':server:_hosts' && ret=0
+    ;;
+ypserv)
+  _arguments \
+    '-a[specify database routines]:database routines:((b\:btree d\:dbm/ndbm h\:hash))' && ret=0
+  ;;
+ypbind)
+  _arguments \
+    '-s[allow secure mode for ypbind]' \
+    '-S[set domain and servers]:domain:->servers' \
+    '(-ypsetme)-ypset[accept all ypset requests]' \
+    '(-ypset)-ypsetme[accept only local ypset requests]' && ret=0
+  ;;
+yppush)
+  _arguments \
+    '-d[specify domain]:domain name:' \
+    '-v[print messages]' \
+    ':map name:->map' && ret=0
+  ;;
+yppoll)
+  _arguments \
+    '-d[specify domain]:domain name:' \
+    '-h[specify host]:ask server on host:_hosts' \
+    ':map name:->map' && ret=0
+  ;;
+ypxfr)
+  _arguments \
+    '-a[specify database routines]:database routines:((b\:btree d\:dbm/ndbm h\:hash))' \
+    '-f[force transfer]' \
+    '-c[don'"'"'t clear current map]' \
+    '-d[specify domain]:domain name:' \
+    '-h[specify host]:get map from host:_hosts' \
+    '-C[call back]:transaction ID: :program number: :IP address: :port number:' \
+    ':map name:->map' && ret=0
+  ;;
+domainname)
+  _message 'new domain name'
+  return 1
+  ;;
+esac
+
+[[ "$state" = keymap ]] && _message 'key'
+
+if [[ "$state" = map* ]]; then
+  local expl
+
+  _description expl 'map name'
+  compadd "$expl[@]" - "$_yp_cache_maps[@]" && ret=0
+  if [[ $+options[-t] -eq 0 && "$state" != maponly ]]; then
+    _description expl 'nicknames'
+    compadd "$expl[@]" - "$_yp_cache_nicks[@]" && ret=0
+  fi
+elif [[ "$state" = servers ]]; then
+  if compset -P '*,'; then
+    _description expl 'server'
+    _hosts -qS, && ret=0
+  else
+    _message 'domain name'
+  fi
+fi
+
+return ret
--- od/Zsh/compsys.yo	Mon Sep  6 13:08:42 1999
+++ Doc/Zsh/compsys.yo	Tue Sep  7 13:09:18 1999
@@ -938,7 +938,9 @@
 in parentheses at the beginning, as in `tt((-two -three)-one:...)'. In 
 this example, the options `tt(-two)' and `tt(-three)' will not be
 offered as possible completions if the option `tt(-one)' is on the
-line.
+line. Also, the list may contain a single colon as one of its elements 
+to specify that the descriptions for normal (non-option-) arguments
+should not be used if the option described is on the line.
 
 Finally, the var(opt-spec) may contain a explanation string. This is
 given in brackets at the end, as in `tt(-q[query operation])'. The
@@ -959,7 +961,7 @@
 (which needs to be preceded by a backslash) and a description. The
 matches will be listed together with their descriptions.
 
-A var(action) of the form `tt(->)var(string)' is used by functions
+An var(action) of the form `tt(->)var(string)' is used by functions
 that implement a state machine. In this case, the `var(string)' (with
 all leading and trailing spaces and tabs removed) will be stored in
 the global parameter tt(state) and the function returns with a return
@@ -976,6 +978,10 @@
 first word which can be given as arguments to the tt(compadd) and
 tt(compgen) builtins and which make sure that the var(message) given
 in the description will be shown above the matches.
+
+In places where no sensible matches can be generated, the action
+should consist of only a space. This will make the var(message) be
+displayed but no possible completions listed.
 
 To include a colon in the var(message) or the var(action), it has to
 be preceded by a backslash.

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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