From f8ce65482d86a136f1320dac89e71662256c2168 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20T=C3=A1vora?= Date: Mon, 18 Feb 2019 20:41:09 +0000 Subject: [PATCH 2/2] cycle-sort-function prevails in completion-all-sorted-completions * lisp/minibuffer.el (completion-all-sorted-completions): Don't re-sort if completion table has cycle-sort-function. --- lisp/minibuffer.el | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 7413be42eb..cc87ffaced 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -1246,20 +1246,23 @@ completion-all-sorted-completions (setq all (delete-dups all)) (setq last (last all)) - (setq all (if sort-fun (funcall sort-fun all) - ;; Prefer shorter completions, by default. - (sort all (lambda (c1 c2) (< (length c1) (length c2)))))) - ;; Prefer recently used completions and put the default, if - ;; it exists, on top. - (when (minibufferp) - (let ((hist (symbol-value minibuffer-history-variable))) - (setq all (sort all + (cond + (sort-fun + (setq all (funcall sort-fun all))) + (t + ;; Prefer shorter completions, by default. + (setq all (sort all (lambda (c1 c2) (< (length c1) (length c2))))) + (when (minibufferp) + ;; Prefer recently used completions and put the default, if + ;; it exists, on top. + (let ((hist (symbol-value minibuffer-history-variable))) + (setq all + (sort all (lambda (c1 c2) (cond ((equal c1 minibuffer-default) t) ((equal c2 minibuffer-default) nil) (t (> (length (member c1 hist)) - (length (member c2 hist)))))))))) + (length (member c2 hist)))))))))))) ;; Cache the result. This is not just for speed, but also so that ;; repeated calls to minibuffer-force-complete can cycle through ;; all possibilities. -- 2.20.0