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 18 Feb, Yuri D'Elia wrote:
> It was failing for the following:
> 
> touch 'file a'
> touch 'file b'
> ls file\ <TAB>
> 
> which made me disregard it too quickly. Interestingly it fails due to
> the fact that $MATCH:q is translating ' ' to '\ ' (which should be
> literal in this context). Same for the quotes.

I'd really have expected superfluous quoting like that to be ignored.
Normally it is:

% b=xyz
% [[ $b = *\y* ]] && echo yup
yup
% a='\y'
% [[ $b = *$~a* ]] && echo yup

With your change it seems to work in single quotes but not for backslash
quotes.

I think it is perhaps better to explicitly quote characters that are
special in patterns rather than reverting the quoting for spaces and
quotes. I've included what I now have in full below to make it easier
for anyone following this.

Having used this for a little while now, I've found it is sometimes
vaguely useful. Is it worth adding to git? I'm inclined to think it
should be included in _main_complete as a zstyle option rather than as a
completer.

This is working for many things that need quoting like | and *. I can't
work out how to cope with an initial = mainly because I can't get the
pattern to match it.

A bug I found while looking at this is the following:

% zsh -f
% autoload -U compinit; compinit
% : ${PS\1<tab>
  -> ${PPS1}

Oliver

#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 toquote='[\(\)\|~^?*[\]#]'
  [[ -n $prefix ]] &&
    ZLS_COLORS+=":=(#i)${prefix[1,-2]//?/(}${prefix[1,-2]//(#m)?/${MATCH/$~toquote/\\$MATCH}|)}${prefix[-1]//(#m)$~toquote/\\$MATCH}(#b)(?|)*==4"
}

_show_ambiguity "$@"



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