5

I want that when I choose a project from the list presented by projectile-switch-project, projectile changes the current working directory to the chosen project's root directory.

I tried this:

;; cd into dir i want, including git-root
  (defun cd-dwim ()
      (cd (projectile-project-root)))
  (setq projectile-switch-project-action 'cd-dwim)

Did not work. It projectile-project-root does not receive the new path from the project I just chose.

I'd love if I was able to write something like this:

(setq projectile-switch-project-action 
'projectile-get-the-root-directory-of-the-project-I-just-chose)

Is it possible?

ninrod
  • 1,506
  • 2
  • 13
  • 29
  • When you say 'changes the current working directory', what do you want to do with it? open it with dired? cd changes the current buffer's working directory. – omajid Nov 18 '16 at 20:45
  • I just want that after I invoke projectile-switch-project and chose a project, a later invocation of M-x projectile-find-file will search files inside the root directory of the project I just chose. – ninrod Nov 18 '16 at 21:25
  • @ninrod It should work as you described without any config. – Saddle Point Nov 18 '16 at 23:38
  • @displayname actually without any config, after choosing a project, projectile immediately forces me to chose a file from all the files in the project. If I don't choose a file, then projectile does not switch to the project that I want. – ninrod Nov 19 '16 at 00:56
  • @ninrod Sorry I misunderstood your needs. I don't know that you even don't want to open a file in project. You should set it to projectile-dired. Or just use the default binding C-c p D. – Saddle Point Nov 19 '16 at 03:33
  • @ninrod I guess I misunderstood again. If you don't even want to leave current buffer, you will need to change default-directory which is a buffer local variable. I don't thinks it's a good idea to do so. – Saddle Point Nov 19 '16 at 03:38
  • Yeah I think that I'll have to get used to the default behaviour. thanks. – ninrod Nov 20 '16 at 13:56

1 Answers1

5

The default action is projectile-find-file. Change it to projectile-dired, and whenever you switch project, you get into a dired buffer of the root of that project:

(setq projectile-switch-project-action 'projectile-dired)
Tu Do
  • 6,812
  • 21
  • 39