zsh-workers
 help / color / mirror / code / Atom feed
* Re: PATCH: Re: Completion/User functions again
@ 1999-07-14 12:46 Sven Wischnowsky
  1999-07-14 13:12 ` Tanaka Akira
  1999-07-14 14:29 ` Completion/User functions again Oliver Kiddle
  0 siblings, 2 replies; 17+ messages in thread
From: Sven Wischnowsky @ 1999-07-14 12:46 UTC (permalink / raw)
  To: zsh-workers


Oliver Kiddle wrote:

> Andrej Borsenkow wrote:
> > 
> >  - _tar and _find are hopelessly GNUish. You cannot expect, that users will
> > study every function to find out if it is applicable to there system. They will
> > simply install it and wonder why it does not work. Of course, gzip, configure
> > etc are GNU as well - but they do not conflict with system standard commands.
> 
> This is why I suggested a while ago that things such as tar and find are
> moved to a 'Gnu' directory and other directories such as Aix, Irix etc
> can contain completions specific to
> those systems.

I've been thinking about this for a long time, too. The problems are
that we would have to fill those directories (so that they don't look
silly) and with such directories users would expect to need only to
copy the contents of one such directory (or link User to it), so they
would have to be (almost) complete. That's a lot of work and who'll do 
that, I wonder.

While we are at it: we still don't have completion functions for some
commands for which we have compctl examples, e.g. cvs and rpm. I don't 
use either of these often enough to be able to write good functions
for them -- any volunteers for that?

> The patch to _x_options also
> causes it to only complete options on words starting with a '-'. I
> prefer to complete options this way as it keeps the number of matches
> down.

I never expected _x_options to survive this long... ;-)

> Maybe we should put a note in one of the readmes to make it clear that
> the functions may not work on all systems, maybe detailing which might
> have issues. I find many of the functions enormously useful and it would
> be a pity for them not to be used.

Maybe, yes.

> One thing which I just noticed which I don't think is right:
> rlogin <tab>
> zsh: do you wish to see all 114 possibilities? n
> The no returns to 'rlogin ' on the command-line. now, if I press tab
> again, menu completion
> starts. I think it should ignore the original tab if the question was
> answered with no.

Hm. 1) It has always been like that (or should have been). 2) Dunno,
you can always use ^D, but I don't have a real opinion about this --
anyone else wanting to comment?


Maybe we should add some kind of programming style guide some day,
containing things like `make functions that can be used as helper
functions do something useful with their arguments if possible' and
`do not use compgen if you're only after the -k or -s options'
(compadd is faster and -- I think -- cleaner for this).

Bye
 Sven

