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

_subscript



This is the current version (or, as I keep typing, versino, which doesn't
mean anything in Italian either) of _subscript after applying Oliver's
changes by hands, plus I've also added a `-V default' to the compadd's which
keeps them from reordering the numbers.  Otherwise menucompletion takes you
through 1, 10, 11, 12, 2, etc.

Hmm... I wonder if it would be possible to arrange for `print' formatting
of parameter output in a general way by having a flag which allowed you to
pass a whole set of arguments to print, like ${(x.-D.)foo}, where x is some
flag that hasn't been used.  Then the final result of expansion at that
level would be effectively filtered through print -D (print would probably
need some significant rewriting), and it would be easy to handle arrays so
you could get output in columns by ${(x.-c.)foo}.  Or maybe there's a
better way.

#compdef -subscript-

if [[ ${(Pt)${compstate[parameter]}} = assoc* ]]; then
  if [[ "$RBUFFER" = \]* ]]; then
    compadd -S '' - "${(@kP)${compstate[parameter]}}"
  else
    compadd -S ']' - "${(@kP)${compstate[parameter]}}"
  fi
elif [[ ${(Pt)${compstate[parameter]}} = array* ]]; then
  local list i j

  ind=( {1..${#${(P)${compstate[parameter]}}}} )
  list=()
  for i in "$ind[@]"; do
    [[ "$i" = ${PREFIX}*${SUFFIX} ]] &&
        list=( "$list[@]" 
	  "${(r:4:: ::):)i} $(print -D ${(P)${compstate[parameter]}[$i]})" )
  done

  if [[ "$RBUFFER" = \]* ]]; then
    compadd -S '' -V default -y list - "$ind[@]"
  else
    compadd -S ']' -V default -y list - "$ind[@]"
  fi
else
  _compalso -math-
fi

-- 
Peter Stephenson <pws@xxxxxxxxxxxxxxxxx>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy



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