4

At times I want to browse the code of projects to which I have read-only access. This makes it impossible for me to drop a .projectile file at the root of the project.

Is there a way to define projects for use with projectile when I do not have write access to the project directories?

3

GitHub user thomasf provided a workaround which I modified only slightly:

;; (source: https://github.com/bbatsov/projectile/issues/364#issuecomment-61296248)
(defun projectile-root-child-of (dir &optional list)
  (projectile-locate-dominating-file
   dir
   (lambda (dir)
     (--first
      (if (and
           (s-equals? (file-remote-p it) (file-remote-p dir))
           (string-match-p (expand-file-name it) (expand-file-name dir)))
          dir)
      (or list project-root-regexps (list))))))

(defvar project-root-regexps ()
  "List of regexps to match against when projectile is searching
  for project root directories.")

(add-to-list 'project-root-regexps "/path/to/some/project/$")
(add-to-list 'project-root-regexps "/path/to/another/project/$")
(add-to-list 'project-root-regexps "/path/to/one/more/project/$")

(nconc projectile-project-root-files-functions '(projectile-root-child-of))

This lets me add projects to to the list project-root-regexps, and as far as I can tell they behave just as if they had a .projectile file at their root.

1

In that case, you can temporary disable projectile-require-project-root:

(setq projectile-require-project-root nil)

Then, you can activate Projectile everywhere.

  • I just tried this out, and it seems like it would only be useful in a flat directory structure. As soon as I open a file in src/ the project root changes to src/ and I can no longer jump to the files in inc/. – nispio Oct 31 '14 at 6:40
  • 2
    There's no way to interactively add to project list. But you may try manually adding a directory to projectile-known-projects. You could also look at this issue. Probably you should update the issue, so someone could add this feature. – Tu Do Oct 31 '14 at 6:44
  • Adding to projectile-known-projects suffered from the same subdirectory issue that I mentioned in my first comment. I did add a comment to the GitHub issue though, and I got a helpful response. – nispio Oct 31 '14 at 19:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.