diff -u -r oc/User/_hosts Completion/User/_hosts
--- oc/User/_hosts	Tue Jul 13 10:58:41 1999
+++ Completion/User/_hosts	Wed Jul 14 14:32:29 1999
@@ -2,4 +2,4 @@
 
 : ${(A)hosts:=${(s: :)${(ps:\t:)${${(f)"$(</etc/hosts)"}%%\#*}##[:blank:]#[^[:blank:]]#}}}
 
-compgen -M 'm:{a-zA-Z}={A-Za-z} r:|.=* r:|=*' -k hosts
+compadd -M 'm:{a-zA-Z}={A-Za-z} r:|.=* r:|=*' "$@" - "$hosts[@]"
diff -u -r oc/User/_x_options Completion/User/_x_options
--- oc/User/_x_options	Wed Jul 14 14:33:41 1999
+++ Completion/User/_x_options	Wed Jul 14 14:42:29 1999
@@ -3,7 +3,8 @@
 # A simple pattern completion, just as an example.
 
 if [ "$words[CURRENT-1]" = "-display" ]; then
-  ISUFFIX=':0' _hosts
+  _compskip=''
+  _hosts -S :0
 else
   compadd -P- -J options - display name xrm
 fi

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


^ permalink raw reply	[flat|nested] 17+ messages in thread
* Re: CVS completer (Re: PATCH: Re: Completion/User functions again)
@ 1999-07-21 11:27 Sven Wischnowsky
  1999-07-21 12:35 ` Tanaka Akira
  1999-07-21 15:54 ` Bart Schaefer
  0 siblings, 2 replies; 17+ messages in thread
From: Sven Wischnowsky @ 1999-07-21 11:27 UTC (permalink / raw)
  To: zsh-workers


Bart Schaefer wrote:

> Below is an improved version of Tanaka's _cvs completer.

Below is this in slightly modified form as a patch (I guess Peter
already put it into files). Note, however, that I put `_complete_opts' 
into Base -- seems reasonable to put it in the directory where
_long_options is, doesn't it?

I mainly changed `compgen -f' to `_files' and `compgen -/' to `_files -/'
and tweaked `_complete_opts' a bit so that `cvs ann -D<TAB>' doesn't
give you `cvs ann -D-'.

Some questions:
- (Bart already marked this) what should the compgen -k '()' do?
- And even with that in place: the `_complete_opts || _files' should
  be reduced to `_files', right? (Unless the `compgen' really should
  add something -- so I've not changed that, yet.)


Bye
 Sven

diff -u -r oc/Base/_complete_opts Completion/Base/_complete_opts
--- oc/Base/_complete_opts	Wed Jul 21 13:14:54 1999
+++ Completion/Base/_complete_opts	Wed Jul 21 13:15:40 1999
@@ -0,0 +1,88 @@
+#autoload
+
+# Usage:
+#  _complete_opts H '' f '_files'
+
+emulate -L zsh
+setopt extendedglob
+
+local done=yes
+
+typeset -A option_pairs
+option_pairs=("$@")
+typeset -a no_arg with_arg opt_arg
+no_arg=($option_pairs[(I)?])
+opt_arg=($option_pairs[(I)?::]:s/:://)
+with_arg=($option_pairs[(I)?:]:s/:// $opt_arg)
+
+case "${#no_arg}-${#with_arg}" in
+  0-0)
+    if [[ x$PREFIX = x-* ]]; then
+      compgen -k '()'			# What does this accomplish?
+    else
+      done=''
+    fi
+    ;;
+
+  0-*)
+    if [[ x$PREFIX = x- ]]; then
+      IPREFIX="$IPREFIX$PREFIX"
+      PREFIX=
+      compadd $with_arg
+    elif [[ x$PREFIX = x-[${(j::)with_arg}] ]]; then
+      IPREFIX="$IPREFIX$PREFIX"
+      PREFIX=
+      eval $option_pairs[$IPREFIX[-1]:]
+    elif [[ x$PREFIX = x-[${(j::)with_arg}]* ]]; then
+      local p="$PREFIX[1,(r)[${(j::)with_arg}]]"
+      IPREFIX="$IPREFIX$p"
+      PREFIX="$PREFIX[$#p + 1,-1]"
+      eval $option_pairs[$IPREFIX[-1]:]
+    elif [[ x$words[$CURRENT-1] = x-[${(j::)with_arg}] ]]; then
+      local p="$words[$CURRENT - 1]"
+      eval $option_pairs[$p[-1]:]
+    else
+      done=''
+    fi
+    ;;
+
+  *-0)
+    if [[ x$PREFIX = x-[${(j::)no_arg}]# ]]; then
+      IPREFIX="$IPREFIX$PREFIX"
+      PREFIX=
+      compadd $no_arg
+    else
+      done=''
+    fi
+    ;;
+
+  *-*)
+    if [[ x$PREFIX = x-[${(j::)no_arg}]# ]]; then
+      IPREFIX="$IPREFIX$PREFIX"
+      PREFIX=
+      compadd $no_arg
+      compadd $with_arg
+    elif [[ x$PREFIX = x-[${(j::)no_arg}]#[${(j::)with_arg}] ]]; then
+      IPREFIX="$IPREFIX$PREFIX"
+      PREFIX=
+      eval $option_pairs[$IPREFIX[-1]:]
+    elif [[ x$PREFIX = x-[${(j::)no_arg}]#[${(j::)with_arg}]* ]]; then
+      local p="$PREFIX[1,(r)[${(j::)with_arg}]]"
+      IPREFIX="$IPREFIX$p"
+      PREFIX="$PREFIX[$#p + 1,-1]"
+      eval $option_pairs[$IPREFIX[-1]:]
+    elif [[ x$words[$CURRENT-1] = x-[${(j::)no_arg}]#[${(j::)with_arg}] ]]; then
+      local p="$words[$CURRENT - 1]"
+      eval $option_pairs[$p[-1]:]
+    else
+      done=''
+    fi
+    ;;
+esac
+
+if [[ -z "$done" ]]; then
+  compadd - -${(k)^option_pairs:gs/://}
+  false
+else
+  true
+fi
diff -u -r oc/User/_cvs Completion/User/_cvs
--- oc/User/_cvs	Wed Jul 21 13:14:47 1999
+++ Completion/User/_cvs	Wed Jul 21 13:14:33 1999
@@ -0,0 +1,134 @@
+#compdef cvs
+
+typeset -A commands
+commands=(add "ad new"            admin "adm rcs"         annotate ann
+          checkout "co get"       commit "ci com"         diff "di dif"
+          edit ""                 editors ""              export "exp ex"
+          history "hi his"        import "im imp"         init ""
+          log "lo rlog"           login "logon lgn"       logout ""
+          rdiff patch             release "re rel"        remove "rm delete"
+          status "st stat"        rtag "rt rfreeze"       tag "ta freeze"
+          unedit ""               update "up upd"         watch ""
+          watchers "")
+
+local com="${words[(i)(${(j:|:)${(kv)=commands}})]}"
+
+local showlist='compstate[list]=list; compstate[force_list]=yes'
+local showhint="$showlist ; compstate[insert]=''"
+local complete_D="compadd yesterday week\\ ago month\\ ago"
+local complete_k="compadd kv kvl k o b v"
+local complete_r="compadd -UX 'Enter tag name or rev number' ''; $showhint"
+local complete_m="compadd -UX 'Enter log message' -n ''; $showhint"
+
+
+if (( com < CURRENT )); then
+  case "$words[$com]" in
+    add|ad|new) # "+k:m:"
+      _complete_opts k: "$complete_k" m: "$complete_m" || _files
+      ;;
+    admin|adm|rcs) # "+ib::c:a:A:e:l::u::LUn:N:m:o:s:t::IqxV:k:"
+      _complete_opts i '' b:: '' c: '' a: '' A: '' e: '' l:: '' u:: '' L '' U '' n: '' N: '' m: "$complete_m" o: '' s: '' t:: '' I '' q '' x '' V: '' k: "$complete_k" || _files
+      ;;
+    annotate|ann) # "+lr:D:fR"
+      _complete_opts l '' r: '' D: '' f '' R '' || _files
+      ;;
+    checkout|co|get) # "+ANnk:d:flRpQqcsr:D:j:P"
+      _complete_opts A '' N '' n '' k: "$complete_k" d: '' f '' l '' R '' p '' Q '' q '' c '' s '' r: "$complete_r" D: "$complete_D" j: '' P '' || compadd MODULE
+      ;;
+    commit|ci|com) # "+nlRm:fF:r:"
+      _complete_opts n '' l '' R '' m: "$complete_m" f '' F: '' r: "$complete_r" || _files
+      ;;
+    diff|di|dif) # "+abcdefhilnpstuw0123456789BHNRC:D:F:I:L:U:V:W:k:r:"
+      _complete_opts a '' b '' c '' d '' e '' f '' h '' i '' l '' n '' p '' s '' t '' u '' w '' 0 '' 1 '' 2 '' 3 '' 4 '' 5 '' 6 '' 7 '' 8 '' 9 '' B '' H '' N '' R '' C: '' D: "$complete_D" F: '' I: '' L: '' U: '' V: '' W: '' k: "$complete_k" r: "$complete_r" || _files
+      ;;
+    edit) # "+lRa:"
+      _complete_opts l '' R '' a: '' || _files
+      ;;
+    editors) # "+lR"
+      _complete_opts l '' R '' || _files
+      ;;
+    export|exp|ex) # "+ANnk:d:flRpQqcsr:D:j:P"
+      _complete_opts A '' N '' n '' k: "$complete_k" d: '' f '' l '' R '' p '' Q '' q '' c '' s '' r: "$complete_r" D: "$complete_D" j: '' P '' || compadd MODULE
+      ;;
+    history|hi|his) # "+Tacelow?D:b:f:m:n:p:r:t:u:x:X:z:"
+      _complete_opts T '' a '' c '' e '' l '' o '' w '' \? '' D: "$complete_D" b: '' f: '' m: "$complete_m" n: '' p: '' r: '' t: '' u: '' x: '' X: '' z: '' || _files
+      ;;
+    import|im|imp) # "+Qqdb:m:I:k:W:"
+      _complete_opts Q '' q '' d '' b: '' m: "$complete_m" I: '' k: "$complete_k" W: '' || case $[CURRENT-com] in
+	1) compgen -X "Enter repository name" -W $CVSROOT -g '*~*CVSROOT(/)' -s '';;
+	2) compadd -UX "Enter vendor tag name" -n '' && eval "$showhint";;
+	3) compadd -UX "Enter release tag name" -n '' && eval "$showhint";;
+	*) compadd -UX "No futher arguments used" -n '' && eval "$showhint";;
+	esac
+      ;;
+    init)
+      break
+      ;;
+    login|logon|lgn|logout)
+      _complete_opts || _files
+      ;;
+    rdiff|patch|pa) # "+V:k:cuftsQqlRD:r:"
+      _complete_opts V: '' k: "$complete_k" c '' u '' f '' t '' s '' Q '' q '' l '' R '' D: "$complete_D" r: "$complete_r" || _files
+      ;;
+    release|re|rel) # "+Qdq"
+      _complete_opts Q '' d '' q '' || _files -/
+      ;;
+    remove|rm|delete) # "+flR"
+      _complete_opts f '' l '' R '' || _files
+      ;;
+    status|st|stat) # "+vlR"
+      _complete_opts v '' l '' R '' || _files
+      ;;
+    tag|ta|freeze) # "+FQqlRcdr:D:bf"
+      _complete_opts F '' Q '' q '' l '' R '' c '' d '' r: "$complete_r" D: "$complete_D" b '' f '' || _files
+      ;;
+    unedit) # "+lR"
+      _complete_opts l '' R '' || _files
+      ;;
+    update|up|upd) # "+ApPflRQqduk:r:D:j:I:W:"
+      _complete_opts A '' p '' P '' f '' l '' R '' Q '' q '' d '' u '' k: "$complete_k" r: "$complete_r" D: "$complete_D" j: '' I: '' W: '' || _files
+      ;;
+    watch)
+      if (( CURRENT == com + 1 )); then
+        compadd on off add remove
+      else
+        case "$words[com+1]" in
+          on|off) # "+lR"
+            _complete_opts l '' R '' || _files
+            ;;
+          add|remove) # "+lRa:"
+            _complete_opts l '' R '' a: '' || _files
+            ;;
+        esac
+      fi
+      ;;
+    watchers) # "+lR"
+      _complete_opts l '' R '' || _files
+      ;;
+    *) _files;;
+  esac
+  return
+fi
+
+case ${+cvs_roots} in
+  0)
+    cvs_roots=()
+    if [[ -f ~/.cvspass ]]; then
+      cvs_roots=(
+	$(cut -d ' ' -f 1 ~/.cvspass)
+      )
+    fi
+    ;;
+esac
+
+_complete_opts \
+  H '' Q '' q '' r '' w '' l '' n '' t '' v '' f '' a '' \
+  b: "compadd /usr/local/bin" \
+  T: "compadd $TMPPREFIX:h $TMPDIR /tmp" \
+  e: "compadd vi" \
+  d: "compadd $cvs_roots || _files -/" \
+  z: "compadd 9'" \
+  s: "_cvs_user_variable" \
+ || 
+compadd ${(k)commands} ||
+compadd ${(kv)=commands}

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


