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

RE: zsh-3.1.5-pws-5: mixing "old" and "new" completions?



>
> I haven't got around to considering the new completion in detail, but
> it did occur to me it could be better integrated with the widget
> completion I added, i.e. zle -c and zle -C could be made more similar.


Actually, after looking at new completion examples, I really think, all
three current ways to do completion should be merged.

compctl is suitable and enough in probably 90% of all cases - and with
post-3.1.5 additions even more (am I wrong?) And if you are lucky to have
the case from remaining 10%, the cool new completion stuff is excellent tool
to extend compctl.

What I think about, is two interfaces: compctl->new completion and new
completion->compctl. That is

compctl->new completion

  we need a way to call completion functions with environment set up
  as expected by new functions. Unfortunately, it is incompatible with
  current -K usage (as we need setup different args); do we have any
  character else free? :-) O.K., let's assume for now that it is 'K'

new completion->compctl

  there is already complist, that can be used to specify completion
  directly. Now, what is needed, is the way to tell: "use completion,
  defined for this command by compctl, if available". It is much the way,
  zle -C works already. Let's call it compcall :-)

  The way, in which compctl is called, must use the same convention
  (arg list and variables) as new completion. This will provide for nice
  recursive calls.

Consider two examples:

compctl -T -K __redirect_handler
function __redirect_handler () {
    case $CONTEXT in
        redirect )
            do completion of redirections
        ;;
    esac
}

This gives easy way to enable completion after redirection without actually
messing up all traditional compctl stuff. Yes, for those who already use -T,
it means some additional work ... But it only one function in this case :-)

Another one is small rewrite of new completion example:

compctl -K __precmd noglob nocorrect exec command builtin
__precmd() {
  COMMAND="$1"
  shift
  (( CURRENT-- ))
  if [[ CURRENT -eq 0 ]] then
    CONTEXT=command
  else
    CONTEXT=argument
  fi
  compcall -c "$1" # -- this calls compctl completion, defined for "$1"
                   # -- now compctl "sees" only modified arguments,
                   # -- that will be passed to any functions called
}

I actually feel very uneasy about replacing compctl interface with new
stuff. But it is really a pity to not use it.

Is it hard to implement? This will give you full flexibility of all three
ways to do completion and free choice, which one to use.

/andrej



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