Add nocache arg to doom-project-* functions

This commit is contained in:
Henrik Lissner 2018-02-01 01:31:26 -05:00
parent 2ab0072d83
commit 7e31d1c5af
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -50,6 +50,15 @@
;; Library ;; Library
;; ;;
(defmacro without-project-cache! (&rest body)
"Run BODY with projectile's project-root cache disabled. This is necessary if
you want to interactive with a project other than the one you're in."
`(let (projectile-project-name
projectile-require-project-root
projectile-cached-buffer-file-name
projectile-cached-project-root)
,@body))
(defun doom//reload-project () (defun doom//reload-project ()
"Reload the project root cache." "Reload the project root cache."
(interactive) (interactive)
@ -58,17 +67,21 @@
(dolist (fn projectile-project-root-files-functions) (dolist (fn projectile-project-root-files-functions)
(remhash (format "%s-%s" fn default-directory) projectile-project-root-cache))) (remhash (format "%s-%s" fn default-directory) projectile-project-root-cache)))
(defun doom-project-p () (defun doom-project-p (&optional nocache)
"Whether or not this buffer is currently in a project or not." "Whether or not this buffer is currently in a project or not."
(let ((projectile-require-project-root t)) (if nocache
(projectile-project-p))) (without-project-cache! (doom-project-p nil))
(let ((projectile-require-project-root t))
(projectile-project-p))))
(defun doom-project-root () (defun doom-project-root (&optional nocache)
"Get the path to the root of your project. "Get the path to the root of your project.
If STRICT-P, return nil if no project was found, otherwise return If STRICT-P, return nil if no project was found, otherwise return
`default-directory'." `default-directory'."
(let (projectile-require-project-root) (if nocache
(projectile-project-root))) (without-project-cache! (doom-project-root nil))
(let (projectile-require-project-root)
(projectile-project-root))))
(defalias 'doom-project-expand #'projectile-expand-root) (defalias 'doom-project-expand #'projectile-expand-root)
@ -81,16 +94,12 @@ they are absolute."
(defun doom-project-find-file (dir) (defun doom-project-find-file (dir)
"Fuzzy-find a file under DIR." "Fuzzy-find a file under DIR."
(let ((default-directory dir) (let ((default-directory dir))
;; Necessary to isolate this search from the current project (without-project-cache!
projectile-project-name (call-interactively
projectile-require-project-root ;; completion modules may remap this command
projectile-cached-buffer-file-name (or (command-remapping #'projectile-find-file)
projectile-cached-project-root) #'projectile-find-file)))))
(call-interactively
;; completion modules may remap this command
(or (command-remapping #'projectile-find-file)
#'projectile-find-file))))
(defun doom-project-browse (dir) (defun doom-project-browse (dir)
"Traverse a file structure starting linearly from DIR." "Traverse a file structure starting linearly from DIR."