^ permalink raw reply	[flat|nested] 17+ messages in thread
* Re: CVS completer (Re: PATCH: Re: Completion/User functions again)
@ 1999-07-22  6:43 Sven Wischnowsky
  0 siblings, 0 replies; 17+ messages in thread
From: Sven Wischnowsky @ 1999-07-22  6:43 UTC (permalink / raw)
  To: zsh-workers


Tanaka Akira wrote:

> > I think it should be replaced by 'compadd "$PREFIX"'.
> 
> The patch is follows.

Just for completeness' sake...

Bye
 Sven

diff -u -r oc/Base/_complete_opts Completion/Base/_complete_opts
--- oc/Base/_complete_opts	Thu Jul 22 08:35:45 1999
+++ Completion/Base/_complete_opts	Thu Jul 22 08:41:05 1999
@@ -18,7 +18,7 @@
 case "${#no_arg}-${#with_arg}" in
   0-0)
     if [[ x$PREFIX = x-* ]]; then
-      compadd - "$PREFIX"
+      compadd -nQ - "$PREFIX$SUFFIX"
     else
       done=''
     fi

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


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

end of thread, other threads:[~1999-07-27  8:58 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-07-14 12:46 PATCH: Re: Completion/User functions again Sven Wischnowsky
1999-07-14 13:12 ` Tanaka Akira
1999-07-20 18:05   ` CVS completer (Re: PATCH: Re: Completion/User functions again) Bart Schaefer
1999-07-26  0:52     ` Tanaka Akira
1999-07-14 14:29 ` Completion/User functions again Oliver Kiddle
1999-07-21 11:27 CVS completer (Re: PATCH: Re: Completion/User functions again) Sven Wischnowsky
1999-07-21 12:35 ` Tanaka Akira
1999-07-21 15:43   ` Tanaka Akira
1999-07-21 15:54 ` Bart Schaefer
1999-07-25  9:23   ` Tanaka Akira
1999-07-25 11:38     ` Tanaka Akira
1999-07-26  4:48     ` Tanaka Akira
1999-07-26 16:26       ` Tanaka Akira
1999-07-26 17:10         ` Tanaka Akira
1999-07-27  8:15           ` Peter Stephenson
1999-07-27  8:58             ` Tanaka Akira
1999-07-22  6:43 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).