From 99c26e2fc25e17a130afd257c015fe56b412717b Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Fri, 19 Apr 2019 17:30:47 -0400 Subject: [PATCH] Allow doom-project-find-file on arbitrary paths - If DIR is not in a valid project, index it as normal and do projectile-find-file from current directory (but do not cache). - If DIR is a valid project, but not the project root, fall back to different mechanism for exploring it (project-find-file, counsel-file-jump, or find-file). - If DIR is a valid project AND is the project root, use projectile-find-file as normal. This is to make doom-project-find-file more do-what-I-mean. --- core/autoload/projects.el | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/core/autoload/projects.el b/core/autoload/projects.el index b1d5a3ab2..a27778ec1 100644 --- a/core/autoload/projects.el +++ b/core/autoload/projects.el @@ -88,22 +88,32 @@ Returns '-' if not in a valid project." ;;;###autoload (defun doom-project-find-file (dir) - "Fuzzy-find a file under DIR. + "Jump to a file in DIR (searched recursively). -Will resolve to the nearest project root above DIR. If no project can be found, -the search will be rooted from DIR." +If DIR is not a project, it will be indexed (but not cached)." (unless (file-directory-p dir) (error "Directory %S does not exist" dir)) - (let ((default-directory (file-truename (expand-file-name dir))) - (projectile-project-root - (or (doom-project-root dir) - default-directory))) - (call-interactively - ;; Intentionally avoid `helm-projectile-find-file', because it runs - ;; asynchronously, and thus doesn't see the lexical `default-directory' - (if (featurep! :completion ivy) - #'counsel-projectile-find-file - #'projectile-find-file)))) + (let* ((default-directory (file-truename (expand-file-name dir))) + (project-root (doom-project-root default-directory)) + (projectile-project-root default-directory) + (projectile-enable-caching projectile-enable-caching)) + (cond ((and project-root (file-equal-p project-root projectile-project-root)) + (unless (doom-project-p projectile-project-root) + ;; Disable caching if this is not a real project; caching + ;; non-projects easily has the potential to inflate the projectile + ;; cache beyond reason. + (setq projectile-enable-caching nil)) + (call-interactively + ;; Intentionally avoid `helm-projectile-find-file', because it runs + ;; asynchronously, and thus doesn't see the lexical `default-directory' + (if (featurep! :completion ivy) + #'counsel-projectile-find-file + #'projectile-find-file))) + ((fboundp 'project-find-file-in) ; emacs 26.1+ only + (project-find-file-in nil (list default-directory) nil)) + ((fboundp 'counsel-file-jump) ; ivy only + (call-interactively #'counsel-file-jump)) + ((call-interactively #'find-file))))) ;;;###autoload (defun doom-project-browse (dir)