[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Strange behavior of `file-exists-p` on latest Tramp version

From: Ruiyang Wu
Subject: Re: Strange behavior of `file-exists-p` on latest Tramp version
Date: Mon, 6 Mar 2023 11:05:54 -0500

Hi Michael,

Currently I only use ivy-mode, so I am not aware if this affects others.

If you are willing to test out ivy-mode, here is the recipe:

With ivy-mode turned on, type "C-x d” (dired), then in the mini buffer, input 
"//ssh:” followed by “C-j” (ivy-alt-done). With Tramp, it will give 
possible completions (which is not as good as Tramp’s builtin completion). With 
Tramp, this gives the error “Reading directory: No such file or 
directory, /ssh:”.

The reason for the error is in the function "ivy--directory-done”.
> (defun ivy--directory-done ()
>   "Handle exit from the minibuffer when completing file names."
>   (let ((dir (ivy--handle-directory ivy-text)))
>     (cond ((equal (ivy-state-current ivy-last) (ivy-state-def ivy-last))
>            (ivy-done))
>           ((and (ivy-state-require-match ivy-last)
>                 (equal ivy-text "")
>                 (null ivy--old-cands))
>            (ivy-immediate-done))
>           (dir
>            (let ((inhibit-message t))
>              (ivy--cd dir)))
>           ((ivy--directory-enter))
>           ((unless (string= ivy-text "")
>              ;; Obsolete since 26.1 and removed in 28.1.
>              (defvar tramp-completion-mode)
>              (with-no-warnings
>                (let* ((tramp-completion-mode t)
>                       (file (expand-file-name
>                              (if (> ivy--length 0) (ivy-state-current 
> ivy-last) ivy-text)
>                              ivy--directory)))
>                  (when (ignore-errors (file-exists-p file))
>                    (if (file-directory-p file)
>                        (ivy--cd (file-name-as-directory file))
>                      (ivy-done))
>                    ivy-text)))))
>           ((or (and (equal ivy--directory "/")
>                     (string-match-p "\\`[^/]+:.*:.*\\'" ivy-text))
>                (string-match-p "\\`/[^/]+:.*:.*\\'" ivy-text))
>            (ivy-done))
>           ((ivy--tramp-prefix-p)
>            (ivy--tramp-candidates))
>           (t
>            (ivy-done)))))
The new behavior of (file-exists-p file) returning t causes the function to 
enter the wrong condition clause. (ivy thinks “/ssh:” is a file and tries to 
open it).


> On Mar 5, 2023, at 3:29 AM, Michael Albinus <> wrote:
> Ruiyang Wu <> writes:
>> Hi,
> Hi Ruiyang,
>> On Tramp version ( (with Emacs 28.2), after setting (setq
>> minibuffer-completing-file-name t), (file-exists-p "/ssh:") returns t,
>> while (tramp-sh-handle-file-exists-p "/ssh:") returns 'Not a Tramp
>> file name: "/ssh:"'.
> tramp-sh-handle-file-exists-p should never be called with "/ssh:", it
> isn't a remote file name. As the error message says. This is not a new 
> behavior.
>> On older versions of Tramp, (file-exists-p
>> "/ssh:") always returns nil. This new behavior affects other
>> completion systems like ivy-mode on melpa.
> Yes, this has been changed for the benefit of Tramp method, user and
> host name completion. See bug#37954, bug#51386, bug#52758, bug#53513,
> bug#54042 and bug#60505.
> I don't use ivy-mode. Could you pls give me a recipe that I can
> reproduce?
> Do you know another completion system which is affected?
>> Best,
>> Ruiyang
> Best regards, Michael.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]