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

Re: PATCH: facilitate completion in "scalar arrays"



Clint Adams wrote:

> We're still lacking completion of options to typeset and friends; you get
> an = if you try to complete 'typeset -'.

For most builtins. Oliver has been working on some of them
lately. Thanks, Oliver!

> Maybe the : rule should only apply when the parameter is *scalar* or
> doesn't exist yet.

I saw the mail on the Debian Bug List on Friday and have been working
on this over the weekend, too.

It's a bit larger than your patch and I've now changed it to give the
same default behaviour your patch did:

It makes _value be used consistently for completing after a `=' and
there it checks the style `assign-list'. This may contain patterns and 
if the word before the `=' matches any of them, the value is completed 
colon-separated-list-wise. And _value is now also used for array
values (we didn't have a function for -array-value- before).

Using _value everywhere also means that one can supply functions of
the form `_value:<name>' to complete the value for parameter <name>.

Bye
 Sven

Index: Completion/Base/_default
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/_default,v
retrieving revision 1.3
diff -u -r1.3 _default
--- Completion/Base/_default	2000/04/11 07:57:56	1.3
+++ Completion/Base/_default	2000/04/17 08:16:07
@@ -12,10 +12,16 @@
   compcall "$opt[@]" || return 0
 fi
 
-_files && return 0
+_files "$@" && return 0
 
 # magicequalsubst allows arguments like <any-old-stuff>=~/foo to do
 # file name expansion after the =.  In that case, it's natural to
 # allow completion to handle file names after any equals sign.
 
-[[ -o magicequalsubst ]] && compset -P 1 '*=' && _files
+if [[ -o magicequalsubst && "$PREFIX" = *\=* ]]; then
+  compstate[parameter]="${words[1]:t}-${PREFIX%%\=*}"
+  compset -P 1 '*='
+  _value "$@"
+else
+  return 1
+fi
Index: Completion/Base/_value
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/_value,v
retrieving revision 1.1.1.2
diff -u -r1.1.1.2 _value
--- Completion/Base/_value	1999/11/02 14:07:19	1.1.1.2
+++ Completion/Base/_value	2000/04/17 08:16:07
@@ -1,11 +1,32 @@
-#compdef -value-
+#compdef -value- -array-value-
 
 _value () {
-  #_view_completion_parameters
+  # You can customize completion for different parameters by writing a
+  # function `_value:<name>'.
+
   if (( $+functions[_value:$compstate[parameter]] )); then
     "_value:$compstate[parameter]" "$@"
+  elif [[ "$compstate[parameter]" != *-* &&
+          "${(Pt)${compstate[parameter]}}" = assoc* ]]; then
+    if (( CURRENT & 1 )); then
+      _wanted association-keys expl 'association key' \
+          compadd - "${(@kP)${compstate[parameter]}}"
+    else
+      compstate[parameter]="${compstate[parameter]}-${words[CURRENT-1]}"
+      _value "$@"
+    fi
   else
-    _default
+    local pats
+
+    if { zstyle -a ":completion:${curcontext}:" assign-list pats &&
+         [[ "$compstate[parameter]" = (${(j:|:)~pats}) ]] } ||
+       [[ "$PREFIX$SUFFIX" = *:* ]]; then
+      compset -P '*:'
+      compset -S ':*'
+      _default -qS: "$@"
+    else
+      _default "$@"
+    fi
   fi
 }
 
@@ -24,6 +45,7 @@
     _files -/ "$@"
   elif compset -P '-R'; then
     compset -P '*:'
+    compset -S ':*'
     _files -/ -S/ -r ' :' "$@"
   else
     _default "$@"
Index: Completion/Builtins/_vars_eq
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Builtins/_vars_eq,v
retrieving revision 1.2
diff -u -r1.2 _vars_eq
--- Completion/Builtins/_vars_eq	2000/04/14 15:15:46	1.2
+++ Completion/Builtins/_vars_eq	2000/04/17 08:16:07
@@ -1,9 +1,9 @@
 #compdef declare export integer local readonly typeset
 
-if compset -P '*=*:'; then
-  _default
-elif compset -P '*='; then
-  _default
+if [[ "$PREFIX" = *\=* ]]; then
+  compstate[parameter]="${PREFIX%%\=*}"
+  compset -P 1 '*='
+  _value
 else
   _parameters -q -S '='
 fi
Index: Completion/Builtins/_zstyle
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Builtins/_zstyle,v
retrieving revision 1.5
diff -u -r1.5 _zstyle
--- Completion/Builtins/_zstyle	2000/04/11 07:57:56	1.5
+++ Completion/Builtins/_zstyle	2000/04/17 08:16:08
@@ -12,9 +12,10 @@
   accept-exact		 c:bool
   add-space		 c:bool
   ambiguous              c:bool
-  arguments		 c:
+  assign-list            c:
   auto-description	 c:
   break-keys             c:
+  command                c:command
   completer		 c:completer
   completions		 c:
   condition		 c:
@@ -38,7 +39,6 @@
   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
@@ -233,6 +233,12 @@
     single-ignored)
       _wanted values expl 'how to handle a single ignored match' \
           compadd - show menu
+      ;;
+
+    command)
+      shift 3 words
+      (( CURRENT -= 3 ))
+      _normal
       ;;
 
     _*)
Index: Doc/Zsh/compsys.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v
retrieving revision 1.17
diff -u -r1.17 compsys.yo
--- Doc/Zsh/compsys.yo	2000/04/13 11:05:16	1.17
+++ Doc/Zsh/compsys.yo	2000/04/17 08:16:09
@@ -771,6 +771,18 @@
 after the first ambiguous pathname component even when menucompletion
 is used.
 )
+kindex(assign-list, completion style)
+item(tt(assign-list))(
+When completing after an equal sign, the completion system normally
+completes only one filename.  But when completing the value for some
+parameters or after other strings separated by an equal sign from a
+value, a colon-separated list of filenames is needed. This style
+can be set to a list of patterns matching the names of parameters for
+which such a colon-separated list of filenames should be completed.
+
+The default is to complete lists when the word on the line already
+contains a colon.
+)
 kindex(auto-description, completion style)
 item(tt(auto-description))(
 If set, this style's value will be used as the description for options which

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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