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.
This commit is contained in:
parent
79ee09d65b
commit
99c26e2fc2
1 changed files with 23 additions and 13 deletions
|
@ -88,22 +88,32 @@ Returns '-' if not in a valid project."
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom-project-find-file (dir)
|
(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,
|
If DIR is not a project, it will be indexed (but not cached)."
|
||||||
the search will be rooted from DIR."
|
|
||||||
(unless (file-directory-p dir)
|
(unless (file-directory-p dir)
|
||||||
(error "Directory %S does not exist" dir))
|
(error "Directory %S does not exist" dir))
|
||||||
(let ((default-directory (file-truename (expand-file-name dir)))
|
(let* ((default-directory (file-truename (expand-file-name dir)))
|
||||||
(projectile-project-root
|
(project-root (doom-project-root default-directory))
|
||||||
(or (doom-project-root dir)
|
(projectile-project-root default-directory)
|
||||||
default-directory)))
|
(projectile-enable-caching projectile-enable-caching))
|
||||||
(call-interactively
|
(cond ((and project-root (file-equal-p project-root projectile-project-root))
|
||||||
;; Intentionally avoid `helm-projectile-find-file', because it runs
|
(unless (doom-project-p projectile-project-root)
|
||||||
;; asynchronously, and thus doesn't see the lexical `default-directory'
|
;; Disable caching if this is not a real project; caching
|
||||||
(if (featurep! :completion ivy)
|
;; non-projects easily has the potential to inflate the projectile
|
||||||
#'counsel-projectile-find-file
|
;; cache beyond reason.
|
||||||
#'projectile-find-file))))
|
(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
|
;;;###autoload
|
||||||
(defun doom-project-browse (dir)
|
(defun doom-project-browse (dir)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue