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

Re: Who is sorting my completion results?



2008/8/30 Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>:
> "Mikael Magnusson" wrote:
>> I'm trying to add reflog completion for git (nevermind what that is if
>> you don't know :), they look like foo@{1}, foo@{2}, etc. git reflog
>> gives an already sorted list of reflog entries, but when I try my
>> completion in the shell, they are re-sorted as foo@{1}, foo@{10},
>> foo@{100}, foo@{2}, etc. Who and why is this list resorted by?
>> (+grammar).
>
> Sorting or not sorting is done by whether you pass the option "-J group"
> or "-V group" to compadd.  In your case it looks like the right thing to
> do is to pass the option "-V" (only) to _wanted, which will construct an
> appropriate argument list for compadd.
> Completion/Zsh/Type/_directory_stack was the simplest example I noticed
> of this happening.

Thanks, with some additional trickery, that did it. With the given
information, I could almost reverse engineer the location in the manpage
where this is written :). _wanted says it has some options in common
with _requested, which in turn hints you might find some information
in the _description text, which does explain what -V does. I am still
somewhat confused about what the difference is between -V, -1V and
-2V though.

The following diff is not submitted in any way, but only to illustrate
the needed changes.

--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -1563,6 +1563,7 @@ _git-checkout () {
   else
     _arguments -C -S \
         '-q[suppress feedback messages]' \
+        '::branch or tree-ish:__git_tree_ishs' \
       - switch-branch \
         '-f[force a complete re-read]' \
         '-b[create a new branch based at given branch]:
:__git_guard_branch-name' \
@@ -1571,9 +1572,7 @@ _git-checkout () {
         '-l[create the branch'\''s reflog]' \
         $new_branch_reflog_arg \
         '-m[3way merge current branch, working tree and new branch]' \
-        '::branch:__git_revisions' \
       - update-files \
-        '::tree-ish:__git_tree_ishs' \
         '*::file:->files' && ret=0
   fi

@@ -2870,9 +2869,8 @@ __git_tree_files () {
 # if both exists, they need to be completed to heads/x and tags/x.
 (( $+functions[__git_commits] )) ||
 __git_commits () {
-  _alternative \
-    'heads::__git_heads' \
-    'tags::__git_tags'
+  __git_heads $*
+  __git_tags $*
 }

 (( $+functions[__git_committishs] )) ||
@@ -3038,7 +3036,7 @@ __git_heads () {

     unset PREFIX IPREFIX

-    _wanted reflog expl reflog-entry compadd $* -ld ref_with_desc - $ref
+    _wanted -V reflog expl reflog-entry compadd $* -ld ref_with_desc - $ref

   else


-- 
Mikael Magnusson



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