bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#69584: 29.2.50; project-find-functions should have access to maybe-p


From: Dmitry Gutov
Subject: bug#69584: 29.2.50; project-find-functions should have access to maybe-prompt
Date: Fri, 15 Mar 2024 03:41:01 +0200
User-agent: Mozilla Thunderbird

Hi Spencer,

On 06/03/2024 16:23, Spencer Baugh wrote:

I'd like to write a project-find-function which might prompt when
called, and so to suppress that prompting I'd like to be able to check
the maybe-prompt argument that project-current received.

This is technically doable, but what looks worrying to me, is that this would make 'project-current' lose more of its idempotency.

Originally, the DIRECTORY argument for it was intended to make sure that all calls from the same directory would return the same instance. But of course a hook can be local, so some can find it practical to define buffer-local projects. This side-steps the original design, making, for example, the relation "files A and B are in the same project" not necessarily symmetric or transitive.

Possible new functions for project-find-functions which would benefit
from this:

- A local project-find-function in a version control buffer for viewing
a branch log; if the branch is not currently checked out, prompt to
check out that branch (or create a worktree for it) before returning the
project

- A local project-find-function in a buffer from a package for Git
forges; if the buffer corresponds to a repository which is not currently
cloned locally, prompt to clone the repository.

These behaviors should of course be suppressed if maybe-prompt is nil,
which is why it would be nice to be able to access maybe-prompt.

What would such project functions return when maybe-prompt is nil? Also nil, right? That would kind of create a separate category of projects, interactive-only.

With regards to caching, for example, if some caller wanted to do so (some related discussion: https://github.com/joaotavora/breadcrumb/issues/18#issuecomment-1984615275), then would also need to take this parameter into account.

So the first thing I'd ask is whether you see a different way to implement the same features. I don't see the whole usage scenarios, so it's hard to judge.

Since adding a new argument to project-find-functions is hard, maybe we
could do this by introducing a new dynamic variable
project-find-functions-may-prompt which we let-bind?  Like:

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index c7c07c3d34c..3975182b88d 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -242,8 +242,9 @@ project-current
          (setq pr (cons 'transient directory))))
      pr))
-(defun project--find-in-directory (dir)
-  (run-hook-with-args-until-success 'project-find-functions dir))
+(defun project--find-in-directory (dir &optional maybe-prompt)
+  (let ((project-find-functions-may-prompt maybe-prompt))
+    (run-hook-with-args-until-success 'project-find-functions dir)))
(defvar project--within-roots-fallback nil)

As far as the implementation goes, a dynamic variable can work. We could also try reusing an existing one: non-essential, and we'd set it to nil when maybe-prompt is non-nil.

I wonder how it would interact with Tramp (ask for password in disconnected buffers?), but that seems to fall into the same general category as your other cases.





reply via email to

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