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

Re: Three questions about a completer



Thank you for all your help, Bart and Oliver!

I am getting closer: the problem with numeric is now solved with your
suggestions, as well as turning off the listing of alternatives. However I
still have trouble reversing the menu completion direction.

I'll explain what it is I want. I believe you've already understood, but
just to make sure: say that I have files A, B and C in my home directory. I
type "print <alt-e>", and "A" is put on the line. I then hit "<alt-e>"
again, and the "A" is replaced by "B".

If I start over and type "print <alt-E>", "C" is put on the line. Another
"<alt-E>" gives me "B". So the two keybindings work independently:
"<alt-e>" gives the list from the beginning, "<alt-E>" from the end.

However, this is what is NOT working: I type "print <alt-e>", and get "A".
I hit "<alt-e>" again, and get "B". Now, I hit "<alt-E>" to go back in the
list. I expected to get "A" again, but instead "B" remains on the line.
It's as though the only thing matching is what's right now on the line.

Below is the entirety of my ~/.zshrc when I experiment with this. It's
Bart's solution with n-rev-list-comp added (and the compinit activation).

autoload -U compinit
compinit

zle -C list-comp menu-complete _generic
zle -C rev-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
}

n-rev-list-comp() {
    local -a dirs=( $HOME /etc /bin )
    local __lsdir=${dirs[${NUMERIC:-1}]}
    zle rev-list-comp -w -n 1
}

zle -N n-list-comp
zle -N n-rev-list-comp

bindkey '\ee' n-list-comp
bindkey '\eE' n-rev-list-comp

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

zstyle ':completion:*list-comp::::' completer _list-result


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