Subject: Re: bug#78929: 31.0.50; ffap does not find the correct filename in remote projects

From: Spencer Baugh <[email-masked]>
Date: Thu, 03 Jul 2025 14:02:21 -0400

Eli Zaretskii <[email-masked]> writes:

>> From: Liu Hui <[email-masked]>
>> Date: Mon, 30 Jun 2025 22:47:10 +0800
>> 
>> Hi,
>> 
>> The following recipe is extracted from bug#78925:
>> 
>> 1. emacs -Q
>> 2. Open a file in a remote project:
>>    C-x C-f /ssh:server:~/a_git_project/test_file
>> 3. Create a file that exists outside the project in the remote host, e.g.
>>    M-! touch /tmp/abc
>> 4. type the above filename (i.e. /tmp/abc) in test_file, and M-x ffap
>> 
>> ffap prompts /ssh:server:~/a_git_project/tmp/abc, while in Emacs 29
>> prompts /ssh:server:/tmp/abc correctly. This problem seems to be
>> related to commit 1eae0e7edf4.
>
> Spencer, could you please look into this?

Thanks for the report, this is indeed a bug in ffap-in-project.  This
should be fixed by the attached patch, could you please test?

>From 3d6b886fb8d9f30ec72950e969427925299d3c8e Mon Sep 17 00:00:00 2001
From: Spencer Baugh <[email-masked]>
Date: Thu, 3 Jul 2025 13:59:46 -0400
Subject: [PATCH] Fix ffap-in-project to check file existence

* lisp/ffap.el (ffap-in-project): Check file existence before
returning non-nil. (bug#78929)
---
 lisp/ffap.el | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lisp/ffap.el b/lisp/ffap.el
index 1c9f0294601..10afcd9514a 100644
--- a/lisp/ffap.el
+++ b/lisp/ffap.el
@@ -807,7 +807,9 @@ ffap-completable
 (declare-function project-root "project" (project))
 (defun ffap-in-project (name)
   (when-let* ((project (project-current)))
-    (file-name-concat (project-root project) name)))
+    (ffap-file-exists-string
+     (file-name-concat (project-root project) name)
+     'nomodify)))
 
 (defun ffap-home (name) (ffap-locate-file name t '("~")))
 
-- 
2.39.3