Function: completion-all-sorted-completions
completion-all-sorted-completions is a byte-compiled function defined
in minibuffer.el.gz.
Signature
(completion-all-sorted-completions &optional START END)
Source Code
;; Defined in /usr/src/emacs/lisp/minibuffer.el.gz
(defun completion-all-sorted-completions (&optional start end)
(or completion-all-sorted-completions
(let* ((start (or start (minibuffer-prompt-end)))
(end (or end (point-max)))
(string (buffer-substring start end))
(md (completion--field-metadata start))
(all (completion-all-completions
string
minibuffer-completion-table
minibuffer-completion-predicate
(- (point) start)
md))
(last (last all))
(base-size (or (cdr last) 0))
(all-md (completion--metadata (buffer-substring-no-properties
start (point))
base-size md
minibuffer-completion-table
minibuffer-completion-predicate))
(sort-fun (completion-metadata-get all-md 'cycle-sort-function))
(group-fun (completion-metadata-get all-md 'group-function)))
(when last
(setcdr last nil)
;; Delete duplicates: do it after setting last's cdr to nil (so
;; it's a proper list), and be careful to reset `last' since it
;; may be a different cons-cell.
(setq all (delete-dups all))
(setq last (last all))
(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))
;; 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)))))
;; Cache the result. This is not just for speed, but also so that
;; repeated calls to minibuffer-force-complete can cycle through
;; all possibilities.
(completion--cache-all-sorted-completions
start end (nconc all base-size))))))