Refactor core-projects; fix autoload-project-mode & doom-project-hook

+ doom-project can now be a symbol or list of project modes.
+ doom-project-hook hooks are promised to receive the mode symbol and
  state, but until now only received the former.
+ Add docstrings to doom-project-{find-file,browse}.
+ doom|autoload-project-mode is now on find-file-hook instead of
  after-change-major-mode (which fires it way too many times).
This commit is contained in:
Henrik Lissner
2017-12-31 11:21:53 -05:00
parent d9175748b7
commit 3e41c11138

View File

@ -1,10 +1,7 @@
;;; core-projects.el -*- lexical-binding: t; -*- ;;; core-projects.el -*- lexical-binding: t; -*-
(defvar doom-project-hook nil
"Hook run when a project is enabled. The name of the project's mode and its
state are passed in.")
(def-package! projectile (def-package! projectile
:hook (doom-init . projectile-mode)
:init :init
(setq projectile-cache-file (concat doom-cache-dir "projectile.cache") (setq projectile-cache-file (concat doom-cache-dir "projectile.cache")
projectile-enable-caching (not noninteractive) projectile-enable-caching (not noninteractive)
@ -14,9 +11,9 @@ state are passed in.")
projectile-globally-ignored-files '(".DS_Store" "Icon projectile-globally-ignored-files '(".DS_Store" "Icon
" "TAGS") " "TAGS")
projectile-globally-ignored-file-suffixes '(".elc" ".pyc" ".o")) projectile-globally-ignored-file-suffixes '(".elc" ".pyc" ".o"))
:config :config
(add-hook 'dired-before-readin-hook #'projectile-track-known-projects-find-file-hook)
(add-hook 'find-file-hook #'doom|autoload-project-mode) (add-hook 'find-file-hook #'doom|autoload-project-mode)
;; a more generic project root file ;; a more generic project root file
@ -79,7 +76,7 @@ they are absolute."
they are absolute." they are absolute."
(doom--resolve-path-forms files (doom-project-root))) (doom--resolve-path-forms files (doom-project-root)))
(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 ;; Necessary to isolate this search from the current project
@ -92,7 +89,7 @@ they are absolute."
(or (command-remapping #'projectile-find-file) (or (command-remapping #'projectile-find-file)
#'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."
(let ((default-directory dir)) (let ((default-directory dir))
(call-interactively (call-interactively
@ -105,15 +102,21 @@ they are absolute."
;; Projects ;; Projects
;; ;;
(defvar-local doom-project nil (defvar-local doom-project nil
"Either the symbol or a list of project modes you want to enable. Available
for .dir-locals.el.")
(defvar doom-project-hook nil
"Hook run when a project is enabled. The name of the project's mode and its
state are passed in.") state are passed in.")
(defun doom|autoload-project-mode () (defun doom|autoload-project-mode ()
"Auto-enable projects listed in `doom-project', which is meant to be set from "Auto-enable the project(s) listed in `doom-project'."
(when doom-project
(if (symbolp doom-project)
(funcall doom-project) (funcall doom-project)
(cl-loop for mode in doom-project (cl-loop for mode in doom-project
unless (symbol-value mode) unless (symbol-value mode)
do (funcall mode)))
do (funcall mode))))) do (funcall mode)))))
(defmacro def-project-mode! (name &rest plist) (defmacro def-project-mode! (name &rest plist)
@ -124,8 +127,7 @@ own settings, keymaps, hooks, snippets, etc.
own settings, keymaps, hooks, snippets, etc. own settings, keymaps, hooks, snippets, etc.
This creates NAME-hook and NAME-map as well. This creates NAME-hook and NAME-map as well.
A project can be enabled through .dir-locals.el too, if `doom-project' is set to
A project can be enabled through .dir-locals.el too, by setting `doom-project'. A project can be enabled through .dir-locals.el too, by setting `doom-project'.
PLIST may contain any of these properties, which are all checked to see if NAME PLIST may contain any of these properties, which are all checked to see if NAME
@ -174,7 +176,7 @@ Relevant: `doom-project-hook'."
:lighter "" :lighter ""
:keymap (make-sparse-keymap) :keymap (make-sparse-keymap)
(if (not ,name) (if (not ,name)
,exit-form ,exit-form
(run-hook-with-args 'doom-project-hook ',name ,name) (run-hook-with-args 'doom-project-hook ',name ,name)
,(when load-form ,(when load-form
`(unless ,init-var `(unless ,init-var