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

Re: widget special PREFIX variable and cursor position with complete_in_word



On 02/25/2014 03:07 PM, Jesper Nygårds wrote:
> Yuri, Oliver,
> 
> This thread has been very interesting, but also a bit hard to follow. Would
> any one of you care to share the final version of your solution, in a more
> concise form? The functionality seems very useful to me.

My current setup:

[zshrc]

fpath+=( $ZDOTDIR/.zfunc )
zmodload zsh/complist
compinit -u

zstyle ':completion:*' completer _show_ambiguity _complete

[$ZDOTDIR/.zfunc/_show_ambiguity]

#autoload

_show_ambiguity()
{
  (( $comppostfuncs[(I)_show_ambiguity_end] )) || comppostfuncs+=(
_show_ambiguity_end )
  return 1
}

_show_ambiguity_end()
{
  local
prefix=${${compstate[unambiguous]}[1,${compstate[unambiguous_cursor]}-1]}
  local unesc=' \''"'
  [ -n "$prefix" ] &&
ZLS_COLORS+=":=${prefix[1,-2]//?/(}${prefix[1,-2]//(#m)?/${${MATCH:q}//\\[$unesc]/$MATCH}|)}${${prefix[-1]:q}//\\[$unesc]/$prefix[-1]}(#b)(?|)*==4"
  ZLS_COLORS+=":=*=0"
}

_show_ambiguity "$@"

EOF

As an additional note, I finally decided not to highlight the first
character in a full list, as Oliver said it's mostly redundant (although
Emacs does it anyway).

The partial match seems to work fine, and with the fixed escaping it
matches all cases correctly.

I also use a final ":=*=0" color spec to disable any built-in coloring
rules when the ambiguity match fails (I like my completions to be
colorless).

To be honest, I often work with directories with large lists of files,
and showing the ambiguity like emacs started to do a while ago is a
godsend since I do not use menu completition.



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