Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

### Changes

- Project root detection no longer goes through `clojure-mode'/`clojure-ts-mode'. New `cider-project-dir' built on top of `project.el' is used instead, with `cider-build-tool-files' as the extra root markers. This works identically whether the user is in `clojure-mode', `clojure-ts-mode', or even a buffer not visiting a Clojure file (e.g. an `M-x cider-connect' from Dired), and respects any `project-find-functions' the user has configured.
- [#710](https://github.com/clojure-emacs/cider-nrepl/issues/710): Use namespaced nREPL ops (e.g. `cider/info` instead of `info`) to match cider-nrepl 0.59+.
- Bump the injected `nrepl` to [1.7.0](https://github.com/nrepl/nrepl/blob/master/CHANGELOG.md#170-2026-04-14).
- Bump the injected `cider-nrepl` to [0.59.0](https://github.com/clojure-emacs/cider-nrepl/blob/master/CHANGELOG.md#0590-2026-04-14).
Expand Down
2 changes: 1 addition & 1 deletion lisp/cider-client.el
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ resolve those to absolute paths."
(cider-sync-tooling-eval)
(nrepl-dict-get "value")
read))
(project (clojure-project-dir)))
(project (cider-project-dir)))
(mapcar (lambda (path) (cider--get-abs-path path project)) classpath))))

