Skip to content

Commit

Permalink
Unify modifications to find-file-hook
Browse files Browse the repository at this point in the history
projectile.el (projectile-find-file-hook-function): New defun. Call
nothing for remote files.

* projectile.el (projectile-mode): Don't set find-file-hook locally.

* test/projectile-test.el (projectile-test-setup-hook-functions-projectile-mode):
(projectile-test-setup-hook-functions-projectile-global-mode): Update tests.
  • Loading branch information
abo-abo authored and bbatsov committed Oct 5, 2016
1 parent 32caf86 commit ade3465
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
17 changes: 10 additions & 7 deletions projectile.el
Original file line number Diff line number Diff line change
Expand Up @@ -3306,6 +3306,13 @@ entirely."
:risky t
:package-version '(projectile "0.12.0"))

(defun projectile-find-file-hook-function ()
"Called by `find-file-hook' when `projectile-mode' is on."
(unless (file-remote-p default-directory)
(projectile-cache-files-find-file-hook)
(projectile-cache-projects-find-file-hook)
(projectile-visit-project-tags-table)))

;;;###autoload
(define-minor-mode projectile-mode
"Minor mode to assist project management and navigation.
Expand All @@ -3330,17 +3337,13 @@ Otherwise behave as if called interactively.
(setq projectile-projects-cache
(or (projectile-unserialize projectile-cache-file)
(make-hash-table :test 'equal))))
(add-hook 'find-file-hook #'projectile-cache-files-find-file-hook t t)
(add-hook 'find-file-hook #'projectile-cache-projects-find-file-hook t t)
(add-hook 'projectile-find-dir-hook #'projectile-cache-projects-find-file-hook)
(add-hook 'find-file-hook #'projectile-visit-project-tags-table t t)
(add-hook 'find-file-hook 'projectile-find-file-hook-function)
(add-hook 'projectile-find-dir-hook #'projectile-cache-projects-find-file-hook t)
(add-hook 'dired-before-readin-hook #'projectile-cache-projects-find-file-hook t t)
(ad-activate 'compilation-find-file)
(ad-activate 'delete-file))
(t
(remove-hook 'find-file-hook #'projectile-cache-files-find-file-hook t)
(remove-hook 'find-file-hook #'projectile-cache-projects-find-file-hook t)
(remove-hook 'find-file-hook #'projectile-visit-project-tags-table t)
(remove-hook 'find-file-hook #'projectile-find-file-hook-function)
(remove-hook 'dired-before-readin-hook #'projectile-cache-projects-find-file-hook t)
(ad-deactivate 'compilation-find-file)
(ad-deactivate 'delete-file))))
Expand Down
12 changes: 4 additions & 8 deletions test/projectile-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -195,19 +195,15 @@

(ert-deftest projectile-test-setup-hook-functions-projectile-mode ()
(projectile-mode 1)
(should (and (memq 'projectile-cache-files-find-file-hook find-file-hook)
(memq 'projectile-cache-projects-find-file-hook find-file-hook)))
(should (memq 'projectile-find-file-hook-function find-file-hook))
(projectile-mode -1)
(should (and (not (memq 'projectile-cache-files-find-file-hook find-file-hook))
(not (memq 'projectile-cache-projects-find-file-hook find-file-hook)))))
(should (not (memq 'projectile-find-file-hook-function find-file-hook))))

(ert-deftest projectile-test-setup-hook-functions-projectile-global-mode ()
(projectile-global-mode 1)
(should (and (memq 'projectile-cache-files-find-file-hook find-file-hook)
(memq 'projectile-cache-projects-find-file-hook find-file-hook)))
(should (memq 'projectile-find-file-hook-function find-file-hook))
(projectile-global-mode -1)
(should (and (not (memq 'projectile-cache-files-find-file-hook find-file-hook))
(not (memq 'projectile-cache-projects-find-file-hook find-file-hook)))))
(should (not (memq 'projectile-find-file-hook-function find-file-hook))))

(ert-deftest projectile-test-relevant-known-projects ()
(let ((projectile-known-projects '("/path/to/project1" "/path/to/project2")))
Expand Down

0 comments on commit ade3465

Please sign in to comment.