]> git.eshelyaron.com Git - emacs.git/commitdiff
Use minibuffer-default in completion-all-sorted-completions (bug#34083)
authorJoão Távora <joaotavora@gmail.com>
Thu, 24 Jan 2019 18:04:52 +0000 (18:04 +0000)
committerJoão Távora <joaotavora@gmail.com>
Fri, 25 Jan 2019 13:04:43 +0000 (13:04 +0000)
* lisp/minibuffer (completion-all-sorted-completions): Sort with the
default on top.

lisp/minibuffer.el

index c8b84b0e9476efeff7f1c2775a7a3425720974b3..b757eb8a5a60cc5ff4b494e829e7605606d1204a 100644 (file)
@@ -1244,12 +1244,16 @@ scroll the window of possible completions."
           (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.
+          ;; 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 (lambda (c1 c2)
-                                    (> (length (member c1 hist))
-                                       (length (member c2 hist))))))))
+              (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))))))))))
           ;; Cache the result.  This is not just for speed, but also so that
           ;; repeated calls to minibuffer-force-complete can cycle through
           ;; all possibilities.