Hook for project-changed
I need to do some work when project is changed - no matter how (sometimes I open files directly or for first time) and it seems impossible now. Can we have it?
There are two hooks that can be used for this purpose: projectile-before-switch-project-hook and projectile-after-switch-project-hook. They are run before and after switching to a new project, respectively.
To take some action after the project has changed, add something like the following to your .emacs:
(defun my-switch-project-hook ()
"Perform some action after switching Projectile projects."
(message "Project changed...")
;; Do something interesting here...
;;
;; `projectile-current-project-files', and `projectile-current-project-dirs' can be used
;; to get access to the new project's files, and directories.
)
(add-hook 'projectile-after-switch-project-hook #'my-switch-project-hook)
They trigger only if you switch project with projectile-switch-project.
@markcol As far as I can tell you cannot access projectile-current-project-files in such a hook because (error "You're not in a project"). Let me know if you need more details / separate issue.
Some basically this hook should fire when project files are written, right? Guess we can have a hook like this.
Thank you, I hope this will be implemented soon, keep up great job you are doing.
BTW, any way to donate?
+1
+1
@bbatsov Any news on this?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding!
This issue is still actual
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding!
This issue is still actual
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding!
This issue is still actual
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding!
This issue is still actual
The reason why I haven't implemented this yet is simple - it's trivial to have the hook be triggered when writing files from Emacs, but it's more involved to trigger it on external file changes (as for those we'll have to listen to filesystem notifications and filter them by for the current project). It'd be good to agree what are the cases we care about.
Use cases I care about are:
- Run some external tool when I switch project (for ex. reindex project files, recompile tags, etc)
- Enable some subset of configuration\modes when I open the particular project
- Determine that I have changed the project when I open a file from another project and do 1 or 2
- I can either switch project or just close current and open a new one