Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making the projectile-add-known-project interactive #364

Closed
llacom opened this issue Jun 12, 2014 · 6 comments
Closed

Making the projectile-add-known-project interactive #364

llacom opened this issue Jun 12, 2014 · 6 comments

Comments

@llacom
Copy link

llacom commented Jun 12, 2014

You can remove projects with "M-x projectile-remove-known-project" but as far as I know the only way to add a project to known projects is by a hook in find-file functions.

Is it possible to make the function interactive ?

@bbatsov
Copy link
Owner

bbatsov commented Jun 14, 2014

Why would you want to add a project manually? Opening a file in the project's dir is pretty much the same as interactively adding the project, so it doesn't make a lot of sense to me.

@llacom
Copy link
Author

llacom commented Jun 18, 2014

I had accidentally removed a project from the list of known projects and was confused as how to add it again.
I opened the project directory in dired but the project wasn't added to known_projects and I didn't know why. It didn't occur to me to open a file in the project until I read projectile.el.

It may also confuse other people that don't systematically open a file but the project root directory.

Making the function interactive would help this (the first thing I did was list all the projectile functions, and I found how to remove a project but not how to add it). Or maybe instead hooking the jump-dired function.

@thomasf
Copy link
Contributor

thomasf commented Sep 8, 2014

This is a function that lets me ensure that a bunch of directories are known projects.

  (defun projectile-add-magit-repo-dirs-to-known-projects ()
      "Add `magit-repo-dirs' to `projectile-known-projects'."
      (interactive)
      (--each (mapcar 'cdr (magit-list-repos magit-repo-dirs))
        (projectile-add-known-project (file-name-as-directory
                                       (file-truename it)))))

Since it is currenlty using magit it is for git repositoreies only.

These are the customizations:

(defcustom magit-repo-dirs nil
  "Directories containing Git repositories.
Magit will look into these directories for Git repositories and
offer them as choices for `magit-status'."
  :group 'magit
  :type '(repeat string))

(defcustom magit-repo-dirs-depth 3
  "The maximum depth to look for Git repos.
When looking for a Git repository below the directories in
`magit-repo-dirs', Magit will only descend this many levels
deep."
  :group 'magit
  :type 'integer)

Not what you asked for but it solves the same problem you are describing for me. That sometimes a folder that should always be in the known projects isnt there.

@nispio
Copy link

nispio commented Oct 31, 2014

At work I have projects to which I have read-only access. I would like to be able to browse those projects using projectile. However, the projects do not have a .git or .projectile or any other type of marker to indicate the root of the project. Since I am not allowed to add such a file to the directory tree, it would be useful to be able to have an interactive method of manually adding a project.

@thomasf
Copy link
Contributor

thomasf commented Oct 31, 2014

You can create functions and add them to projectile-project-root-files-functions..

I have something along the lines of what you are asking for in my init.el.. It allows for regular expressions to be used.. In my case to allow python virtual environments in ~/.virtualenvs/ to be identified as projects.

 (setq projectile-project-root-files-child-of
          '("~/\.virtualenvs/[^/]+/\\(local/\\)?lib/python[^/]*/site-packages/?$"
            "~/\.virtualenvs/[^/]+/?$"))

   (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 projectile-project-root-files-child-of (list))))))

(setq projectile-project-root-files-functions
     '(projectile-root-bottom-up
       projectile-root-top-down
       projectile-root-top-down-recurring
       projectile-root-child-of))

@nispio
Copy link

nispio commented Oct 31, 2014

@thomasf That works great, thank you. I copied your code as an answer to my question on Emacs.SE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants