branch: elpa/projectile commit 7d5e81689566a507b5602c812426933a6481185c Author: Bozhidar Batsov <bozhi...@batsov.dev> Commit: Bozhidar Batsov <bozhi...@batsov.dev>
Speed-up load time by moving known projects initialization It's now done outside of `projectile-mode`'s init, which should make Projectile load faster. * As a side effect the known projects will be initialized properly even if you're not using `projectile-mode`. * The projects are read from disk the first time you invoke `projectile-switch-project` or a similar command. * We no longer do auto-cleanup of known projects when projectile-mode starts. I'll think about how to handle this in an efficient manner. --- CHANGELOG.md | 3 +++ projectile.el | 18 ++++++++++++------ test/projectile-test.el | 16 +++------------- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd9af9b57c..fdf7aeb612 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,9 @@ This makes caching both more robust and faster, as before the cache file for all projects was loaded when projectile-mode was enabled. +* Speed-up load time by moving known projects initialization outside of `projectile-mode`'s init. + * As a side effect the known projects will be initialized properly even if you're not using `projectile-mode`. + * The projects are read from disk the first time you invoke `projectile-switch-project` or a similar command. ## 2.8.0 (2023-10-13) diff --git a/projectile.el b/projectile.el index 7790f6f414..6e09c0ea7c 100644 --- a/projectile.el +++ b/projectile.el @@ -5528,8 +5528,20 @@ An open project is a project with any open buffers." (list (abbreviate-file-name project))) projects)) +(defun projectile--init-known-projects () + "Initialize the known projects. + +This might potentially clean up redundant projects +and discover new ones if `projectile-auto-discover' is enabled." + ;; load the known projects + (unless projectile-known-projects + (projectile-load-known-projects)) + (when projectile-auto-discover + (projectile-discover-projects-in-search-path))) + (defun projectile-relevant-known-projects () "Return a list of known projects." + (projectile--init-known-projects) (pcase projectile-current-project-on-switch ('remove (projectile--remove-current-project projectile-known-projects)) ('move-to-end (projectile--move-current-project-to-end projectile-known-projects)) @@ -6316,12 +6328,6 @@ Otherwise behave as if called interactively. (projectile-mode ;; setup the commander bindings (projectile-commander-bindings) - ;; load the known projects - (projectile-load-known-projects) - ;; update the list of known projects - (projectile--cleanup-known-projects) - (when projectile-auto-discover - (projectile-discover-projects-in-search-path)) (add-hook 'project-find-functions #'project-projectile) (add-hook 'find-file-hook 'projectile-find-file-hook-function) (add-hook 'projectile-find-dir-hook #'projectile-track-known-projects-find-file-hook t) diff --git a/test/projectile-test.el b/test/projectile-test.el index 7b40e15247..8c62a63acf 100644 --- a/test/projectile-test.el +++ b/test/projectile-test.el @@ -529,17 +529,7 @@ Just delegates OPERATION and ARGS for all operations except for`shell-command`'. (projectile-mode 1) (expect (memq 'projectile-find-file-hook-function find-file-hook) :to-be-truthy) (projectile-mode -1) - (expect (memq 'projectile-find-file-hook-function find-file-hook) :not :to-be-truthy)) - (it "respects projectile-auto-discover setting" - (unwind-protect - (progn - (let ((projectile-auto-discover nil)) - (projectile-mode 1) - (expect 'projectile-discover-projects-in-search-path :not :to-have-been-called)) - (let ((projectile-auto-discover t)) - (projectile-mode 1) - (expect 'projectile-discover-projects-in-search-path :to-have-been-called))) - (projectile-mode -1)))) + (expect (memq 'projectile-find-file-hook-function find-file-hook) :not :to-be-truthy))) (describe "projectile-relevant-known-projects" (it "returns a list of known projects" @@ -1039,8 +1029,8 @@ Just delegates OPERATION and ARGS for all operations except for`shell-command`'. (describe "projectile-switch-project" (it "fails if there are no projects" - (let ((projectile-known-projects nil)) - (expect (projectile-switch-project) :to-throw)))) + (spy-on 'projectile-relevant-known-projects :and-return-value nil) + (expect (projectile-switch-project) :to-throw))) (describe "projectile-delete-dir-local-variable" (it "Deletes existing dir-local variables"