2018-06-16 11:42:37 +02:00
|
|
|
;;; core/autoload/projects.el -*- lexical-binding: t; -*-
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; Macros
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(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."
|
2018-09-22 12:42:38 -04:00
|
|
|
`(let ((projectile-project-root-cache (make-hash-table :test 'equal))
|
|
|
|
projectile-project-name
|
|
|
|
projectile-require-project-root)
|
2018-06-16 11:42:37 +02:00
|
|
|
,@body))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defmacro project-file-exists-p! (files)
|
|
|
|
"Checks if the project has the specified FILES.
|
|
|
|
Paths are relative to the project root, unless they start with ./ or ../ (in
|
|
|
|
which case they're relative to `default-directory'). If they start with a slash,
|
|
|
|
they are absolute."
|
|
|
|
`(file-exists-p! ,files (doom-project-root)))
|
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; Commands
|
|
|
|
|
|
|
|
;;;###autoload
|
2018-08-11 21:45:53 +02:00
|
|
|
(defun doom/reload-project ()
|
2018-06-16 11:42:37 +02:00
|
|
|
"Reload the project root cache."
|
|
|
|
(interactive)
|
|
|
|
(projectile-invalidate-cache nil)
|
|
|
|
(projectile-reset-cached-project-root)
|
|
|
|
(dolist (fn projectile-project-root-files-functions)
|
|
|
|
(remhash (format "%s-%s" fn default-directory) projectile-project-root-cache)))
|
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; Library
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun doom-project-p (&optional nocache)
|
|
|
|
"Return t if this buffer is currently in a project.
|
|
|
|
If NOCACHE, don't fetch a cached answer."
|
|
|
|
(if nocache
|
|
|
|
(without-project-cache! (doom-project-p nil))
|
|
|
|
(let ((projectile-require-project-root t))
|
|
|
|
(and (projectile-project-p) t))))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun doom-project-name (&optional nocache)
|
|
|
|
"Return the name of the current project.
|
|
|
|
If NOCACHE, don't fetch a cached answer."
|
|
|
|
(if nocache
|
|
|
|
(without-project-cache! (doom-project-name nil))
|
|
|
|
(projectile-project-name)))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun doom-project-root (&optional nocache)
|
|
|
|
"Returns the root of your project, or `default-directory' if none was found.
|
|
|
|
If NOCACHE, don't fetch a cached answer."
|
|
|
|
(if nocache
|
|
|
|
(without-project-cache! (doom-project-root nil))
|
|
|
|
(let (projectile-require-project-root)
|
2018-09-22 11:54:08 -04:00
|
|
|
;; NOTE `projectile-project-root' should return default-directory if we're
|
|
|
|
;; not in a project. Seems to be a bug upstream.
|
|
|
|
(or (projectile-project-root)
|
|
|
|
default-directory))))
|
2018-06-16 11:42:37 +02:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defalias 'doom-project-expand #'projectile-expand-root)
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun doom-project-find-file (dir)
|
|
|
|
"Fuzzy-find a file under DIR."
|
2018-08-26 12:00:13 +02:00
|
|
|
(without-project-cache!
|
2018-09-04 01:01:54 +02:00
|
|
|
(let* ((default-directory (file-truename dir))
|
|
|
|
(projectile-project-root default-directory))
|
2018-06-16 11:42:37 +02:00
|
|
|
(call-interactively
|
|
|
|
;; completion modules may remap this command
|
|
|
|
(or (command-remapping #'projectile-find-file)
|
|
|
|
#'projectile-find-file)))))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun doom-project-browse (dir)
|
|
|
|
"Traverse a file structure starting linearly from DIR."
|
2018-09-04 01:01:54 +02:00
|
|
|
(let ((default-directory (file-truename dir)))
|
2018-06-16 11:42:37 +02:00
|
|
|
(call-interactively
|
|
|
|
;; completion modules may remap this command
|
|
|
|
(or (command-remapping #'find-file)
|
|
|
|
#'find-file))))
|