(if (eq (car bounds) base) md-at-point
(completion-metadata (substring string 0 base) table pred))))
-(defun minibuffer--sort-by-key (elems keyfun)
- "Return ELEMS sorted by increasing value of their KEYFUN.
-KEYFUN takes an element of ELEMS and should return a numerical value."
- (mapcar #'cdr
- (sort (mapcar (lambda (x) (cons (funcall keyfun x) x)) elems)
- #'car-less-than-car)))
-
(defun minibuffer--sort-by-position (hist elems)
"Sort ELEMS by their position in HIST."
(let ((hash (make-hash-table :test #'equal :size (length hist)))
(unless (gethash c hash)
(puthash c index hash))
(cl-incf index))
- (minibuffer--sort-by-key
- elems (lambda (x) (gethash x hash most-positive-fixnum)))))
+ (sort elems :key (lambda (x) (gethash x hash most-positive-fixnum)))))
(defun minibuffer--sort-by-length-alpha (elems)
"Sort ELEMS first by length, then alphabetically."
- (sort elems (lambda (c1 c2)
- (or (< (length c1) (length c2))
- (and (= (length c1) (length c2))
- (string< c1 c2))))))
+ (sort elems :key (lambda (c) (cons (length c) c))))
(defun minibuffer--sort-preprocess-history (base)
"Preprocess history.
(defun minibuffer-sort-by-length (completions)
"Sort COMPLETIONS by length."
- (sort completions (lambda (a b) (< (length a) (length b)))))
+ (sort completions :key #'length))
(defun minibuffer-sort-alphabetically (completions)
"Sort COMPLETIONS alphabetically.
This is a suitable function to use for `completions-sort' or to
include as `sort-function' in completion metadata."
- (sort completions #'string-lessp))
+ (sort completions))
(defvar minibuffer-completion-base nil
"The base for the current completion.
This is a suitable function to use for `completions-sort' or to
include as `sort-function' in completion metadata."
- (let ((alphabetized (sort completions #'string-lessp)))
+ (let ((alphabetized (sort completions)))
;; Only use history when it's specific to these completions.
(if (eq minibuffer-history-variable
(default-value minibuffer-history-variable))
group-fun
(pcase completions-group-sort
('nil #'identity)
- ('alphabetical
- (lambda (groups)
- (sort groups
- (lambda (x y)
- (string< (car x) (car y))))))
+ ('alphabetical #'sort)
(_ completions-group-sort))
completions)))
(defun minibuffer--sort-file-names-by-last-modified-time (files)
"Sort file name completion candidates FILES by last modified time."
- (let ((file-time-alist
- (mapcar (lambda (file)
- (cons file
- (file-attribute-modification-time
+ (sort files
+ :key (lambda (f)
+ (list (or (file-attribute-modification-time
(ignore-errors
(file-attributes
(substitute-in-file-name
- (concat minibuffer-completion-base file)))))))
- files)))
- (sort files (lambda (a b)
- (let ((atime (alist-get a file-time-alist
- nil nil #'string=))
- (btime (alist-get b file-time-alist
- nil nil #'string=)))
- (if atime
- (or (not btime)
- ;; Put more recently modified files first.
- (time-less-p btime atime)
- (and (time-equal-p atime btime)
- (string-lessp a b)))
- (and (not btime) (string-lessp a b))))))))
+ (concat minibuffer-completion-base f)))))
+ `(,most-positive-fixnum))
+ f))
+ :reverse t))
(defun read-file-name-default (prompt &optional dir default-filename mustmatch initial predicate)
"Default method for reading file names.