Refactor Project API to reflect changes upstream

projectile-project-root no longer returns `default-directory` if not in
a project (it returns nil). As such, doom-project-* functions (and their
uses) have been refactored.

+ doom-project-p & doom-project-root are aliases for
  projectile-project-p & projectile-project-root.
+ doom-project-{p,root,name,expand} now has a DIR argument (for
  consistency, since projectile-project-name and
  projectile-project-expand do not).
+ The nocache parameter is no longer necessary, as projectile's caching
  behavior is now more sane.
+ Removed some projectile advice/hacks that are no longer necessary.
+ Updated unit tests
This commit is contained in:
Henrik Lissner 2018-09-28 13:54:20 -04:00
parent 3961ba1662
commit 53fe7a1f04
22 changed files with 53 additions and 84 deletions

View file

@ -13,7 +13,7 @@
(interactive)
(call-interactively
(if (or (file-equal-p default-directory "~")
(when-let* ((proot (doom-project-root 'nocache)))
(when-let* ((proot (doom-project-root)))
(file-equal-p proot "~")))
#'helm-find-files
#'helm-projectile-find-file)))

View file

@ -217,11 +217,11 @@ The point of this is to avoid Emacs locking up indexing massive file trees."
(interactive)
(call-interactively
(cond ((or (file-equal-p default-directory "~")
(when-let* ((proot (doom-project-root 'nocache)))
(when-let* ((proot (doom-project-root)))
(file-equal-p proot "~")))
#'counsel-find-file)
((doom-project-p 'nocache)
((doom-project-p)
(let ((files (projectile-current-project-files)))
(if (<= (length files) ivy-sort-max-size)
#'counsel-projectile-find-file

View file

@ -3,9 +3,7 @@
;;;###autoload
(defun eshell/cd-to-project ()
"Change to the project root of the current directory."
(let* ((default-directory (eshell/pwd))
(project-root (doom-project-root 'nocache)))
(eshell/cd project-root)))
(eshell/cd (doom-project-root (eshell/pwd))))
;;;###autoload
(defun eshell/quit-and-close (&rest _)

View file

@ -7,7 +7,7 @@ non-nil, cd into the current project's root."
(interactive "P")
(let ((default-directory
(if arg
(doom-project-root 'nocache)
(or (doom-project-root) default-directory)
default-directory)))
;; Doom's switch-buffer hooks prevent themselves from triggering when
;; switching from buffer A back to A. Because `multi-term' uses `set-buffer'
@ -22,7 +22,7 @@ non-nil, cd into the current project's root."
(interactive "P")
(let ((default-directory
(if arg
(doom-project-root 'nocache)
(or (doom-project-root) default-directory)
default-directory)))
(pop-to-buffer (save-window-excursion (multi-term)))))

View file

@ -11,7 +11,7 @@
(unless (buffer-live-p buffer)
(remhash key +eval-repl-buffers)))
+eval-repl-buffers)
(let* ((project-root (doom-project-root 'nocache))
(let* ((project-root (doom-project-root))
(key (cons major-mode project-root))
(buffer (gethash key +eval-repl-buffers)))
(cl-check-type buffer (or buffer null))

View file

@ -288,7 +288,7 @@ Otherwise, falls back on `find-file-at-point'."
(when (and buffer-file-name (file-equal-p fullpath buffer-file-name))
(user-error "Already here"))
(let* ((insert-default-directory t)
(project-root (doom-project-root 'nocache))
(project-root (doom-project-root))
(ffap-file-finder
(cond ((not (file-directory-p fullpath))
#'find-file)

View file

@ -104,7 +104,7 @@ preceded by the opening brace or a comma (disregarding whitespace in between)."
(executable-find "rc"))
(with-temp-buffer
(message "Reloaded compile commands for rtags daemon")
(rtags-call-rc :silent t "-J" (doom-project-root))))
(rtags-call-rc :silent t "-J" (or (doom-project-root) default-directory))))
;; then irony
(when (and (featurep 'irony) irony-mode)
(+cc|irony-init-compile-options)))

View file

@ -82,7 +82,7 @@ you're done. This can be called from an external shell script."
filename
(or (locate-dominating-file (file-truename default-directory)
filename)
(if (doom-project-p 'nocache) (doom-project-root 'nocache))
(doom-project-root)
(user-error "Couldn't detect a project")))))
;;;###autoload

View file

@ -49,7 +49,8 @@
(setq phpactor-working-dir
(or phpactor-working-dir
(php-project-get-root-dir)
(doom-project-root))))
(doom-project-root)
default-directory)))
(advice-add #'phpactor-get-working-dir :before #'+php*project-root)
(map! :map php-mode-map

View file

@ -38,7 +38,7 @@ started it."
(puthash proot
(+python--extract-version "Pipenv " v)
+python-version-cache))
(puthash (doom-project-root)
(puthash (or (doom-project-root) default-directory)
(+python--extract-version "Python " (car (process-lines "python" "--version")))
+python-version-cache))
(error "Python")))
@ -53,7 +53,8 @@ started it."
(setq +python--version
(or (gethash (or (and (fboundp 'pipenv-project-p)
(pipenv-project-p))
(doom-project-root))
(doom-project-root)
default-directory)
+python-version-cache)
(+python-version))))

View file

@ -27,7 +27,7 @@ pipenv, unless those tools have modified the PATH that Emacs picked up when you
started it."
(condition-case _
(let ((version-str (car (process-lines "ruby" "--version"))))
(puthash (doom-project-root)
(puthash (or (doom-project-root) default-directory)
(format "Ruby %s" (cadr (split-string version-str " ")))
+ruby-version-cache))
(error "Ruby")))
@ -40,7 +40,8 @@ started it."
(defun +ruby|update-version (&rest _)
"Update `+ruby--version' by consulting `+ruby-version' function."
(setq +ruby--version
(or (gethash (doom-project-root) +python-version-cache)
(or (gethash (or (doom-project-root) default-directory)
+python-version-cache)
(+ruby-version))))
;;;###autoload

View file

@ -31,7 +31,8 @@
(+macos!open-with reveal-in-finder "Finder" default-directory)
;;;###autoload (autoload '+macos/reveal-project-in-finder "tools/macos/autoload" nil t)
(+macos!open-with reveal-project-in-finder "Finder" (doom-project-root))
(+macos!open-with reveal-project-in-finder "Finder"
(or (doom-project-root) default-directory))
;;;###autoload (autoload '+macos/send-to-transmit "tools/macos/autoload" nil t)
(+macos!open-with send-to-transmit "Transmit")
@ -43,4 +44,5 @@
(+macos!open-with send-to-launchbar "LaunchBar")
;;;###autoload (autoload '+macos/send-project-to-launchbar "tools/macos/autoload" nil t)
(+macos!open-with send-project-to-launchbar "LaunchBar" (doom-project-root))
(+macos!open-with send-project-to-launchbar "LaunchBar"
(or (doom-project-root) default-directory))

View file

@ -7,7 +7,7 @@
"Run a make task in the current project. If multiple makefiles are available,
you'll be prompted to select one."
(interactive)
(if (doom-project-p 'nocache)
(if (doom-project-p)
(makefile-executor-execute-project-target)
(let ((makefile (cl-loop with buffer-file = (or buffer-file-name default-directory)
for file in (list "Makefile" "makefile")

View file

@ -44,7 +44,7 @@
(defun +prodigy*services (orig-fn &rest args)
"Adds a new :project property to prodigy services, which hides the service
unless invoked from the relevant project."
(let ((project-root (downcase (doom-project-root)))
(let ((project-root (downcase (or (doom-project-root) default-directory)))
(services (apply orig-fn args)))
(if current-prefix-arg
services

View file

@ -314,7 +314,7 @@ e.g. ~/w/project/src/lib/file.c
Meant for `+modeline-buffer-path-function'."
(pcase-let
((`(,root-parent ,root ,dir, file)
(shrink-path-file-mixed (doom-project-root)
(shrink-path-file-mixed (or (doom-project-root) default-directory)
(file-name-directory buffer-file-name)
buffer-file-name)))
(list (cons root-parent 'font-lock-comment-face)

View file

@ -8,7 +8,7 @@
(defun +neotree/open ()
"Open the neotree window in the current project."
(interactive)
(let ((project-root (doom-project-root 'nocache)))
(let ((project-root (doom-project-root)))
(require 'neotree)
(if (neo-global--window-exists-p)
(neotree-hide)
@ -19,7 +19,7 @@
"Open the neotree window in the current project, and find the current file."
(interactive)
(let ((path buffer-file-name)
(project-root (doom-project-root 'nocache)))
(project-root (doom-project-root)))
(require 'neotree)
(cond ((and (neo-global--window-exists-p)
(get-buffer-window neo-buffer-name t))

View file

@ -10,8 +10,8 @@
(treemacs-do-remove-project-from-workspace project))
(with-current-buffer origin-buffer
(treemacs-do-add-project-to-workspace
(treemacs--canonical-path (doom-project-root 'nocache))
(doom-project-name 'nocache))
(treemacs--canonical-path (doom-project-root))
(doom-project-name))
(setq treemacs--ready-to-follow t)
(when (or treemacs-follow-after-init treemacs-follow-mode)
(treemacs--follow)))))