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

Re: widget special PREFIX variable and cursor position with complete_in_word

Bart wrote:
> Indeed, I forgot how early in the process _setup gets called, and that
> is the only place the list-colors style is examined.

_setup is too early for PREFIX/IPREFIX to have meaningful values. For
file completion (or for a simpler example, anything using _multi_parts),
the description is set once, not for each directory component.

list-colors is just stuffing things in ZLS_COLORS so I think it is
better to bypass it and set ZLS_COLORS ourself. To really get the right
prefixes, you need some trick overriding compadd but I think it is
easier to try to do things in a comppostfunc as you suggested before.

The pattern in ZLS_COLORS is matched against the display string. With
matching control etc, this really may not correspond to the actual
matches all that closely. So this is never going to be perfect.

The completer I've put below, turns an unambiguous string such as ./te
into (((.|)/|)t|)e and matches as much of that as possible on the
beginning of the match display string. So with file completion and a
file named test, the 'te' would match that pattern, ./ is missing from
the display string and the s gets underlined. You can easily contrive
ways to break that but the result seems to work reasonably in my very
limited testing.

You could include the last character (e in the example above) in the
pattern but it seems fairly pointless to highlight the first character
in matches. I've also not put any thought into the affect of various
configurable options, ZLS_COLORS being empty before the ..-end()
function, exactly where in the completer list it should go, etc. I
think ignored suffixes are harmless as we only match against the
beginning of the display string. There are also other options like using
zle_highlight to mark $compstate[insert_positions] on the command-line.



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

  local prefix=${${compstate[unambiguous]}[1,${compstate[unambiguous_cursor]}-1]}
  [[ -n $prefix ]] && \

_show_ambiguity "$@"

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