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

From: Stefan Monnier <[email-masked]>
Date: Sun, 31 Aug 2025 00:31:45 -0400

>>> The appended patch seems to fix it. But I don't know whether this is the
>>> way to go. Stefan?
>>
>> That looks ugly since the completion code should be "above" the
>> `file-name-handler-alist` abstraction and thus shouldn't have
>> Tramp-specific code.
>
> We're speaking about completion of Tramp method, user and host
> names. Something like "/ssh: user@ host:" - I've shown the word
> boundaries as space.

AFAICT the patch changes `completion-file-name-table` which knows
nothing about Tramp, so I don't understand what you mean by "We're
speaking about completion of Tramp ...".

> `file-directory-p' does TRT in Tramp in this case. But it isn't called,
> because of the bypass in `completion-file-name-table', which simply
> looks for a trailing "/". `file-name-handler-alist' abstraction broken.

Ah... right, here the code assumes that the elements returned by
`file-name-all-completions` which are directories all end in `/`, and
indeed that's not guaranteed to hold when we go through
`file-name-handler-alist`.

How 'bout the patch below instead (which generalizes your patch to
all file name handlers)?

        Stefan

diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 122459be062..e2920d76d92 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -3437,7 +3437,9 @@ 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 (find-file-name-handler
+                                      realdir 'file-name-all-completions)))
                            ;; Brute-force speed up for directory checking:
                            ;; Discard strings which don't end in a slash.
                            (lambda (s)