]> git.eshelyaron.com Git - emacs.git/commitdiff
Correctly cache sorted completions in icomplete--sorted-completions
authorJoão Távora <joaotavora@gmail.com>
Wed, 25 Dec 2019 17:54:00 +0000 (17:54 +0000)
committerJoão Távora <joaotavora@gmail.com>
Tue, 31 Dec 2019 13:31:45 +0000 (13:31 +0000)
* lisp/icomplete.el (icomplete--sorted-completions): Use
completion--cache-all-sorted-completions.

(cherry picked from commit 83587bb68830bd91124f99ddf8590d1d5f63869f)

lisp/icomplete.el

index ec5591d806e3202fe0fe39fd6c3796daa7e4e197..5126c035de13f9fa1bf94d67d4d9d575087d7eee 100644 (file)
@@ -444,35 +444,36 @@ Usually run by inclusion in `minibuffer-setup-hook'."
     (add-hook 'post-command-hook 'icomplete-post-command-hook nil t)))
 
 (defun icomplete--sorted-completions ()
-  (let ((all (completion-all-sorted-completions
-              (icomplete--field-beg) (icomplete--field-end))))
-    (cl-loop
-     for fn in (cond ((and minibuffer-default
-                           (= (icomplete--field-end) (icomplete--field-beg)))
-                      ;; When we have a non-nil default and no input
-                      ;; whatsoever: we want to make sure that default
-                      ;; is bubbled to the top so that
-                      ;; `icomplete-force-complete-and-exit' will
-                      ;; select it (do that even if the match doesn't
-                      ;; match the completion perfectly.
-                      `(,(lambda (comp)
-                           (equal minibuffer-default comp))
-                        ,(lambda (comp)
-                           (string-prefix-p minibuffer-default comp))))
-                     ((and fido-mode
-                           (not minibuffer-default)
-                           (eq (icomplete--category) 'file))
-                      `(,(lambda (comp)
-                           (string= "./" comp)))))
-     thereis (cl-loop
-              for l on all
-              while (consp (cdr l))
-              for comp = (cadr l)
-              when (funcall fn comp)
-              do (setf (cdr l) (cddr l))
-              and return
-              (setq completion-all-sorted-completions (cons comp all)))
-     finally return all)))
+  (cl-loop
+   with beg = (icomplete--field-beg)
+   with end = (icomplete--field-end)
+   with all = (completion-all-sorted-completions beg end)
+   for fn in (cond ((and minibuffer-default
+                         (= (icomplete--field-end) (icomplete--field-beg)))
+                    ;; When we have a non-nil default and no input
+                    ;; whatsoever: we want to make sure that default
+                    ;; is bubbled to the top so that
+                    ;; `icomplete-force-complete-and-exit' will
+                    ;; select it (do that even if the match doesn't
+                    ;; match the completion perfectly.
+                    `(,(lambda (comp)
+                         (equal minibuffer-default comp))
+                      ,(lambda (comp)
+                         (string-prefix-p minibuffer-default comp))))
+                   ((and fido-mode
+                         (not minibuffer-default)
+                         (eq (icomplete--category) 'file))
+                    `(,(lambda (comp)
+                         (string= "./" comp)))))
+   thereis (cl-loop
+            for l on all
+            while (consp (cdr l))
+            for comp = (cadr l)
+            when (funcall fn comp)
+            do (setf (cdr l) (cddr l))
+            and return
+            (completion--cache-all-sorted-completions beg end (cons comp all)))
+   finally return all))
 
 \f