]> git.eshelyaron.com Git - emacs.git/commitdiff
Make fido-mode behave more like ido-mode when finding directories
authorJoão Távora <joaotavora@gmail.com>
Mon, 23 Dec 2019 23:43:30 +0000 (23:43 +0000)
committerJoão Távora <joaotavora@gmail.com>
Tue, 31 Dec 2019 13:31:45 +0000 (13:31 +0000)
Notably C-x d (M-x dired) and C-x v d (M-x vc-dir) behaved quite
differently, having regular files as the default instead of ido's
usual "./".

* lisp/icomplete.el (icomplete--sorted-completions): New helper.
(icomplete-completions): Use it.

(cherry picked from commit ee914051fbb4fbff9073a23b5ea7668bf48b5c6a)

lisp/icomplete.el

index 4d6dfcd18a189ddab7e7eb41f2204b9fe3b0277d..bf7e2ea7cb415e97e4a11bbe3e83873840cc22ad 100644 (file)
@@ -442,6 +442,24 @@ Usually run by inclusion in `minibuffer-setup-hook'."
                                          (cdr tem)))))
     (add-hook 'pre-command-hook  'icomplete-pre-command-hook  nil t)
     (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))))
+    (if (and fido-mode
+             (window-minibuffer-p)
+             (not minibuffer-default)
+             (eq (icomplete--category) 'file))
+        (cl-loop for l on all
+                 while (listp (cdr l))
+                 for comp = (cadr l)
+                 when (string= comp "./")
+                 do (setf (cdr l) (cddr l))
+                 and return
+                 (setq completion-all-sorted-completions (cons comp all))
+                 finally return all)
+      all)))
+
 \f
 
 
@@ -550,8 +568,7 @@ matches exist."
                          (funcall predicate cand))))
             predicate))
         (md (completion--field-metadata (icomplete--field-beg)))
-        (comps (completion-all-sorted-completions
-                 (icomplete--field-beg) (icomplete--field-end)))
+        (comps (icomplete--sorted-completions))
          (last (if (consp comps) (last comps)))
          (base-size (cdr last))
          (open-bracket (if require-match "(" "["))