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

PATCH: completion for zstyle



Here's some completion support for zstyle.  In the first argument it will
complete only :completion: or :zftp:; for the second all the standard styles;
for the third, it knows about most completable values for the various
styles (and knows whether they are specific to :completion:* or :zftp:*).
Goodness knows if I've used contexts and tags in a consistent fashion
within _zstyle itself.

It's possible that styles and tags will need moving out to _styles and,
say, _complete_tags, but it's not yet necessary.

It also adds some .distfiles stuff I missed before.

Index: Completion/Builtins/.distfiles
===================================================================
RCS file: /home/pws/CVSROOT/projects/zsh/Completion/Builtins/.distfiles,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 .distfiles
--- Completion/Builtins/.distfiles	1999/11/28 17:42:27	1.1.1.1
+++ Completion/Builtins/.distfiles	1999/12/23 17:32:43
@@ -4,5 +4,5 @@
     _compdef _disable _echotc _enable _fc _fg_jobs _functions _hash _kill
     _limits _nothing _pids _popd _sched _set _setopt _source _stat _trap
     _unhash _unsetopt _vars _vars_eq _wait _which _zftp _zle _zmodload
-    _signals
+    _signals _zstyle
 '
Index: Completion/Builtins/_zstyle
===================================================================
RCS file: _zstyle
diff -N _zstyle
--- /dev/null	Tue May  5 21:32:27 1998
+++ _zstyle	Thu Dec 23 17:28:31 1999
@@ -0,0 +1,177 @@
+#compdef zstyle
+
+local curcontext="$curcontext" state ostate line expl ctop
+local nm=$compstat[nmatches]
+
+typeset -A styles
+# Assoc array of styles; the values give the possible top-level
+# contexts (currently c for completion, z for zftp or cz for both),
+# followed by a colon, followed by a state to enter, empty if none.
+styles=(
+  accept-exact		 c:bool
+  arguments		 c:
+  auto-description	 c:
+  cache-path		 'c:_path_files -/'
+  completer		 c:completer
+  completions		 c:
+  condition		 c:
+  cursor		 c:bool
+  disable-stat		 c:bool
+  expand		 c:
+  format		 c:
+  glob			 c:
+  group-name		 c:
+  group-order		 c:tag
+  groups		 c:_groups
+  hidden		 c:bool
+  hosts			 c:_hosts
+  hosts-ports		 c:host-port
+  hosts-ports-users	 c:host-port-user
+  ignored-suffixes	 c:
+  insert-unambiguous	 c:bool
+  last-prompt		 c:bool
+  list			 c:listwhen
+  list-arguments	 c:
+  list-colors		 c:
+  list-packed		 c:bool
+  list-rows-first	 c:bool
+  local			 c:
+  max-errors		 c:
+  menu			 c:boolauto
+  numbers		 c:bool
+  original		 c:bool
+  path			 'c:_path_files -/'
+  ports			 c:_ports
+  prefix-hidden		 c:bool
+  prefix-needed		 c:bool
+  prompt		 c:
+  remove-all-dups	 c:bool
+  sort			 c:bool
+  tag-order		 c:tag
+  special-dirs		 c:sdirs
+  stop			 c:stop
+  substitute		 c:
+  users			 c:_users
+  users-hosts		 c:user-host
+  verbose		 c:bool
+  word			 c:bool
+
+  chpwd			 z:bool
+  progress		 z:progress
+  remote_glob		 z:bool
+  titlebar		 z:bool
+  update		 z:
+)
+
+local taglist
+taglist=(accounts all-files all-expansions arguments arrays
+association-keys bookmarks builtins characters colors commands corrections
+cursors cvs default descriptions devices directories directory-stack
+displays expansions extensions files fonts functions globbed-files groups
+history-words hosts indexes jobs keymaps keysyms local-directories
+libraries limits manuals maps messages modifiers modules my-accounts
+named-directories names nicknames options original other-accounts packages
+parameters path-directories paths pods ports prefixes processes ps regex
+sequences sessions signals strings tags targets types urls users values
+warnings widgets windows zsh-options)
+
+_arguments ':context:->contexts' ':style:->styles' '*:argument:->style-arg'
+
+while [[ -n $state ]]; do
+  ostate=$state
+  state=
+
+  case "$ostate" in
+    contexts)
+      if [[ $PREFIX != :*: ]]; then
+	_wanted contexts expl context &&
+	compadd -P : -S : "$expl[@]" completion zftp
+      fi
+      ;;
+
+    styles)
+      # Get the top-level context we're completing for, if any.
+      if [[ $words[2] = :(completion|zftp):* ]]; then
+	ctop=${words[2][2]}
+      else
+        ctop=cz
+      fi
+      _wanted styles expl style &&
+         compadd "$expl[@]" - ${(k)styles[(R)[^:]#[$ctop][^:]#:*]}
+      ;;
+      
+    style-arg)
+      state="${styles[$words[3]]#*:}"
+      ;;
+
+    bool) 
+      _wanted values expl boolean &&
+	compadd "$expl[@]" true false
+      ;;
+
+    boolauto) 
+      _wanted values expl boolean &&
+	compadd "$expl[@]" true false auto select
+      ;;
+
+    completer)
+      _wanted values expl completer &&
+	compadd "$expl[@]" _complete _approximate _correct _match \
+          _expand _list _menu _oldlist
+      ;;
+
+    host-port*)
+      if [[ $PREFIX != *:* ]]; then
+	_hosts -S :
+      elif [[ $ostate != *user || $PREFIX != *:*:* ]]; then
+	compset -P 1 '*:'
+	_ports
+      else
+	compset -P 2 '*:'
+        _users
+      fi
+      ;;
+
+    listwhen)
+      _wanted values expl 'when to list completions' &&
+	compadd "$expl[@]" always never sometimes
+      ;;
+
+    progress)
+      _wanted values expl 'progress meter style' &&
+        compadd "$expl[@]" none bar percent
+      ;;
+
+    sdirs)
+      _wanted values expl 'whether to complete . or ..' &&
+        compadd "$expl[@]" true false ..
+      ;;
+
+    stop)
+      _wanted values expl 'when to insert matches' &&
+	compadd "$expl[@]" true false verbose
+      ;;
+
+    tag)
+      _wanted tags expl tag && compadd "$expl[@]" - $taglist
+      ;;
+
+    user-host)
+      if [[ $PREFIX = *:* ]]; then
+	compset -P '*:'
+	_hosts
+      else
+	_users
+      fi
+      ;;
+
+    _*)
+      ${=ostate}
+      ;;
+
+    *)
+      ;;
+  esac
+done
+
+[[ $compstate[nmatches] != $nm ]]
Index: Test/.distfiles
===================================================================
RCS file: /home/pws/CVSROOT/projects/zsh/Test/.distfiles,v
retrieving revision 1.2
diff -u -r1.2 .distfiles
--- Test/.distfiles	1999/12/13 20:03:25	1.2
+++ Test/.distfiles	1999/12/23 17:34:29
@@ -1,5 +1,6 @@
 DISTFILES_SRC='
     .cvsignore .distfiles Makefile.in
     ztst.zsh
-    01grammar.ztst 02alias.ztst 03quoting.ztst 50cd.ztst
+    01grammar.ztst 02alias.ztst 03quoting.ztst 04redirect.ztst
+    05command.ztst 06arith.ztst 07cond.ztst 50cd.ztst
 '

-- 
Peter Stephenson <pws@xxxxxxxxxxxxxxxxxxxxxxxx>



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