completion: override default alphabetical sorting
The "*Completions*" buffer for completing-read and for crm-driven read-from-minibuffer defaults to alphabetically sorting the collection. As a result, any meaningful order given to the collection (e.g., by the recently added magit-list-refs-sortby) won't be visible to the user. This is probably most problematic when reading a refname in a repo with many numeric tags because these tags are displayed before branches staring with letters even though tags (and especially the older tags at the beginning of the list) are not likely to be the desired target. If the order of the collection is respected, this problem is avoided because, by default, magit-list-refs returns refs sorted by their full name, so branches ("refs/heads") come before tags ("refs/tags"), as well as remotes ("refs/remotes") and GitHub pull requests ("refs/pull"). Preserve the order of the collection by using identity for the display-sort-function metadata. Unfortunately, the items are actually displayed in reverse in some cases because a completion function, completion-pcm--all-completions, reverses the collection's order (Emacs bug#24676). The next commit will add a kludge for this. Many third-party completion packages preserve the order of the collection without any intervention. I tested completing-read and crm completion with magit-completing-read-function set to magit-ido-completing-read, helm--completing-read-default, and ivy-completing-read. These all appeared to work fine. With the global modes for helm and ivy enabled, the order in the crm completion list is not preserved. In the case of ivy, this is due to bug#24676. For helm, this is because helm--completion-in-region uses its own function to sort the output of completion-all-completions. Closes #2925.
Showing with 15 additions and 2 deletions