Subject: Re: bug#77425: 31.0.50; Switching to remote project -> no applicable method

From: Visuwesh <[email-masked]>
Date: Thu, 03 Apr 2025 16:04:40 +0530

[வியாழன் ஏப்ரல் 03, 2025] Gerd Möllmann wrote:

> Gerd Möllmann <[email-masked]> writes:
>
>> - emacs -Q -nw
>>
>> - Eval in *scratch* (or C-x p p equivalent)
>>   (project-switch-project "/ssh:mini:~/emacs/github/master/")
>>   where "/ssh:mini:~/emacs/github/master/" is a Git repository on another machien
>>
>> =>
>>
>> Debugger entered--Lisp error: (cl-no-applicable-method project-root nil)
>
> Bisect gives
>
> 6aa60038ee999d25184a639ce0ac76b614e3afb6 is the first bad commit
> commit 6aa60038ee999d25184a639ce0ac76b614e3afb6
> Author: Visuwesh <[email-masked]>
> Date:   Mon Mar 3 13:56:04 2025 +0530
>     Add new user option to exclude projects from being remembered
>     
>     * lisp/progmodes/project.el (project-list-exclude): Add new user
>     option to exclude projects from being remembered.
>     (project-remember-project): Consider the user option above.
>     (project-switch-project): Use 'project-remember-project' instead.
>     * doc/emacs/maintaining.texi (Managing Projects): Mention the new user option.
>     * etc/NEWS: Announce the change.  (Bug#76587)
>  doc/emacs/maintaining.texi |  9 +++++++++
>  etc/NEWS                   |  7 +++++++
>  lisp/progmodes/project.el  | 21 +++++++++++++++++++--
>  3 files changed, 35 insertions(+), 2 deletions(-)
>
> Author in CC.

Am I right to assume there's no existing Tramp connection to the mini
host?  The recipe signals an error because we call project-current with
MAYBE-PROMPT=nil in project-switch-project, and project-current binds
non-essential depending on the value of MAYBE-PROMPT:

(defun project-current (&optional maybe-prompt directory)
  ...
  (unless directory (setq directory (or project-current-directory-override
                                        default-directory)))
  (let* ((non-essential (not maybe-prompt))
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         (pr (project--find-in-directory directory)))
  ...

With a non-nil non-essential, no wonder project-current fails to return
the project object.  One possible remedy would to be have

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index e2cd5bfa231..dfadf67de27 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -2301,7 +2301,7 @@ project-switch-project
 When called in a program, it will use the project corresponding
 to directory DIR."
   (interactive (list (funcall project-prompter)))
-  (project-remember-project (project-current nil dir))
+  (project-remember-project (project-current t dir))
   (let ((command (if (symbolp project-switch-commands)
                      project-switch-commands
                    (project--switch-project-command dir)))

but I don't know if it is the right solution.  I hope Dmitry (CC'd) will
have a better answer.