Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: widget special PREFIX variable and cursor position with complete_in_word
- X-seq: zsh-users 18448
- From: Oliver Kiddle <okiddle@xxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: widget special PREFIX variable and cursor position with complete_in_word
- Date: Fri, 14 Feb 2014 12:56:54 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s1024; t=1392379015; bh=VmpBWuJzRl3w0uuPlYsznajd5LrSnqPpYMke4LzxoYQ=; h=X-Yahoo-Newman-Id:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:X-Rocket-Received:Received:In-reply-to:From:References:To:Subject:MIME-Version:Content-Type:Content-ID:Date:Message-ID; b=ke1DAH57JlWLBBwlnov2BlMGRQ0WquBnP2aVmpy6Z0iO6qeKZ+ol71HKzXHOpeq8S4FzUJsp6Uw+osGg1dJqVOagDqSF7oP0gl2WspdlsLpNPDTMkvFJm2pZZp5blTvMbPbF3BFJ6a5ssbdWT7XkPcQz/0+Arjv/7jCGPK6myvo=
- In-reply-to: <140213223438.ZM27375@torch.brasslantern.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <ldgnl5$fo8$1@ger.gmane.org> <140212214707.ZM25929@torch.brasslantern.com> <ldii13$jg7$1@ger.gmane.org> <140213092531.ZM26966@torch.brasslantern.com> <ldj21h$9dj$1@ger.gmane.org> <140213223438.ZM27375@torch.brasslantern.com>
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.
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]}
[[ -n $prefix ]] && \
ZLS_COLORS+=":=${prefix[1,-2]//?/(}${prefix[1,-2]//(#m)?/$MATCH:q|)}$prefix[-1](#b)(?|)*==4"
}
_show_ambiguity "$@"
Messages sorted by:
Reverse Date,
Date,
Thread,
Author