base-size md
minibuffer-completion-table
minibuffer-completion-predicate))
- (sort-fun (completion-metadata-get all-md 'cycle-sort-function)))
+ (sort-fun (completion-metadata-get all-md 'cycle-sort-function))
+ (group-fun (completion-metadata-get all-md 'group-function)))
(when last
(setcdr last nil)
(setq all (delete-dups all))
(setq last (last all))
- (if sort-fun
- (setq all (funcall sort-fun all))
- ;; Sort first by length and alphabetically.
+ (cond
+ (sort-fun (setq all (funcall sort-fun all)))
+ ((and completions-group group-fun)
+ ;; TODO: experiment with re-grouping here. Might be slow
+ ;; if the group-fun (given by the table and out of our
+ ;; control) is slow and/or allocates too much.
+ )
+ (t
+ ;; If the table doesn't stipulate a sorting function or a
+ ;; group function, sort first by length and
+ ;; alphabetically.
(setq all (minibuffer--sort-by-length-alpha all))
- ;; Sort by history position, put the default, if it
+ ;; Then sort by history position, and put the default, if it
;; exists, on top.
(when (minibufferp)
(setq all (minibuffer--sort-by-position
(minibuffer--sort-preprocess-history
(substring string 0 base-size))
- all))))
+ all)))))
;; Cache the result. This is not just for speed, but also so that
;; repeated calls to minibuffer-force-complete can cycle through