Function: cider-project-dir

cider-project-dir is a byte-compiled function defined in cider-util.el.

Signature

(cider-project-dir &optional DIR)

Documentation

Return the absolute path of the current Clojure project root, or nil.

DIR defaults to default-directory.

Walks up from DIR looking for any of cider-build-tool-files; the deepest match wins. This finds the Clojure project root even when a broader VC repo (e.g. a .git monorepo) sits higher up, and regardless of whether project-current is backed by project-try-vc, projectile, or any other discovery function plugged into project-find-functions.

Falls back to project-current when no build-tool file is found anywhere up from DIR, so cider-connect invoked from a non-Clojure directory still has a sensible default.

Source Code

;; Defined in ~/.emacs.d/elpa/cider-20260822.1520/cider-util.el
(defun cider-project-dir (&optional dir)
  "Return the absolute path of the current Clojure project root, or nil.
DIR defaults to `default-directory'.

Walks up from DIR looking for any of `cider-build-tool-files'; the
deepest match wins.  This finds the Clojure project root even when a
broader VC repo (e.g. a `.git' monorepo) sits higher up, and regardless
of whether `project-current' is backed by `project-try-vc', projectile,
or any other discovery function plugged into `project-find-functions'.

Falls back to `project-current' when no build-tool file is found
anywhere up from DIR, so `cider-connect' invoked from a non-Clojure
directory still has a sensible default."
  (let ((default-directory (or dir default-directory)))
    (or (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))))
        (when-let* ((proj (project-current)))
          (expand-file-name (project-root proj))))))