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

Re: Three questions about a completer

On Sep 13,  9:18pm, Jesper Nygards wrote:
} So now, at least, I get the completion to trigger. However, I still have
} the same problem: hitting alt-e for menu-complete works, and hitting alt-E
} for reverse-menu-complete works as well, but switching direction doesn't:

The doc for the _menu completer that Oliver mentioned, states:

     Note that this is independent of the setting of the
     MENU_COMPLETE option and does not work with the other menu
     completion widgets such as reverse-menu-complete, or

So that suggestion is out.

>> 2) The line starting with "[[ -n $words[CURRENT] ]] ..." is meant to make
>> sure that only files that match whats given on the command line (case
>> insensitively and anywhere within the file name) is offered as
>> alternatives.

You should not have to do this yourself; this is what the completion
internals are made to do.  You need to caculate ALL the possible files
that fit the rest of your criteria, and "compadd" will take care of
filtering that set down to the ones that match what's on the line.

If you don't want to match by simple prefix then you do have to tell
compadd how to filter.  You do this with the matching control format
that Oliver outlined.

To stop the listing, and only menu through the matches, you assign
empty string to compstate[list].

Finally you need Oliver's wrapper technique to interpret NUMERIC.
The nice thing about menu-complete / reverse-menu-complete is that
if a menu is already in progress, it won't re-invoke the completer,
so if you start from the wrapper widget in the forward direction,
you can reverse without having to use the wrapper again.

So the whole thing looks something like:

    zle -C list-comp menu-complete _generic
    zle -C reve-list-comp reverse-menu-complete _generic

    n-list-comp() {
      local -a dirs=( $HOME /etc /bin )
      local __lsdir=${dirs[${NUMERIC:-1}]
      zle list-comp -w -n 1
    zle -N n-list-comp
    # Similarly for n-rev-list-comp to start in reverse with NUMERIC

    bindkey '\ee' n-list-comp
    bindkey '\eE' rev-list-comp    # or n-rev-list-comp if defined

    _list-result() {
      compadd -M 'l:|=* m:{[:lower:]}={[:upper:]}' -f ${__lsdir:-HOME}/*
    zstyle ':completion:*list-comp::::' completer _list-result

Strictly speaking you don't even need rev-list-comp, you could just
invoke reverse-menu-complete provided that you always first enter
the menu in the forward direction.

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