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

PATCH: Re: widget special PREFIX variable and cursor position with complete_in_word



Yuri D'Elia wrote:
> I would definitely like this as a general addition to the main completer.
> 
> It just needs a customizable color for the match.

This patch adds a 'show-ambiguity' style. The value is the colour to
use.

One thing I've noticed is that the patterns specified with ZLS_COLORS
will also match descriptions. This can be annoying if the -- separator
(or whatever you configure the list-separator style to) matches for the
ambiguity. It is actually a nice feature if you include something like
'=(#b)(--) (*)==32=3' in list-colors. Given that there is syntax for
selecting matches by tag group, I wonder if something could be easily
added for the descriptions. I'm not sure what syntax would make sense.

Oliver

diff --git a/Completion/Base/Core/_main_complete b/Completion/Base/Core/_main_complete
index 8dd781d..e881ea6 100644
--- a/Completion/Base/Core/_main_complete
+++ b/Completion/Base/Core/_main_complete
@@ -334,6 +334,14 @@ elif [[ nm -eq 0 && -z "$_comp_mesg" &&
   compadd -x "$mesg"
 fi
 
+if zstyle -s ":completion:${curcontext}:" show-ambiguity tmp; then
+  local prefix=${${compstate[unambiguous]}[1,${compstate[unambiguous_cursor]}-1]}
+  local toquote='[=\(\)\|~^?*[\]#<>]'
+  [[ $tmp = (yes|true|on) ]] && tmp=4
+  [[ -n $prefix ]] &&
+    _comp_colors+=( "=(#i)${prefix[1,-2]//?/(}${prefix[1,-2]//(#m)?/${MATCH/$~toquote/\\$MATCH}|)}${prefix[-1]//(#m)$~toquote/\\$MATCH}(#b)(?|)*==$tmp" )
+fi
+
 [[ "$_comp_force_list" = always ||
    ( "$_comp_force_list" = ?*  && nm -ge _comp_force_list ) ]] &&
     compstate[list]="${compstate[list]//messages} force"
diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo
index c304461..5a5e619 100644
--- a/Doc/Zsh/compsys.yo
+++ b/Doc/Zsh/compsys.yo
@@ -2440,6 +2440,15 @@ completing words for the dict command. It allows words from different
 dictionary databases to be added separately.
 The default for this style is `false'.
 )
+kindex(show-ambiguity, completion style)
+item(tt(show-ambiguity))(
+If the tt(zsh/complist) module is loaded, this style can be used to
+highlight the first ambiguous character in completion lists. The
+value is either a color indication such as those supported by the
+tt(list-colors) style or, with a value of tt(true), a default of
+underlining is selected. The highlighting is only applied if the
+completion display strings correspond to the actual matches.
+)
 kindex(show-completer, completion style)
 item(tt(show-completer))(
 Tested whenever a new completer is tried.  If it is true, the completion



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