Skip to content

Commit ee91405

Browse files
committed
Make fido-mode behave more like ido-mode when finding directories
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.
1 parent 24a1f52 commit ee91405

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

lisp/icomplete.el

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,24 @@ Usually run by inclusion in `minibuffer-setup-hook'."
442442
(cdr tem)))))
443443
(add-hook 'pre-command-hook 'icomplete-pre-command-hook nil t)
444444
(add-hook 'post-command-hook 'icomplete-post-command-hook nil t)))
445+
446+
(defun icomplete--sorted-completions ()
447+
(let ((all (completion-all-sorted-completions
448+
(icomplete--field-beg) (icomplete--field-end))))
449+
(if (and fido-mode
450+
(window-minibuffer-p)
451+
(not minibuffer-default)
452+
(eq (icomplete--category) 'file))
453+
(cl-loop for l on all
454+
while (listp (cdr l))
455+
for comp = (cadr l)
456+
when (string= comp "./")
457+
do (setf (cdr l) (cddr l))
458+
and return
459+
(setq completion-all-sorted-completions (cons comp all))
460+
finally return all)
461+
all)))
462+
445463

446464

447465

@@ -550,8 +568,7 @@ matches exist."
550568
(funcall predicate cand))))
551569
predicate))
552570
(md (completion--field-metadata (icomplete--field-beg)))
553-
(comps (completion-all-sorted-completions
554-
(icomplete--field-beg) (icomplete--field-end)))
571+
(comps (icomplete--sorted-completions))
555572
(last (if (consp comps) (last comps)))
556573
(base-size (cdr last))
557574
(open-bracket (if require-match "(" "["))

0 commit comments

Comments
 (0)