Function: minibuffer-sort-by-history
minibuffer-sort-by-history is a byte-compiled function defined in
minibuffer.el.gz.
Signature
(minibuffer-sort-by-history COMPLETIONS)
Documentation
Sort COMPLETIONS by their position in minibuffer-history-variable.
COMPLETIONS are sorted first by minibuffer-sort-alphbetically,
then any elements occurring in the minibuffer history list are
moved to the front based on the chronological order they occur in
the history. If a history variable hasn't been specified for
this call of completing-read, COMPLETIONS are sorted only by
minibuffer-sort-alphbetically.
This is a suitable function to use for completions-sort or to
include as display-sort-function in completion metadata.
Source Code
;; Defined in /usr/src/emacs/lisp/minibuffer.el.gz
(defun minibuffer-sort-by-history (completions)
"Sort COMPLETIONS by their position in `minibuffer-history-variable'.
COMPLETIONS are sorted first by `minibuffer-sort-alphbetically',
then any elements occurring in the minibuffer history list are
moved to the front based on the chronological order they occur in
the history. If a history variable hasn't been specified for
this call of `completing-read', COMPLETIONS are sorted only by
`minibuffer-sort-alphbetically'.
This is a suitable function to use for `completions-sort' or to
include as `display-sort-function' in completion metadata."
(let ((alphabetized (sort completions #'string-lessp)))
;; Only use history when it's specific to these completions.
(if (eq minibuffer-history-variable
(default-value minibuffer-history-variable))
alphabetized
(minibuffer--sort-by-position
(minibuffer--sort-preprocess-history minibuffer-completion-base)
alphabetized))))