From 0efac68c82d8ebdb3fd83ea5e530c4b816c87f8f Mon Sep 17 00:00:00 2001 From: Bozhidar Batsov Date: Mon, 3 Feb 2025 20:52:47 +0200 Subject: Use an idle timer in projectile-cache-current-file This prevents freezes when creating new files, as the function is triggered by find-file-hook. --- projectile.el | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/projectile.el b/projectile.el index 1962fb0..1f8f6c2 100644 --- a/projectile.el +++ b/projectile.el @@ -1166,9 +1166,15 @@ The cache is created both in memory and on the hard drive." (unless (or (projectile-file-cached-p current-file current-project) (projectile-ignored-directory-p (file-name-directory abs-current-file)) (projectile-ignored-file-p abs-current-file)) - (let ((project-files (cons current-file (gethash current-project projectile-projects-cache)))) + (let ((project-files (cons current-file (gethash current-project projectile-projects-cache))) + (cache-file (projectile-project-cache-file current-project))) (puthash current-project project-files projectile-projects-cache) - (projectile-serialize project-files (projectile-project-cache-file current-project))) + ;; we serialize the cache with an idle time to avoid freezing the UI + ;; immediately after the new file was created + (run-with-idle-timer + 30 + nil + 'projectile-serialize project-files cache-file)) (message "File %s added to project %s cache." (propertize current-file 'face 'font-lock-keyword-face) (propertize current-project 'face 'font-lock-keyword-face))))))) -- cgit v1.0