Use project.el directly for project root detection#3922
Merged
Conversation
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.
This was referenced May 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Step 1 of decoupling cider from
clojure-mode/clojure-ts-modefor things that don't actually require either: introducecider-project-dir(built on top ofproject.el) and migrate everyclojure-project-dircall site to it.Why this is better than dispatching between
clojure-project-dirandclojure-ts-project-dir:clojure-project-diruseslocate-dominating-filedirectly, whileclojure-ts-project-dirgoes throughproject.el. The same file can return different roots depending on which major mode is active. One source of truth removes that.clojure-mode,clojure-ts-mode, or any other buffer (e.g.M-x cider-connectfrom Dired).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-filesis appended toproject-vc-extra-root-markersso adeps.edn/project.cljroot wins over a deeper enclosing VC root.locate-dominating-fileagainstcider-build-tool-fileswhenproject.eldoesn't detect anything. That also handles Emacs 28, which doesn't haveproject-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 migratingcider-get-ns-nameoff theup-list-based path entirely.