(defun cider-classpath-entries (&optional connection)
Expand Down
4 changes: 2 additions & 2 deletions lisp/cider-cljs.el
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ The default options of `browser-repl' and `node-repl' are also included."

(defun cider--shadow-get-builds ()
"Extract build names from the shadow-cljs.edn config file in the project root."
(let ((shadow-edn (concat (clojure-project-dir) "shadow-cljs.edn")))
(let ((shadow-edn (concat (cider-project-dir) "shadow-cljs.edn")))
(when (file-readable-p shadow-edn)
(with-temp-buffer
(insert-file-contents shadow-edn)
Expand Down Expand Up @@ -206,7 +206,7 @@ Figwheel for details."
(defun cider--figwheel-main-get-builds ()
"Extract build names from the <build-id>.cljs.edn config files.
Fetches them in the project root."
(when-let ((project-dir (clojure-project-dir)))
(when-let ((project-dir (cider-project-dir)))
(let ((builds (directory-files project-dir nil ".*\\.cljs\\.edn")))
(mapcar (lambda (f) (string-match "^\\(.*\\)\\.cljs\\.edn" f)
(match-string 1 f))
Expand Down
2 changes: 1 addition & 1 deletion lisp/cider-doc.el
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ Same for `jar:file:...!/' segments."
file-with-protocol)))
(if (string-match "\\`file:\\(.*\\)" result)
(let ((file (match-string 1 result))
(proj-dir (clojure-project-dir)))
(proj-dir (cider-project-dir)))
(if (and proj-dir
(file-in-directory-p file proj-dir))
(file-relative-name file proj-dir)
Expand Down
2 changes: 1 addition & 1 deletion lisp/cider-endpoint.el
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ Necessary since we run some OS-specific commands that may fail."
When DIR is non-nil also look for nREPL port files in DIR. Return a list
of list of the form (project-dir port)."
(let* ((pairs (cider--running-nrepl-paths))
(pairs (if-let (c (and dir (clojure-project-dir dir)))
(pairs (if-let (c (and dir (cider-project-dir dir)))
(append (cider--path->path-port-pairs c) pairs)
pairs)))
(thread-last pairs
Expand Down
8 changes: 4 additions & 4 deletions lisp/cider-jack-in.el
Original file line number Diff line number Diff line change
Expand Up @@ -709,10 +709,10 @@ that host instead of the local one."

(defun cider--resolve-project-command (command)
"Find COMMAND in project dir or exec path (see variable `exec-path').
If COMMAND starts with ./ or ../ resolve relative to `clojure-project-dir',
If COMMAND starts with ./ or ../ resolve relative to `cider-project-dir',
otherwise resolve via `cider--resolve-command'."
(if (string-match-p "\\`\\.\\{1,2\\}/" command)
(locate-file command (list (clojure-project-dir)) '("" ".bat") 'executable)
(locate-file command (list (cider-project-dir)) '("" ".bat") 'executable)
(cider--resolve-command command)))

(defun cider--resolve-prefix-command (command)
Expand Down Expand Up @@ -962,7 +962,7 @@ only when the ClojureScript dependencies are met."
"Identify build systems present by their build files in PROJECT-DIR.
PROJECT-DIR defaults to the current project. The set of recognized build
files is derived from the :project-files entries in `cider-jack-in-tools'."
(let ((default-directory (or project-dir (clojure-project-dir (cider-current-dir)))))
(let ((default-directory (or project-dir (cider-project-dir (cider-current-dir)))))
(delq nil
(mapcar (lambda (entry)
(when (seq-some #'file-exists-p
Expand Down Expand Up @@ -1044,7 +1044,7 @@ For example, to jack in to leiningen which is assigned to prefix arg 2 type

M-2 \\[cider-jack-in-universal]."
(interactive "P")
(let ((cpt (clojure-project-dir (cider-current-dir))))
(let ((cpt (cider-project-dir (cider-current-dir))))
(if (or (integerp arg) (null cpt))
(let* ((tools (cider--universal-jack-in-tools))
(project-type
Expand Down
4 changes: 2 additions & 2 deletions lisp/cider-repl.el
Original file line number Diff line number Diff line change
Expand Up @@ -1390,7 +1390,7 @@ regexes from `cider-locref-regexp-alist' to infer locations at point."
(let ((file-from-regexp (if (file-name-absolute-p file)
file
;; when not absolute, expand within the current project
(when-let* ((proj (clojure-project-dir)))
(when-let* ((proj (cider-project-dir)))
(expand-file-name file proj)))))
(or (when (file-readable-p file-from-regexp)
file-from-regexp)
Expand Down Expand Up @@ -1598,7 +1598,7 @@ It does not yet set the input history."
"Find the first suitable directory to store the project's history."
(seq-find
(lambda (dir) (and dir (not (tramp-tramp-file-p dir))))
(list nrepl-project-dir (clojure-project-dir) default-directory)))
(list nrepl-project-dir (cider-project-dir) default-directory)))

(defun cider-repl-history-load (&optional filename)
"Load history from FILENAME into current session.
Expand Down
4 changes: 2 additions & 2 deletions lisp/cider-session.el
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ removed."
(let* ((dir (directory-file-name
(abbreviate-file-name
(or (plist-get params :project-dir)
(clojure-project-dir (cider-current-dir))
(cider-project-dir (cider-current-dir))
default-directory))))
(short-proj (file-name-nondirectory (directory-file-name dir)))
(parent-dir (ignore-errors
Expand Down Expand Up @@ -403,7 +403,7 @@ Reverts to normal project-based session association."

(cl-defmethod sesman-project ((_system (eql CIDER)))
"Find project directory."
(clojure-project-dir (cider-current-dir)))
(cider-project-dir (cider-current-dir)))

(cl-defmethod sesman-more-relevant-p ((_system (eql CIDER)) session1 session2)
"Figure out if SESSION1 or SESSION2 is more relevant."
Expand Down
52 changes: 52 additions & 0 deletions lisp/cider-util.el
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
(require 'clojure-mode)
(require 'nrepl-dict)

;; Declared so the byte-compiler doesn't flag the `let' binding in
;; `cider-project-dir' as an unused lexical variable on Emacs 28,
;; where project.el doesn't define this variable.
(defvar project-vc-extra-root-markers)

(defalias 'cider-pop-back #'pop-tag-mark)

(defcustom cider-font-lock-max-length 10000
Expand Down Expand Up @@ -89,6 +94,53 @@ Setting this to nil removes the fontification restriction."
(file-name-directory buffer-file-name)
default-directory))

(defcustom cider-build-tool-files
'("project.clj" ; Leiningen
"build.boot" ; Boot
"build.gradle" ; Gradle
"build.gradle.kts" ; Gradle Kotlin
"deps.edn" ; Clojure CLI (tools.deps)
"shadow-cljs.edn" ; shadow-cljs
"bb.edn" ; babashka
"nbb.edn" ; nbb
"basilisp.edn" ; Basilisp (Python)
)
"Files indicating the root of a Clojure project.
Used by `cider-project-dir' as extra root markers passed to
`project.el'."
:type '(repeat string)
:group 'cider
:safe (lambda (value)
(and (listp value)
(cl-every #'stringp value))))

(defun cider-project-dir (&optional dir)
"Return the absolute path of the current Clojure project root, or nil.
DIR defaults to `default-directory'.

Built on top of `project.el', so the result respects any project-discovery
customization the user has configured (`project-find-functions',
`project-vc-extra-root-markers', etc.). `cider-build-tool-files' extends
the set of markers project.el's VC backend will accept, so a `deps.edn'
or `project.clj' root wins over a deeper enclosing VC root.

Falls back to a `locate-dominating-file' search against
`cider-build-tool-files' when project.el doesn't detect anything; this
also covers Emacs 28, which doesn't have `project-vc-extra-root-markers'."
(let ((default-directory (or dir default-directory)))
(or (let ((project-vc-extra-root-markers
(append (and (boundp 'project-vc-extra-root-markers)
project-vc-extra-root-markers)
cider-build-tool-files)))
(when-let* ((proj (project-current)))
(expand-file-name (project-root proj))))
(when-let* ((hits (delq nil
(mapcar (lambda (f)
(locate-dominating-file
default-directory f))
cider-build-tool-files))))
(expand-file-name (car (sort hits #'file-in-directory-p)))))))

(defun cider-in-string-p ()
"Return non-nil if point is in a string."
(let ((beg (save-excursion (beginning-of-defun-raw) (point))))
Expand Down
4 changes: 2 additions & 2 deletions lisp/cider.el
Original file line number Diff line number Diff line change
Expand Up @@ -353,14 +353,14 @@ Params is a plist with the following keys (non-exhaustive)
(proj-dir (if (or (plist-get params :do-prompt)
(plist-get params :edit-project-dir))
(read-directory-name "Project: "
(clojure-project-dir (cider-current-dir)))
(cider-project-dir (cider-current-dir)))
(plist-get params :project-dir)))
(orig-buffer (current-buffer)))
(if (or (null proj-dir)
(file-in-directory-p default-directory proj-dir))
(plist-put params :project-dir
(or proj-dir
(clojure-project-dir (cider-current-dir))))
(cider-project-dir (cider-current-dir))))
;; If proj-dir is not a parent of default-directory, transfer all
;; local variables and hack dir-local variables into a temporary
;; buffer kept on `params' for the rest of the param-update pipeline.
Expand Down
10 changes: 5 additions & 5 deletions test/cider-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
:and-call-fake (lambda (params) (setq chosen-fn 'clj chosen-args params)))
(spy-on 'cider-jack-in-cljs
:and-call-fake (lambda (params) (setq chosen-fn 'cljs chosen-args params)))
(spy-on 'clojure-project-dir :and-return-value nil))
(spy-on 'cider-project-dir :and-return-value nil))

(it "dispatches to cider-jack-in-clj for a clj prefix-arg"
(cider-jack-in-universal 2)
Expand Down Expand Up @@ -572,7 +572,7 @@
(file-path (concat temporary-file-directory edn-file)))
(with-temp-file file-path
(insert ,contents))
(spy-on 'clojure-project-dir :and-return-value temporary-file-directory)
(spy-on 'cider-project-dir :and-return-value temporary-file-directory)
,@body
(delete-file file-path)))

Expand Down Expand Up @@ -637,12 +637,12 @@
(expect (cider--resolve-command "no-such-command") :to-be nil))))

(describe "cider--resolve-project-command"
(it "if command starts with ./ it resolves relative to clojure-project-dir"
(it "if command starts with ./ it resolves relative to cider-project-dir"
(spy-on 'locate-file :and-return-value "/project/command")
(spy-on 'executable-find :and-return-value "/bin/command")
(expect (cider--resolve-project-command "./command")
:to-equal "/project/command"))
(it "if command starts with ../ it resolves relative to clojure-project-dir"
(it "if command starts with ../ it resolves relative to cider-project-dir"
(spy-on 'locate-file :and-return-value "/project/command")
(spy-on 'executable-find :and-return-value "/bin/command")
(expect (cider--resolve-project-command "../command")
Expand Down Expand Up @@ -741,7 +741,7 @@
(spy-on 'cider--running-lein-nrepl-paths :and-return-value '(("lein" "1234")))
(spy-on 'cider--running-local-nrepl-paths :and-return-value '(("local" "2345")))
(spy-on 'cider--running-non-lein-nrepl-paths :and-return-value '(("non-lein" "3456")))
(spy-on 'clojure-project-dir :and-return-value #'identity)
(spy-on 'cider-project-dir :and-return-value #'identity)
(spy-on 'cider--path->path-port-pairs :and-return-value '(("from-dir" "4567")))
(spy-on 'directory-file-name :and-call-fake #'identity)
(spy-on 'file-name-nondirectory :and-call-fake #'identity)
Expand Down
Loading