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

Re: Preventing sorting in completers



Bart Schaefer wrote:
> Slightly revised suggestion:  Allow styles to override an explicit -J,
> but do not allow overriding an explicit -V.  I did a quick grep, and
> there are very few cases where the -V option is passed; but in none of
> those would it be useful to apply a sort.

I've now ended up with the following.  The special history code is still
necessary because it reverses the usual default; it assumes you don't
want it sorted unless you say you do.

Index: Completion/Base/Core/_description
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/Core/_description,v
retrieving revision 1.4
diff -u -r1.4 _description
--- Completion/Base/Core/_description	12 Feb 2002 13:37:03 -0000	1.4
+++ Completion/Base/Core/_description	15 Jul 2003 18:32:02 -0000
@@ -1,6 +1,6 @@
 #autoload
 
-local name gropt nopt xopt format gname hidden hide match opts tag
+local name gropt nopt xopt format gname hidden hide match opts tag sort
 
 opts=()
 
@@ -30,6 +30,18 @@
 zstyle -s ":completion:${curcontext}:$1" matcher match &&
     opts=($opts -M "$match")
 [[ -n "$_matcher" ]] && opts=($opts -M "$_matcher")
+
+# Use sort style, but ignore `menu' value to help _expand.
+# Also don't override explicit use of -V.
+if { zstyle -s ":completion:${curcontext}:$1" sort sort ||
+     zstyle -s ":completion:${curcontext}:" sort sort; } &&
+    [[ "$gropt" = -J && $sort != menu ]]; then
+    if [[ "$sort" = (yes|true|1|on) ]]; then
+	gropt=(-J)
+    else
+	gropt=(-V)
+    fi
+fi
 
 if [[ -z "$_comp_no_ignore" ]]; then
   zstyle -a ":completion:${curcontext}:$1" ignored-patterns _comp_ignore ||
Index: Doc/Zsh/compsys.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v
retrieving revision 1.171
diff -u -r1.171 compsys.yo
--- Doc/Zsh/compsys.yo	7 Jul 2003 09:48:46 -0000	1.171
+++ Doc/Zsh/compsys.yo	15 Jul 2003 18:32:02 -0000
@@ -2162,12 +2162,22 @@
 )
 kindex(sort, completion style)
 item(tt(sort))(
-If set to `true', completing words from the command
-history sorts the words alphabetically instead of
-keeping them in the order in which they appear in the history (from
-youngest to oldest).
+Many completion widgets call tt(_description) at some point which
+decides whether the matches are added sorted or unsorted (often
+indirectly via tt(_wanted) or tt(_requested)).  This style can be set
+explicitly to one of the usual true or false values as an override.
+If it is not set for the context, the standard behaviour of the
+calling widget is used.
 
-This is also used by the tt(_expand) completer. If it is set to
+The style is tested first against the full context including the tag, and
+if that fails to produce a value against the context without the tag.
+
+If the calling widget explicitly requests unsorted matches, this is usually
+honoured.  However, the default (unsorted) behaviour of completion
+for the command history may be overridden by setting the style to
+tt(true).
+
+In the tt(_expand) completer, if it is set to
 `true', the expansions generated will always be sorted.  If it is set
 to `tt(menu)', then the expansions are only sorted when they are offered 
 as single strings but not in the string containing all possible

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************



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