projectile icon indicating copy to clipboard operation
projectile copied to clipboard

Hook for project-changed

Open iced opened this issue 9 years ago • 18 comments

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?

iced avatar Mar 08 '16 19:03 iced

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)

markcol avatar Mar 30 '16 22:03 markcol

They trigger only if you switch project with projectile-switch-project.

iced avatar Apr 01 '16 13:04 iced

@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.

behaghel avatar Oct 02 '16 16:10 behaghel

Some basically this hook should fire when project files are written, right? Guess we can have a hook like this.

bbatsov avatar Oct 05 '16 16:10 bbatsov

Thank you, I hope this will be implemented soon, keep up great job you are doing.

BTW, any way to donate?

iced avatar Oct 17 '16 13:10 iced

+1

yauhen-l avatar Nov 28 '16 11:11 yauhen-l

+1

auvn avatar Dec 03 '16 11:12 auvn

@bbatsov Any news on this?

sergeyklay avatar Mar 13 '19 01:03 sergeyklay

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!

stale[bot] avatar May 08 '19 15:05 stale[bot]

This issue is still actual

sergeyklay avatar May 08 '19 18:05 sergeyklay

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!

stale[bot] avatar Aug 07 '19 01:08 stale[bot]

This issue is still actual

sergeyklay avatar Aug 07 '19 05:08 sergeyklay

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!

stale[bot] avatar Feb 03 '20 06:02 stale[bot]

This issue is still actual

sergeyklay avatar Feb 03 '20 07:02 sergeyklay

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!

stale[bot] avatar Aug 05 '20 23:08 stale[bot]

This issue is still actual

sergeyklay avatar Aug 06 '20 11:08 sergeyklay

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.

bbatsov avatar Dec 02 '20 15:12 bbatsov

Use cases I care about are:

  1. Run some external tool when I switch project (for ex. reindex project files, recompile tags, etc)
  2. Enable some subset of configuration\modes when I open the particular project
  3. Determine that I have changed the project when I open a file from another project and do 1 or 2
  4. I can either switch project or just close current and open a new one

sergeyklay avatar Dec 02 '20 19:12 sergeyklay