From 36730677369b214ec47b2f6852e65f252751fff2 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Fri, 3 Aug 2018 16:10:20 +0200 Subject: [PATCH] Fix projectile-find-file locking up Emacs This occurs when invoking it from the root of massive file trees, like $HOME or certain non-project folders. It's better that it defer to a different command altogether (counsel-find-file) if invoked from $HOME, and counsel-file-jump from anywhere else, which offers approximately what we want, but at a fraction of the performance cost in those cases. --- modules/completion/ivy/autoload/ivy.el | 18 ++++++++++++++++++ modules/completion/ivy/config.el | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/modules/completion/ivy/autoload/ivy.el b/modules/completion/ivy/autoload/ivy.el index 01b59253b..5d666cdac 100644 --- a/modules/completion/ivy/autoload/ivy.el +++ b/modules/completion/ivy/autoload/ivy.el @@ -208,6 +208,24 @@ search current file. See `+ivy-task-tags' to customize what this searches for." ;; File searching ;; +;;;###autoload +(defun +ivy/projectile-find-file () + "A more sensible `projectile-find-file', which will revert to +`counsel-find-file' if invoked from $HOME (usually not what you want), or +`counsel-file-jump' if invoked from a non-project. + +Both are much faster than letting `projectile-find-file' index massive file +trees." + (interactive) + (call-interactively + (cond ((or (file-equal-p default-directory "~") + (when-let* ((proot (doom-project-root 'nocache))) + (file-equal-p proot "~"))) + #'counsel-find-file) + ((doom-project-p 'nocache) + #'projectile-find-file) + (#'counsel-file-jump)))) + ;;;###autoload (cl-defun +ivy-file-search (engine &key query in all-files (recursive t)) "Conduct a file search using ENGINE, which can be any of: rg, ag, pt, and diff --git a/modules/completion/ivy/config.el b/modules/completion/ivy/config.el index 94a275a78..aedfd1bd3 100644 --- a/modules/completion/ivy/config.el +++ b/modules/completion/ivy/config.el @@ -159,7 +159,7 @@ immediately runs it on the current candidate (ending the ivy session)." counsel-projectile-grep counsel-projectile-ag counsel-projectile-switch-project) :init (define-key! 'global - [remap projectile-find-file] #'counsel-projectile-find-file + [remap projectile-find-file] #'+ivy/projectile-find-file [remap projectile-find-dir] #'counsel-projectile-find-dir [remap projectile-switch-to-buffer] #'counsel-projectile-switch-to-buffer [remap projectile-grep] #'counsel-projectile-grep