Subject: Re: bug#79236: 30.1; file-directory-p in read-file-name prevents TRAMP protocol, user, and host completions

From: Michael Albinus <[email-masked]>
Date: Mon, 18 Aug 2025 09:03:05 +0200

Michael Albinus <[email-masked]> writes:

Hi,

I'm adding Stefan.

> I've debugged the recipe, and the problem isn't Tramp related. It seems
> to be in function completion-file-name-table, which contains the
> following code:
>
>               ;; Check the predicate, if necessary.
>               (unless (memq pred '(nil file-exists-p))
>                 (let ((comp ())
>                       (pred
>                        (if (eq pred 'file-directory-p)
>                            ;; Brute-force speed up for directory checking:
>                            ;; Discard strings which don't end in a slash.
>                            (lambda (s)
>                              (let ((len (length s)))
>                                (and (> len 0) (eq (aref s (1- len)) ?/))))
>                          ;; Must do it the hard (and slow) way.
>                          pred)))
>                   (let ((default-directory (expand-file-name realdir)))
>                     (dolist (tem all)
>                       (if (funcall pred tem) (push tem comp))))
>                   (setq all (nreverse comp))))
>
> Hmmm. Every hit like "/ssh:" is discarded, when the predicate is file-directory-p.

The appended patch seems to fix it. But I don't know whether this is the
way to go. Stefan?

Best regards, Michael.

diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index f0994adbb70..2129f86b63c 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -3487,9 +3487,15 @@ completion-file-name-table
               (unless (memq pred '(nil file-exists-p))
                 (let ((comp ())
                       (pred
-                       (if (eq pred 'file-directory-p)
+                       (if (and (eq pred 'file-directory-p)
+                                (not (string-match-p
+                                      (or (bound-and-true-p
+                                           tramp-completion-file-name-regexp)
+                                          (rx unmatchable))
+                                      string)))
                            ;; Brute-force speed up for directory checking:
                            ;; Discard strings which don't end in a slash.
+                           ;; Unless it is a Tramp construct like "/ssh:".
                            (lambda (s)
                              (let ((len (length s)))
                                (and (> len 0) (eq (aref s (1- len)) ?/))))