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

Completeinword and ambiguous completions



Consider the following situation:

zsh% setopt completeinword
zsh% setopt pro<TAB>
zsh% setopt prompt<TAB>
promptbang     promptcr       promptpercent  promptsubst    promptvars

Note that the prefix "prompt" is unambiguous.  Now consider what happens
if the cursor is over the "m" when TAB is hit in each of these cases:

zsh% setopt prompt
(feep, cursor stays on "m")
zsh% setopt promptvars
zsh% setopt promptvars
(cursor is one space past end of word)

What I'd like is, in the first of those cases, the cursor doesn't stay
on the "m" but rather moves to the end of the unambiguous prefix, so that
I can immediately start menu completion for the rest of the word.  The
following almost does it:

    complete-in-prefix () {
        local lbuf=$LBUFFER rbuf=$RBUFFER
        integer i=1 curs=$CURSOR
        RBUFFER="" 
        zle expand-or-complete
        while ((curs < CURSOR)) && [[ $rbuf[i] == $LBUFFER[++curs] ]]
        do
             ((++i))
        done
        if ((curs == CURSOR)) || [[ -z $rbuf[i] || $rbuf[i] == [$' \t'] ]]
        then
            RBUFFER=$rbuf[i,-1]
        else
            LBUFFER=$lbuf 
            RBUFFER=$rbuf 
            return 1
        fi
    }
    zle -N complete-in-prefix
    bindkey '\t' complete-in-prefix

But it advances the cursor even when there is no overlap at all among rbuf
and any of the ambiguous suffixes, which is not what I want; it does the
wrong thing when the remainder of rbuf could disambiguate the completion
more; and of course I'd like to integrate it into the completion system
rather than run it as a wrapper.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



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