9

Is there any way to get the current projectile root path in elisp.

Something similar to the command eproject-root in eproject.

Thanks

Drew
  • 29,895
  • 7
  • 74
  • 104
Pedro Luz
  • 2,694
  • 4
  • 44
  • 54

2 Answers2

14

There is! The function is called projectile-project-root. You can see an example use here in my virtualenvwrapper.el project.

James Porter
  • 1,853
  • 2
  • 17
  • 30
2

There is no single way to do this, as the definition of a project root is not built into emacs.

You can call:

Without depending on 3rd party packages you can use vc directly (assuming projects use version control).

(defun my-vc-root-path-or-default (filepath &optional default)
  "Return the version control directory from FILEPATH or DEFAULT."
  (let ((vc-base-path default))
    (condition-case err
      (let ((vc-backend (ignore-errors (vc-responsible-backend filepath))))
        (when vc-backend
          (setq vc-base-path (vc-call-backend vc-backend 'root filepath))))
      (error (message "Error creating vc-backend root name: %s" err)))
    vc-base-path))
ideasman42
  • 42,413
  • 44
  • 197
  • 320