Skip to content

Commit 8af4339

Browse files
committed
Add use-package-tags-load function
1 parent d16eb0c commit 8af4339

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

use-package-tags.el

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,5 +290,40 @@ If SORT is non-nil, the result will be lexicographically sorted."
290290
(cl-remove-duplicates)
291291
(order)))))
292292

293+
(defun use-package-tags--unloaded-tags ()
294+
"Return a list of tags that are not in the current profile."
295+
(-difference (use-package-tags-collect-tags t :sort t)
296+
use-package-tags-current-profile))
297+
298+
;;;###autoload
299+
(defun use-package-tags-load (tag)
300+
"Load packages with a TAG.
301+
302+
This function evalates `use-package' forms with the selected tag
303+
in `use-package-tags-init-files'.
304+
305+
After successfully loading all matching packages, the tag will be
306+
added to `use-package-tags-current-profile', without saving the value
307+
to `custom-file'."
308+
(interactive (list (intern (completing-read "Load packages with tag: "
309+
(use-package-tags--unloaded-tags)
310+
nil 'match))))
311+
(cl-labels
312+
((get-keyword (prop rest) (-some->> (member prop rest)
313+
(nth 1)))
314+
(has-tag-p (tag rest)
315+
(let ((tags (cdr (get-keyword :tags rest))))
316+
(memq tag (cl-etypecase tags
317+
(list tags)
318+
(symbol (list tags)))))))
319+
(use-package-tags--with-package-forms
320+
(use-package-tags--source-buffer-list t)
321+
(let ((exp (read (current-buffer))))
322+
(when (has-tag-p tag exp)
323+
(message "Loading package %s configured at %s..."
324+
(nth 1 exp)
325+
(abbreviate-file-name (buffer-file-name)))
326+
(eval exp))))))
327+
293328
(provide 'use-package-tags)
294329
;;; use-package-tags.el ends here

0 commit comments

Comments
 (0)