From 38ca1ca0aff16d9d8d51be905a0a5f89208182fc Mon Sep 17 00:00:00 2001 From: Akira Komamura Date: Mon, 6 Jul 2020 23:08:03 +0900 Subject: [PATCH 1/3] Add use-package-tags-load function --- use-package-tags-test.el | 7 +++++++ use-package-tags.el | 44 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/use-package-tags-test.el b/use-package-tags-test.el index 33deefa..5ef4aa5 100644 --- a/use-package-tags-test.el +++ b/use-package-tags-test.el @@ -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)) diff --git a/use-package-tags.el b/use-package-tags.el index b99d2c3..06ecffd 100644 --- a/use-package-tags.el +++ b/use-package-tags.el @@ -290,5 +290,49 @@ 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)))) + (push tag use-package-tags-current-profile) + (condition-case err + (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)))) + (error (progn + (message "Error while loading the package: %s" err) + (cl-delete tag use-package-tags-current-profile) + (error err)))))) + (provide 'use-package-tags) ;;; use-package-tags.el ends here From d488f31df07cbce187b26fbf15861924cb8985d2 Mon Sep 17 00:00:00 2001 From: Akira Komamura Date: Mon, 6 Jul 2020 23:16:28 +0900 Subject: [PATCH 2/3] Docs: Document on use-package-tags-load command --- README.org | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.org b/README.org index 09e6809..b986b43 100644 --- a/README.org +++ b/README.org @@ -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. From 2f170e2331e06003676ed34354f624a335ee0ff9 Mon Sep 17 00:00:00 2001 From: Akira Komamura Date: Tue, 7 Jul 2020 21:44:31 +0900 Subject: [PATCH 3/3] Load packages unconditionally when evaluating use-package --- use-package-tags.el | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/use-package-tags.el b/use-package-tags.el index 06ecffd..13d1422 100644 --- a/use-package-tags.el +++ b/use-package-tags.el @@ -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))) @@ -319,20 +319,15 @@ to `custom-file'." (setq tag (cl-etypecase tag (tag tag) (string (intern tag)))) - (push tag use-package-tags-current-profile) - (condition-case err - (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)))) - (error (progn - (message "Error while loading the package: %s" err) - (cl-delete tag use-package-tags-current-profile) - (error err)))))) + (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