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

Re: Preventing sorting in completers



Peter Stephenson wrote:
> I suspect what we want to do is test for an explicitly set sort style in
> _description and used that to override the default.  Then we can all
> forget about tweaking the functions.

For example, the following very lightly tested function where I've tried
not to screw up _expand but fell into apathy at the thought of actually
testing whether I had.

I think this makes the direct use in _history redundant.

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	14 Jul 2003 16:38:30 -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,16 @@
 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.
+if zstyle -s ":completion:${curcontext}:$1" sort sort &&
+    [[ $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	14 Jul 2003 16:38:30 -0000
@@ -2162,12 +2162,19 @@
 )
 kindex(sort, completion style)
 item(tt(sort))(
-If set to `true', completing words from the command
-history sorts the words alphabetically instead of
+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.
+
+When completing words from the command
+history, if set to `true' the words are sorted alphabetically instead of
 keeping them in the order in which they appear in the history (from
 youngest to oldest).
 
-This is also used by the tt(_expand) completer. If it is set to
+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