Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incrementally loading packages associated with a tag #2

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,9 @@ The function handles some built-in keywords of =use-package= to exclude packages
- Having an =:if= property that evaluates to nil.

Not all keywords are supported right now, but it can be extended to support more keywords.

This package also provides =use-package-tags-collect-tags= function, which returns a list of all tags in a source.
*** Loading packages by a tag
:PROPERTIES:
:CREATED_TIME: [2020-07-06 Mon 23:11]
:END:
Finally, this package allows you to incrementally load packages with a tag.
After you configure =use-package-tags-init-files= variable, =use-package-tags-load= command displays a list of tags that are not in the current profile (i.e. =use-package-tags-current-profile=) and loads all packages with a tag in the files.
7 changes: 7 additions & 0 deletions use-package-tags-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@
(expect (use-package-tags-collect-tags "./tests/init.el" :sort t)
:to-equal '(active bar foo inactive))))

(describe "use-package-tags-load"
(xit "loads packages with a tag and add the tag to the profile")
(xit "If an error occurs, don't add the tag to the profile"))

(describe "use-package-tags--unloaded-tags (private function)"
(xit "returns tags that are not in the profile"))

(describe "use-package-tags--source-buffer-list (private function)"
(describe "When t is given"
(if (file-exists-p (expand-file-name "init.el" user-emacs-directory))
Expand Down
41 changes: 40 additions & 1 deletion use-package-tags.el
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
NAME, _KEYWORD, TAGS, REST, and STATE are arguments that follow
the conventions of use-package."
(let ((body (use-package-process-keywords name rest state)))
(if tags
(if (and load-in-progress tags)
`((when (cl-intersection ,tags use-package-tags-current-profile)
,@body))
body)))
Expand Down Expand Up @@ -290,5 +290,44 @@ If SORT is non-nil, the result will be lexicographically sorted."
(cl-remove-duplicates)
(order)))))

(defun use-package-tags--unloaded-tags ()
"Return a list of tags that are not in the current profile."
(-difference (use-package-tags-collect-tags t :sort t)
use-package-tags-current-profile))

;;;###autoload
(defun use-package-tags-load (tag)
"Load packages with a TAG.

This function evalates `use-package' forms with the selected tag
in `use-package-tags-init-files'.

After successfully loading all matching packages, the tag will be
added to `use-package-tags-current-profile', without saving the value
to `custom-file'."
(interactive (list (completing-read "Load packages with tag: "
(use-package-tags--unloaded-tags)
nil 'match)))
(cl-labels
((get-keyword (prop rest) (-some->> (member prop rest)
(nth 1)))
(has-tag-p (tag rest)
(let ((tags (cdr (get-keyword :tags rest))))
(memq tag (cl-etypecase tags
(list tags)
(symbol (list tags)))))))
(setq tag (cl-etypecase tag
(tag tag)
(string (intern tag))))
(use-package-tags--with-package-forms
(use-package-tags--source-buffer-list t)
(let ((exp (read (current-buffer))))
(when (has-tag-p tag exp)
(message "Loading package %s configured at %s..."
(nth 1 exp)
(abbreviate-file-name (buffer-file-name)))
(eval exp))))
(push tag use-package-tags-current-profile)))

(provide 'use-package-tags)
;;; use-package-tags.el ends here