Skip to content

Use project.el directly for project root detection#3922

Merged
bbatsov merged 2 commits into
masterfrom
decouple-project-dir
May 20, 2026
Merged

Use project.el directly for project root detection#3922
bbatsov merged 2 commits into
masterfrom
decouple-project-dir

Conversation

@bbatsov
Copy link
Copy Markdown
Member

@bbatsov bbatsov commented May 19, 2026

Step 1 of decoupling cider from clojure-mode/clojure-ts-mode for things that don't actually require either: introduce cider-project-dir (built on top of project.el) and migrate every clojure-project-dir call site to it.

Why this is better than dispatching between clojure-project-dir and clojure-ts-project-dir:

  • The two have different semantics today. clojure-project-dir uses locate-dominating-file directly, while clojure-ts-project-dir goes through project.el. The same file can return different roots depending on which major mode is active. One source of truth removes that.
  • Works the same in clojure-mode, clojure-ts-mode, or any other buffer (e.g. M-x cider-connect from Dired).
  • Respects project-find-functions, project-vc-extra-root-markers, etc., the same project.el customization users already have configured for everything else in Emacs.
  • cider-build-tool-files is appended to project-vc-extra-root-markers so a deps.edn/project.clj root wins over a deeper enclosing VC root.
  • Falls back to locate-dominating-file against cider-build-tool-files when project.el doesn't detect anything. That also handles Emacs 28, which doesn't have project-vc-extra-root-markers.

No caching layer for now. project.el's detection is already cheap in the common case, and adding a cache would need an invalidation story we don't have yet. Easy follow-up if profiling turns up a hot path.

Follow-ups in the same direction (not in this PR): cider-expected-ns, and migrating cider-get-ns-name off the up-list-based path entirely.

bbatsov added 2 commits May 19, 2026 17:10
Introduce `cider-project-dir` + `cider-build-tool-files` and migrate
all `clojure-project-dir' call sites to use them.  Project root
detection now goes through `project.el' instead of bouncing through
`clojure-mode' or `clojure-ts-mode' wrappers.

This:

* Decouples cider's project detection from `clojure-mode' (it still
  needs the package loaded for other reasons, but not for this one).
* Works the same whether the buffer is in `clojure-mode',
  `clojure-ts-mode', or anything else (e.g. running `cider-connect'
  from Dired).
* Respects user customisation of `project-find-functions',
  `project-vc-extra-root-markers', and friends -- the same semantics
  clojure-ts-mode already adopted internally.

Falls back to `locate-dominating-file' against
`cider-build-tool-files' when `project.el' doesn't find anything; that
also covers Emacs 28, which doesn't have `project-vc-extra-root-markers'.

No caching layer for now -- `project.el's' detection is already cheap
in the common case, and adding our own cache would require a clear
invalidation story we don't have yet.  Easy to revisit if profiling
turns up a hot path.
On Emacs 28, project.el doesn't define this variable, so the
byte-compiler treats the `let' binding in `cider-project-dir' as an
unused lexical variable.  Declaring it with a value-less `defvar' tells
the compiler it's dynamic without changing runtime behavior.
@bbatsov bbatsov merged commit b4a83d7 into master May 20, 2026
13 checks passed
@bbatsov bbatsov deleted the decouple-project-dir branch May 20, 2026 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant