Function: clojure-project-root-path

clojure-project-root-path is a byte-compiled function defined in clojure-mode.el.

Signature

(clojure-project-root-path &optional DIR-NAME)

Documentation

Return the absolute path to the project's root directory.

Use default-directory if DIR-NAME is nil. Return nil if not inside a project.

Source Code

;; Defined in ~/.emacs.d/elpa/clojure-mode-20260325.811/clojure-mode.el
(defun clojure-project-root-path (&optional dir-name)
  "Return the absolute path to the project's root directory.

Use `default-directory' if DIR-NAME is nil.
Return nil if not inside a project."
  (let* ((dir-name (or dir-name default-directory))
         (choices (delq nil
                        (mapcar (lambda (fname)
                                  (locate-dominating-file dir-name fname))
                                clojure-build-tool-files))))
    (when choices
      (if clojure-preferred-build-tool
          ;; When a preferred build tool is set, look for it specifically.
          (or (locate-dominating-file dir-name clojure-preferred-build-tool)
              (car (sort choices #'file-in-directory-p)))
        ;; Otherwise, prefer candidates that contain a .git directory.
        ;; Note: `sort' is destructive, so we must capture its return value.
        (let ((sorted (sort choices #'file-in-directory-p)))
          (or (car (seq-filter (lambda (dir)
                                 (file-directory-p (expand-file-name ".git" dir)))
                               sorted))
              (car sorted)))))))