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

PATCH: selective parameter completion



I've implemented the change to _parameters which I mentioned yesterday
and modified a few other completion functions to make use of it. In the
process, it has raised a few questions:

In _arrays, _wanted is used but _parameters also calls _wanted so the
description of what is to be completed - 'array' - is replaced by
'parameter'. _files manages to avoid this problem so how is it done and
what should _parameters be doing here?

How does the implementation of _math differ from if compset -P and
compset -S were used to move the patterns from PREFIX to IPREFIX and
SUFFIX to ISUFFIX? It would be nice if spaces were treated more
cleanly, for example:
: $(( <tab>
doesn't complete parameters but quotes the space.

I have made _vars complete arrays and associations separately so that a
'[' suffix can be added automatically. The trouble here is that it has
to be quoted unless the glob option is not set otherwise a message
about no matches being found will be printed when the command is run.
Is it worth checking the state of the glob option before quoting this
suffix. If so, should _precommand be doing a 'setopt localoptions
noglob' when the noglob command is being completed to ensure the option
is set during the completion of the command after it?

Also, it would make sense to use _vars instead of _parameters when
completing in command position but the square brackets aren't treated
as a pattern there so how can I detect that it is being used in command
postion: is [[ CURRENT = 1 ]] going to work?

As far as I can tell, the existing code in _vars for completing
association keys after an opening square-bracket is only useful when we
have quoting because _subscript will do the job otherwise. I would add
similar code for array indexes but it seems a bit pointless to be
repeating code that we already have in _subscript. Calling _subscript
doesn't seem to work so what would be a good way to avoid this
repetition?

Oliver

Index: Completion/Base/_math
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/_math,v
retrieving revision 1.2
diff -u -r1.2 _math
--- Completion/Base/_math	2000/05/09 17:16:08	1.2
+++ Completion/Base/_math	2000/08/10 21:01:00
@@ -9,4 +9,4 @@
   SUFFIX="${SUFFIX%%[^a-zA-Z0-9_]*}"
 fi
 
-_parameters
+_parameters -g '(integer|float)*'
Index: Completion/Builtins/_arrays
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Builtins/_arrays,v
retrieving revision 1.2
diff -u -r1.2 _arrays
--- Completion/Builtins/_arrays	2000/06/22 08:42:36	1.2
+++ Completion/Builtins/_arrays	2000/08/10 21:01:00
@@ -2,4 +2,4 @@
 
 local expl
 
-_wanted arrays expl array compadd -k "parameters[(R)*array*~*local*]"
+_wanted arrays expl array _parameters "$@" -g '*array*'
Index: Completion/Builtins/_vars
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Builtins/_vars,v
retrieving revision 1.4
diff -u -r1.4 _vars
--- Completion/Builtins/_vars	2000/08/09 21:20:41	1.4
+++ Completion/Builtins/_vars	2000/08/10 21:01:00
@@ -1,9 +1,10 @@
 #compdef getopts unset vared
 
 # This will handle completion of keys of associative arrays, e.g. at
-# `vared foo[<TAB>'.  However, in this version the [ must be added
-# by hand.
+# `vared foo[<TAB>'.
 
+local ret=1
+
 if [[ $PREFIX = *\[* ]]; then
   local var=${PREFIX%%\[*}
   local elt="${PREFIX#*\]}${SUFFIX%\]}"
@@ -11,7 +12,7 @@
 
   compset -p $(( ${#var} + 1 ))
   if ! compset -S \]; then
-    addclose=(-S ']')
+    addclose=(-S "${${QIPREFIX:+]}:-\]}")
   fi
   if [[ ${(tP)var} = assoc* ]]; then
     local expl
@@ -20,5 +21,13 @@
         compadd $addclose -k "$var"
   fi
 else
-  _parameters "$@"
+  _parameters -g '^a*' "$@" && ret=0
+  
+  if compset -S '\[*'; then
+    set - -S "" "$@"
+  else
+    set - -qS"${${QIPREFIX:+[}:-\[}" "$@"
+  fi
+  _parameters -g 'a*' "$@" && ret=0
+  return ret
 fi
Index: Completion/Builtins/_zpty
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Builtins/_zpty,v
retrieving revision 1.8
diff -u -r1.8 _zpty
--- Completion/Builtins/_zpty	2000/05/31 09:38:26	1.8
+++ Completion/Builtins/_zpty	2000/08/10 21:01:00
@@ -10,7 +10,7 @@
   '(-r -w -L -e -b)-d[delete command]:*:name:->name' \
   '(-r -L -e -b -d)-w[send string to command]:name:->name:*:strings to write' \
   '(: -r -w -e -b -d)-L[list defined commands as calls]' \
-  '(: -w -L -e -b -d)-r[read string from command]:name:->name:param: _parameters:pattern:' \
+  '(: -w -L -e -b -d)-r[read string from command]:name:->name:param: _vars:pattern:' \
   '(-r -w -L -d):zpty command name:' \
   '(-r -w -L -d):cmd: _command_names -e' \
   '(-r -w -L -d)*::args:_precommand' && return 0
@@ -21,7 +21,7 @@
 #   - read \
 #     '-r[read string from command]' \
 #     ':name:->name' \
-#     ':param: _parameters' \
+#     ':param: _vars' \
 #     ':pattern:' \
 #   - write \
 #     '-w[send string to command]' \
Index: Completion/Commands/_bash_completions
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Commands/_bash_completions,v
retrieving revision 1.5
diff -u -r1.5 _bash_completions
--- Completion/Commands/_bash_completions	2000/08/03 13:35:43	1.5
+++ Completion/Commands/_bash_completions	2000/08/10 21:01:00
@@ -34,7 +34,7 @@
   '!') _main_complete _command_names
        ;;
   '$') _main_complete - parameters _wanted parameters expl 'exported parameters' \
-                                       compadd -k 'parameters[(R)*export*]'
+                                       _parameters -g '*export*'
        ;;
   '@') _main_complete _hosts
        ;;
Index: Completion/Core/_parameters
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Core/_parameters,v
retrieving revision 1.2
diff -u -r1.2 _parameters
--- Completion/Core/_parameters	2000/06/22 08:42:36	1.2
+++ Completion/Core/_parameters	2000/08/10 21:01:00
@@ -3,6 +3,13 @@
 # This should be used to complete parameter names if you need some of the
 # extra options of compadd. It completes only non-local parameters.
 
-local expl
+# If you specify a -g option with a pattern, the pattern will be used to
+# restrict the type of parameters matched.
 
-_wanted parameters expl parameter compadd "$@" -k 'parameters[(R)^*local*]'
+local expl pattern
+
+pattern=(-g \*)
+zparseopts -D -K -E g:=pattern
+
+_wanted parameters expl parameter compadd "$@" \
+    -k "parameters[(R)${pattern[2]}~*local*]"
Index: Doc/Zsh/compsys.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v
retrieving revision 1.90
diff -u -r1.90 compsys.yo
--- Doc/Zsh/compsys.yo	2000/08/02 13:45:52	1.90
+++ Doc/Zsh/compsys.yo	2000/08/10 21:01:27
@@ -3470,8 +3470,12 @@
 )
 findex(_parameters)
 item(tt(_parameters))(
-This should be used to complete parameter names.  All arguments are
-passed unchanged to the tt(compadd) builtin.
+This should be used to complete parameter names.  tt(_parameters) can
+take a tt(-g var(pattern)) option which specifies that only parameters
+whose type matches the var(pattern) should be completed.  Strings of
+the same form as those returned by the tt(t) parameter expansion flag
+are used here when matching the type.  All other arguments are passed
+unchanged to the tt(compadd) builtin.
 )
 findex(_path_files)
 item(tt(_path_files))(



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