Refactor +ivy/projectile-find-file to use counsel

counsel-projectile-find-file has other capabilities (like actions and
sorting). So we conditionally use projectile-find-file only if the
project is large enough to warrant it.
This commit is contained in:
Henrik Lissner 2018-08-04 02:28:45 +02:00
parent 316a9f06b2
commit c878314aa6
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -210,20 +210,25 @@ search current file. See `+ivy-task-tags' to customize what this searches for."
;;;###autoload ;;;###autoload
(defun +ivy/projectile-find-file () (defun +ivy/projectile-find-file ()
"A more sensible `projectile-find-file', which will revert to "A more sensible `counsel-projectile-find-file', which will revert to
`counsel-find-file' if invoked from $HOME (usually not what you want), or `counsel-find-file' if invoked from $HOME, `counsel-file-jump' if invoked from a
`counsel-file-jump' if invoked from a non-project. non-project, `projectile-find-file' if in a bug project (more than
`ivy-sort-max-size' files), or `counsel-projectile-find-file' otherwise.
Both are much faster than letting `projectile-find-file' index massive file The point of this is to avoid Emacs locking up indexing massive file trees."
trees."
(interactive) (interactive)
(call-interactively (call-interactively
(cond ((or (file-equal-p default-directory "~") (cond ((or (file-equal-p default-directory "~")
(when-let* ((proot (doom-project-root 'nocache))) (when-let* ((proot (doom-project-root 'nocache)))
(file-equal-p proot "~"))) (file-equal-p proot "~")))
#'counsel-find-file) #'counsel-find-file)
((doom-project-p 'nocache) ((doom-project-p 'nocache)
#'projectile-find-file) (let ((files (projectile-current-project-files)))
(if (<= (length files) ivy-sort-max-size)
#'counsel-projectile-find-file
#'projectile-find-file)))
(#'counsel-file-jump)))) (#'counsel-file-jump))))
;;;###autoload ;;;###autoload