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.
This commit is contained in:
Henrik Lissner 2018-08-03 16:10:20 +02:00
parent 31c8c0c033
commit 3673067736
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 19 additions and 1 deletions

View file

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

View file

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